diff --git a/webapp/src/pages/dashboard/centerContent.test.tsx b/webapp/src/pages/dashboard/centerContent.test.tsx index 5658120b7..fb1785a4b 100644 --- a/webapp/src/pages/dashboard/centerContent.test.tsx +++ b/webapp/src/pages/dashboard/centerContent.test.tsx @@ -3,6 +3,7 @@ import React from 'react' import configureStore from 'redux-mock-store' import {Provider as ReduxProvider} from 'react-redux' +import 'isomorphic-fetch' import {createMemoryHistory} from 'history' @@ -16,8 +17,16 @@ import {wrapIntl} from '../../testUtils' import {UserWorkspace} from '../../user' +import {FetchMock} from '../../test/fetchMock' + import DashboardCenterContent from './centerContent' +global.fetch = FetchMock.fn + +beforeEach(() => { + FetchMock.fn.mockReset() +}) + describe('pages/dashboard/CenterContent', () => { const mockStore = configureStore([]) const workspace1: UserWorkspace = { @@ -45,6 +54,8 @@ describe('pages/dashboard/CenterContent', () => { }, }) + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(new Array(workspace1, workspace2, workspace3)))) + const component = wrapIntl( @@ -61,6 +72,8 @@ describe('pages/dashboard/CenterContent', () => { }, }) + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(new Array(workspace1, workspace2, workspace3)))) + const component = wrapIntl( @@ -80,6 +93,8 @@ describe('pages/dashboard/CenterContent', () => { }, }) + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(new Array(workspace1, workspace2, workspace3)))) + const component = wrapIntl( @@ -99,6 +114,8 @@ describe('pages/dashboard/CenterContent', () => { }, }) + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(new Array(workspace1, workspace2, workspace3)))) + const history = createMemoryHistory() const component = wrapIntl( diff --git a/webapp/src/pages/dashboard/centerContent.tsx b/webapp/src/pages/dashboard/centerContent.tsx index 8168751bf..696256f94 100644 --- a/webapp/src/pages/dashboard/centerContent.tsx +++ b/webapp/src/pages/dashboard/centerContent.tsx @@ -31,12 +31,8 @@ const DashboardCenterContent = (): JSX.Element => { } useEffect(() => { - if (rawWorkspaces.length > 0) { - return - } - initializeUserWorkspaces() - }) + }, []) const userWorkspaces = rawWorkspaces. filter((workspace) => (workspace.boardCount > 0 || showEmptyWorkspaces) && (workspace.title.toLowerCase().includes(searchFilter) || workspace.boardCount.toString().includes(searchFilter))). diff --git a/webapp/src/pages/dashboard/dashboardPage.test.tsx b/webapp/src/pages/dashboard/dashboardPage.test.tsx index 94dcb10e7..223fd4fcf 100644 --- a/webapp/src/pages/dashboard/dashboardPage.test.tsx +++ b/webapp/src/pages/dashboard/dashboardPage.test.tsx @@ -2,6 +2,7 @@ // See LICENSE.txt for license information. import React from 'react' import {render} from '@testing-library/react' +import 'isomorphic-fetch' import configureStore from 'redux-mock-store' @@ -27,6 +28,8 @@ beforeAll(() => { mockMatchMedia({matches: true}) }) +global.fetch = FetchMock.fn + describe('pages/dashboard/DashboardPage', () => { const mockStore = configureStore([]) const workspace1: UserWorkspace = { @@ -63,6 +66,8 @@ describe('pages/dashboard/DashboardPage', () => { }, }) + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(new Array(workspace1, workspace2, workspace3)))) + const history = createMemoryHistory() const component = wrapIntl(