Commit 19e8f333 authored by Aanand Prasad's avatar Aanand Prasad

fix: dashboard tests

parent 87df5b47
Pipeline #4918 passed with stages
in 4 minutes and 5 seconds
......@@ -3,6 +3,7 @@ import Enzyme, { shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import Dashboard from './Dashboard'
import { Section, Heading, UploadContainer } from './molecules/Page'
// this should be elsewhere
Enzyme.configure({ adapter: new Adapter() })
......@@ -12,7 +13,7 @@ jest.mock('config', () => ({ 'pubsweet-client': {} }))
const getProjects = section =>
section
.children()
.not('.heading')
.not(Heading)
.map(c => c.props().project)
describe('Dashboard', () => {
......@@ -39,8 +40,8 @@ describe('Dashboard', () => {
it('shows a message when there are no projects', () => {
const dashboard = makeWrapper()
expect(dashboard.find('.empty')).toHaveLength(1)
expect(dashboard.find('.heading')).toHaveLength(0)
expect(dashboard.find(UploadContainer)).toHaveLength(2)
expect(dashboard.find(Section)).toHaveLength(0)
})
it('shows a list of projects submitted by the current user', () => {
......@@ -50,7 +51,7 @@ describe('Dashboard', () => {
})
expect(dashboard.find('.empty')).toHaveLength(0)
const section = dashboard.find('.section')
const section = dashboard.find(Section)
expect(section).toHaveLength(1)
expect(getProjects(section)).toEqual([project])
})
......@@ -61,8 +62,8 @@ describe('Dashboard', () => {
dashboard: { reviewer: [project] },
})
expect(dashboard.find('.empty')).toHaveLength(0)
const section = dashboard.find('.section')
expect(dashboard.find(UploadContainer)).toHaveLength(1)
const section = dashboard.find(Section)
expect(section).toHaveLength(1)
expect(getProjects(section)).toEqual([project])
})
......@@ -73,8 +74,8 @@ describe('Dashboard', () => {
dashboard: { editor: [project] },
})
expect(dashboard.find('.empty')).toHaveLength(0)
const section = dashboard.find('.section')
expect(dashboard.find(UploadContainer)).toHaveLength(1)
const section = dashboard.find(Section)
expect(section).toHaveLength(1)
expect(getProjects(section)).toEqual([project])
})
......
......@@ -7,10 +7,13 @@ import thunk from 'redux-thunk'
import Enzyme, { mount } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { ThemeProvider } from 'styled-components'
import { reducers } from 'pubsweet-client'
import conversion from '../redux/conversion'
import DashboardPage from './DashboardPage'
import { Section, UploadContainer } from './molecules/Page'
// this should be elsewhere
Enzyme.configure({ adapter: new Adapter() })
......@@ -47,15 +50,18 @@ describe('DashboardPage', () => {
const store = mockStore()
const page = mount(
<MemoryRouter>
<Provider store={store}>
<DashboardPage />
</Provider>
<ThemeProvider theme={{ colorPrimary: 'blue' }}>
<Provider store={store}>
<DashboardPage />
</Provider>
</ThemeProvider>
</MemoryRouter>,
)
setImmediate(() => {
page.update()
expect(page.find('.empty')).toHaveLength(1)
expect(page.find(UploadContainer)).toHaveLength(2)
expect(page.find(Section)).toHaveLength(0)
done()
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment