|
|
@@ -4,7 +4,7 @@ import { screen, waitForElementToBeRemoved } from '@testing-library/react'
|
|
|
import fetchMock from 'fetch-mock'
|
|
|
|
|
|
import ChatPane from '../../../../../frontend/js/features/chat/components/chat-pane'
|
|
|
-import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
|
|
+import { renderWithChatContext } from '../../../helpers/render-with-context'
|
|
|
import {
|
|
|
stubChatStore,
|
|
|
stubMathJax,
|
|
|
@@ -37,6 +37,7 @@ describe('<ChatPane />', function() {
|
|
|
]
|
|
|
|
|
|
beforeEach(function() {
|
|
|
+ global.localStorage.clear()
|
|
|
stubChatStore({ user: currentUser })
|
|
|
stubUIConfig()
|
|
|
stubMathJax()
|
|
|
@@ -53,9 +54,7 @@ describe('<ChatPane />', function() {
|
|
|
it('renders multiple messages', async function() {
|
|
|
fetchMock.get(/messages/, testMessages)
|
|
|
// unmounting before `beforeEach` block is executed is required to prevent cleanup errors
|
|
|
- const { unmount } = renderWithEditorContext(
|
|
|
- <ChatPane resetUnreadMessages={() => {}} chatIsOpen />
|
|
|
- )
|
|
|
+ const { unmount } = renderWithChatContext(<ChatPane />)
|
|
|
|
|
|
await screen.findByText('a message')
|
|
|
await screen.findByText('another message')
|
|
|
@@ -64,9 +63,7 @@ describe('<ChatPane />', function() {
|
|
|
|
|
|
it('A loading spinner is rendered while the messages are loading, then disappears', async function() {
|
|
|
fetchMock.get(/messages/, [])
|
|
|
- const { unmount } = renderWithEditorContext(
|
|
|
- <ChatPane resetUnreadMessages={() => {}} chatIsOpen />
|
|
|
- )
|
|
|
+ const { unmount } = renderWithChatContext(<ChatPane />)
|
|
|
await waitForElementToBeRemoved(() => screen.getByText('Loading…'))
|
|
|
unmount()
|
|
|
})
|
|
|
@@ -74,18 +71,14 @@ describe('<ChatPane />', function() {
|
|
|
describe('"send your first message" placeholder', function() {
|
|
|
it('is rendered when there are no messages ', async function() {
|
|
|
fetchMock.get(/messages/, [])
|
|
|
- const { unmount } = renderWithEditorContext(
|
|
|
- <ChatPane resetUnreadMessages={() => {}} chatIsOpen />
|
|
|
- )
|
|
|
+ const { unmount } = renderWithChatContext(<ChatPane />)
|
|
|
await screen.findByText('Send your first message to your collaborators')
|
|
|
unmount()
|
|
|
})
|
|
|
|
|
|
it('is not rendered when messages are displayed', function() {
|
|
|
fetchMock.get(/messages/, testMessages)
|
|
|
- const { unmount } = renderWithEditorContext(
|
|
|
- <ChatPane resetUnreadMessages={() => {}} chatIsOpen />
|
|
|
- )
|
|
|
+ const { unmount } = renderWithChatContext(<ChatPane />)
|
|
|
expect(
|
|
|
screen.queryByText('Send your first message to your collaborators')
|
|
|
).to.not.exist
|