|
@@ -12,8 +12,21 @@ import {
|
|
|
cleanUpContext,
|
|
cleanUpContext,
|
|
|
} from '../../../helpers/render-with-context'
|
|
} from '../../../helpers/render-with-context'
|
|
|
import { stubMathJax, tearDownMathJaxStubs } from './stubs'
|
|
import { stubMathJax, tearDownMathJaxStubs } from './stubs'
|
|
|
|
|
+import sinon from 'sinon'
|
|
|
|
|
|
|
|
describe('<ChatPane />', function () {
|
|
describe('<ChatPane />', function () {
|
|
|
|
|
+ beforeEach(function () {
|
|
|
|
|
+ this.clock = sinon.useFakeTimers({
|
|
|
|
|
+ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval'],
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ afterEach(function () {
|
|
|
|
|
+ this.clock.runAll()
|
|
|
|
|
+ this.clock.restore()
|
|
|
|
|
+ fetchMock.reset()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
const user = {
|
|
const user = {
|
|
|
id: 'fake_user',
|
|
id: 'fake_user',
|
|
|
first_name: 'fake_user_first_name',
|
|
first_name: 'fake_user_first_name',
|
|
@@ -78,10 +91,16 @@ describe('<ChatPane />', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('a loading spinner is rendered while the messages are loading, then disappears', async function () {
|
|
it('a loading spinner is rendered while the messages are loading, then disappears', async function () {
|
|
|
- fetchMock.get(/messages/, [])
|
|
|
|
|
|
|
+ fetchMock.get(/messages/, [], { delay: 1000 })
|
|
|
|
|
|
|
|
renderWithChatContext(<ChatPane />, { user })
|
|
renderWithChatContext(<ChatPane />, { user })
|
|
|
|
|
|
|
|
|
|
+ this.clock.tick(600) // wait for spinner to be displayed
|
|
|
|
|
+
|
|
|
|
|
+ await screen.findByText('Loading…')
|
|
|
|
|
+
|
|
|
|
|
+ this.clock.tick(1000) // wait for response to be received
|
|
|
|
|
+
|
|
|
await waitForElementToBeRemoved(() => screen.getByText('Loading…'))
|
|
await waitForElementToBeRemoved(() => screen.getByText('Loading…'))
|
|
|
})
|
|
})
|
|
|
|
|
|