Skip to content

Commit

Permalink
chore: fix tests and css and dedupe again
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen committed Aug 27, 2024
1 parent 784d941 commit 1bc2e57
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1,438 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,47 @@ test('renders menu for active type MAP and type CHART', async () => {
},
})

const { container } = render(<ViewAsMenuItems {...props} />)
const { queryByText } = render(<ViewAsMenuItems {...props} />)

expect(container).toMatchSnapshot()
expect(queryByText('View as Map')).toBeNull()
expect(queryByText('View as Chart')).toBeTruthy()
expect(queryByText('View as Pivot table')).toBeTruthy()
})

test('renders disabled menu items when offline', () => {
useDhis2ConnectionStatus.mockImplementation(jest.fn(() => offline))

test('renders menu for active type CHART and type MAP', async () => {
useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online))
const props = Object.assign({}, defaultProps, {
type: CHART,
activeType: MAP,
type: MAP,
activeType: CHART,
visualization: {
type: 'COLUMN',
mapViews: [{ layer: 'thematic' }],
},
})

const { container } = render(<ViewAsMenuItems {...props} />)
expect(container).toMatchSnapshot()
const { queryByText } = render(<ViewAsMenuItems {...props} />)

expect(queryByText('View as Map')).toBeTruthy()
expect(queryByText('View as Chart')).toBeNull()
expect(queryByText('View as Pivot table')).toBeTruthy()
})

test('renders menu for active type CHART and type MAP', async () => {
useDhis2ConnectionStatus.mockImplementation(jest.fn(() => online))
test('renders disabled menu items when offline', () => {
useDhis2ConnectionStatus.mockImplementation(jest.fn(() => offline))

const props = Object.assign({}, defaultProps, {
type: MAP,
activeType: CHART,
type: CHART,
activeType: MAP,
visualization: {
mapViews: [{ layer: 'thematic' }],
type: 'COLUMN',
},
})

const { container } = render(<ViewAsMenuItems {...props} />)

expect(container).toMatchSnapshot()
const listItems = container.querySelectorAll('li')
listItems.forEach((listItem) => {
expect(listItem.getAttribute('class')).toContain('disabled')
})
})

test('renders menu for active type MAP and type MAP without Thematic layer', async () => {
Expand All @@ -86,9 +94,17 @@ test('renders menu for active type MAP and type MAP without Thematic layer', asy
},
})

const { container } = render(<ViewAsMenuItems {...props} />)
const { container, queryByText } = render(<ViewAsMenuItems {...props} />)

expect(container).toMatchSnapshot()
expect(queryByText('View as Map')).toBeNull()
expect(queryByText('View as Chart')).toBeTruthy()
expect(queryByText('View as Pivot table')).toBeTruthy()

const listItems = container.querySelectorAll('li')
expect(listItems).toHaveLength(2)
listItems.forEach((listItem) => {
expect(listItem.getAttribute('class')).toContain('disabled')
})
})

test('renders menu for active type MAP and type MAP without Thematic layer when offline', async () => {
Expand All @@ -101,9 +117,17 @@ test('renders menu for active type MAP and type MAP without Thematic layer when
},
})

const { container } = render(<ViewAsMenuItems {...props} />)
const { container, queryByText } = render(<ViewAsMenuItems {...props} />)

expect(container).toMatchSnapshot()
expect(queryByText('View as Map')).toBeNull()
expect(queryByText('View as Chart')).toBeTruthy()
expect(queryByText('View as Pivot table')).toBeTruthy()

const listItems = container.querySelectorAll('li')
expect(listItems).toHaveLength(2)
listItems.forEach((listItem) => {
expect(listItem.getAttribute('class')).toContain('disabled')
})
})

test('renders menu for active type REPORT_TABLE and type CHART', async () => {
Expand All @@ -114,9 +138,11 @@ test('renders menu for active type REPORT_TABLE and type CHART', async () => {
visualization: { type: 'COLUMN' },
})

const { container } = render(<ViewAsMenuItems {...props} />)
const { queryByText } = render(<ViewAsMenuItems {...props} />)

expect(container).toMatchSnapshot()
expect(queryByText('View as Map')).toBeTruthy()
expect(queryByText('View as Chart')).toBeTruthy()
expect(queryByText('View as Pivot table')).toBeNull()
})

test('renders menu for active type CHART and type REPORT_TABLE', async () => {
Expand All @@ -127,9 +153,11 @@ test('renders menu for active type CHART and type REPORT_TABLE', async () => {
visualization: { type: 'PIVOT_TABLE' },
})

const { container } = render(<ViewAsMenuItems {...props} />)
const { queryByText } = render(<ViewAsMenuItems {...props} />)

expect(container).toMatchSnapshot()
expect(queryByText('View as Map')).toBeTruthy()
expect(queryByText('View as Chart')).toBeNull()
expect(queryByText('View as Pivot table')).toBeTruthy()
})

test('renders menu for active type EVENT_REPORT and type EVENT_CHART', async () => {
Expand All @@ -140,9 +168,11 @@ test('renders menu for active type EVENT_REPORT and type EVENT_CHART', async ()
visualization: {},
})

const { container } = render(<ViewAsMenuItems {...props} />)
const { queryByText } = render(<ViewAsMenuItems {...props} />)

expect(container).toMatchSnapshot()
expect(queryByText('View as Map')).toBeNull()
expect(queryByText('View as Chart')).toBeTruthy()
expect(queryByText('View as Pivot table')).toBeNull()
})

test('renders menu for active type EVENT_CHART and type EVENT_REPORT', async () => {
Expand All @@ -153,7 +183,9 @@ test('renders menu for active type EVENT_CHART and type EVENT_REPORT', async ()
visualization: {},
})

const { container } = render(<ViewAsMenuItems {...props} />)
const { queryByText } = render(<ViewAsMenuItems {...props} />)

expect(container).toMatchSnapshot()
expect(queryByText('View as Map')).toBeNull()
expect(queryByText('View as Chart')).toBeNull()
expect(queryByText('View as Pivot table')).toBeTruthy()
})
Loading

0 comments on commit 1bc2e57

Please sign in to comment.