Update dashboard data whenever we open it (#1479)

* Update dashboard data whenever we open it

* Fixed dashboard tests
This commit is contained in:
Harshil Sharma 2021-10-08 18:58:09 +05:30 committed by GitHub
parent a184206395
commit 6d22385eba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View file

@ -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<UserWorkspace>(workspace1, workspace2, workspace3))))
const component = wrapIntl(
<ReduxProvider store={store}>
<DashboardCenterContent/>
@ -61,6 +72,8 @@ describe('pages/dashboard/CenterContent', () => {
},
})
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(new Array<UserWorkspace>(workspace1, workspace2, workspace3))))
const component = wrapIntl(
<ReduxProvider store={store}>
<DashboardCenterContent/>
@ -80,6 +93,8 @@ describe('pages/dashboard/CenterContent', () => {
},
})
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(new Array<UserWorkspace>(workspace1, workspace2, workspace3))))
const component = wrapIntl(
<ReduxProvider store={store}>
<DashboardCenterContent/>
@ -99,6 +114,8 @@ describe('pages/dashboard/CenterContent', () => {
},
})
FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(new Array<UserWorkspace>(workspace1, workspace2, workspace3))))
const history = createMemoryHistory()
const component = wrapIntl(

View file

@ -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))).

View file

@ -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<UserWorkspace>(workspace1, workspace2, workspace3))))
const history = createMemoryHistory()
const component = wrapIntl(