-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for dashboard filter and item context menu (#1325)
This PR includes: New tests: * added tests for dashboard item context menu * added tests for dashboard filter Refactoring: * ItemFooter is now a functional component (modified this file since I was adding a data-test attribute) * Move common cypress test functions to common.js using cucumber's reusable syntax (using curly braces in step titles) * Start capturing all data specific to Sierra Leone db backend in a single place. * Keep cypress selector strings in separate files under /selectors (e.g. dashboardItem) so that there is just one place to update the value if needed
- Loading branch information
1 parent
d922f54
commit c1f0fc9
Showing
25 changed files
with
406 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { dashboards } from './sierraLeone_236' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const dashboards = { | ||
'Antenatal Care': { | ||
route: '#/nghVC4wtyzi', | ||
}, | ||
Delivery: { | ||
route: '#/iMnYyBfSxmM', | ||
items: { | ||
chart: { itemUid: 'GaVhJpqABYX', visUid: 'HDEDqV3yv3H' }, | ||
table: { itemUid: 'qXsjttMYuoZ' }, | ||
map: { itemUid: 'G3EtzSWNP9o' }, | ||
}, | ||
}, | ||
Immunization: { | ||
route: '#/TAMlzYkstb7', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Given, Then } from 'cypress-cucumber-preprocessor/steps' | ||
import { dashboards } from '../../assets/backends' | ||
import { EXTENDED_TIMEOUT } from '../../support/utils' | ||
import { chartSel } from '../../selectors/dashboardItem' | ||
import { dashboardTitleSel } from '../../selectors/titleBar' | ||
import { dashboardChipSel } from '../../selectors/dashboardsBar' | ||
|
||
beforeEach(() => { | ||
cy.visit('/', EXTENDED_TIMEOUT) | ||
}) | ||
|
||
Given('I open the {string} dashboard', title => { | ||
cy.get(dashboardChipSel, EXTENDED_TIMEOUT).contains(title).click() | ||
}) | ||
|
||
Then('the {string} dashboard displays in view mode', title => { | ||
cy.location().should(loc => { | ||
expect(loc.hash).to.equal(dashboards[title].route) | ||
}) | ||
|
||
cy.get(dashboardTitleSel).should('be.visible').and('contain', title) | ||
cy.get(chartSel).should('exist') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Feature: Dashboard filter | ||
|
||
Background: | ||
Given I open the "Delivery" dashboard | ||
And the "Delivery" dashboard displays in view mode | ||
|
||
@nonmutating | ||
Scenario: I add a Period filter | ||
When I add a "Period" filter | ||
Then the Period filter is applied to the dashboard | ||
|
||
@nonmutating | ||
Scenario: I add a Organisation Unit filter | ||
When I add a "Organisation Unit" filter | ||
Then the Organisation Unit filter is applied to the dashboard | ||
|
||
|
||
@nonmutating | ||
Scenario: I add a Facility Type filter | ||
When I add a "Facility Type" filter | ||
Then the Facility Type filter is applied to the dashboard |
89 changes: 89 additions & 0 deletions
89
cypress/integration/ui/dashboard_filter/dashboard_filter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { When, Then } from 'cypress-cucumber-preprocessor/steps' | ||
import { | ||
getDashboardItem, | ||
chartSubtitleSel, | ||
chartXAxisLabelSel, | ||
} from '../../../selectors/dashboardItem' | ||
import { | ||
unselectedItemsSel, | ||
filterDimensionsPanelSel, | ||
filterBadgeSel, | ||
orgUnitHierarchySel, | ||
orgUnitCheckboxesSel, | ||
} from '../../../selectors/dashboardFilter' | ||
import { dashboards } from '../../../assets/backends' | ||
import { EXTENDED_TIMEOUT } from '../../../support/utils' | ||
|
||
const PERIOD = 'Last 6 months' | ||
const OU = 'Sierra Leone' | ||
const FACILITY_TYPE = 'Clinic' | ||
|
||
const chartItemUid = dashboards.Delivery.items.chart.itemUid | ||
|
||
When('I add a {string} filter', dimensionType => { | ||
cy.contains('Add filter').click() | ||
|
||
// open the dimensions modal | ||
cy.get(filterDimensionsPanelSel).contains(dimensionType).click() | ||
|
||
// select an item in the modal | ||
if (dimensionType === 'Period') { | ||
cy.get(unselectedItemsSel).contains(PERIOD).dblclick() | ||
} else if (dimensionType === 'Organisation Unit') { | ||
cy.get(orgUnitHierarchySel, EXTENDED_TIMEOUT).find('.arrow').click() | ||
cy.get(orgUnitHierarchySel, EXTENDED_TIMEOUT) | ||
.find(orgUnitCheckboxesSel, EXTENDED_TIMEOUT) | ||
.contains(OU, EXTENDED_TIMEOUT) | ||
.click() | ||
} else { | ||
cy.get(unselectedItemsSel).contains(FACILITY_TYPE).dblclick() | ||
} | ||
|
||
// confirm to apply the filter | ||
cy.get('button').contains('Confirm').click() | ||
}) | ||
|
||
/* | ||
Scenario: I add a Period filter | ||
*/ | ||
|
||
Then('the Period filter is applied to the dashboard', () => { | ||
cy.get(filterBadgeSel).contains(`Period: ${PERIOD}`).should('be.visible') | ||
|
||
getDashboardItem(chartItemUid) | ||
.find(chartSubtitleSel, EXTENDED_TIMEOUT) | ||
.scrollIntoView() | ||
.contains(PERIOD, EXTENDED_TIMEOUT) | ||
.should('be.visible') | ||
}) | ||
|
||
/* | ||
Scenario: I add an Organisation Unit filter | ||
*/ | ||
|
||
Then('the Organisation Unit filter is applied to the dashboard', () => { | ||
cy.get(filterBadgeSel) | ||
.contains(`Organisation Unit: ${OU}`) | ||
.should('be.visible') | ||
|
||
getDashboardItem(chartItemUid) | ||
.find(chartXAxisLabelSel, EXTENDED_TIMEOUT) | ||
.scrollIntoView() | ||
.contains(OU, EXTENDED_TIMEOUT) | ||
.should('be.visible') | ||
}) | ||
|
||
/* | ||
Scenario: I add a Facility Type filter | ||
*/ | ||
Then('the Facility Type filter is applied to the dashboard', () => { | ||
cy.get(filterBadgeSel) | ||
.contains(`Facility Type: ${FACILITY_TYPE}`) | ||
.should('be.visible') | ||
|
||
getDashboardItem(chartItemUid) | ||
.find(chartSubtitleSel, EXTENDED_TIMEOUT) | ||
.scrollIntoView() | ||
.contains(FACILITY_TYPE, EXTENDED_TIMEOUT) | ||
.should('be.visible') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Feature: Item context menu | ||
|
||
Background: | ||
Given I open the "Delivery" dashboard | ||
And the "Delivery" dashboard displays in view mode | ||
And the chart dashboard item displays as a chart | ||
And the table dashboard item displays as a table | ||
|
||
@nonmutating | ||
Scenario: View chart as table | ||
When I click View As Table on a chart dashboard item | ||
Then the chart dashboard item displays as a table | ||
|
||
@nonmutating | ||
Scenario: View chart as map | ||
When I click View As Map on a chart dashboard item | ||
Then the chart dashboard item displays as a map | ||
|
||
@nonmutating | ||
Scenario: View table as chart | ||
When I click View As Chart on a table dashboard item | ||
Then the table dashboard item displays as a chart | ||
|
||
@nonmutating | ||
Scenario: Open chart in Data Visualizer app | ||
When I click Open in Data Visualizer app on a chart dashboard item | ||
Then the chart is opened in the Data Visualizer app | ||
|
||
@nonmutating | ||
Scenario: Open the interpretations panel | ||
When I click Show interpretations and details on a chart dashboard item | ||
Then the interpretations panel is displayed | ||
|
||
|
139 changes: 139 additions & 0 deletions
139
cypress/integration/ui/item_context_menu/item_context_menu.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { When, Then } from 'cypress-cucumber-preprocessor/steps' | ||
import { | ||
chartSel, | ||
mapSel, | ||
tableSel, | ||
itemDetailsSel, | ||
clickMenuButton, | ||
getDashboardItem, | ||
} from '../../../selectors/dashboardItem' | ||
import { dashboards } from '../../../assets/backends' | ||
|
||
// these tests being run on the "Delivery" dashboard | ||
const chartItemUid = dashboards.Delivery.items.chart.itemUid | ||
const tableItemUid = dashboards.Delivery.items.table.itemUid | ||
const chartItemVisUrl = `dhis-web-data-visualizer/#/${dashboards.Delivery.items.chart.visUid}` | ||
|
||
/* | ||
Background | ||
*/ | ||
|
||
Then('the chart dashboard item displays as a chart', () => { | ||
getDashboardItem(chartItemUid) | ||
.find(chartSel) | ||
.should('exist') | ||
.and('be.visible') | ||
}) | ||
|
||
Then('the table dashboard item displays as a table', () => { | ||
getDashboardItem(tableItemUid) | ||
.find(tableSel) | ||
.should('exist') | ||
.and('be.visible') | ||
}) | ||
|
||
/* | ||
Scenario: View chart as table | ||
*/ | ||
|
||
When('I click View As Table on a chart dashboard item', () => { | ||
clickMenuButton(chartItemUid) | ||
cy.contains('View as Table').click() | ||
}) | ||
|
||
Then('the chart dashboard item displays as a table', () => { | ||
getDashboardItem(chartItemUid) | ||
.find(tableSel) | ||
.should('exist') | ||
.and('be.visible') | ||
}) | ||
|
||
/* | ||
Scenario: View chart as map | ||
*/ | ||
|
||
When('I click View As Map on a chart dashboard item', () => { | ||
clickMenuButton(chartItemUid) | ||
cy.contains('View as Map').click() | ||
}) | ||
|
||
Then('the chart dashboard item displays as a map', () => { | ||
getDashboardItem(chartItemUid) | ||
.find(mapSel) | ||
.should('exist') | ||
.and('be.visible') | ||
}) | ||
|
||
/* | ||
Scenario: View table as chart | ||
*/ | ||
|
||
When('I click View As Chart on a table dashboard item', () => { | ||
clickMenuButton(tableItemUid) | ||
cy.contains('View as Chart').click() | ||
}) | ||
|
||
Then('the table dashboard item displays as a chart', () => { | ||
getDashboardItem(tableItemUid) | ||
.find(chartSel) | ||
.should('exist') | ||
.and('be.visible') | ||
}) | ||
|
||
/* | ||
Scenario: Open chart in Data Visualizer app | ||
*/ | ||
|
||
When('I click Open in Data Visualizer app on a chart dashboard item', () => { | ||
clickMenuButton(chartItemUid) | ||
|
||
cy.contains('Open in Data Visualizer app') | ||
.should('have.attr', 'href') | ||
.and('include', chartItemVisUrl) | ||
|
||
/** | ||
* Since Cypress cannot work with multiple tabs and more | ||
* than one domain in a single test, modify the link to: | ||
* 1) open in the current Cypress tab instead of new tab | ||
* 2) open on the test domain instead of the api domain | ||
*/ | ||
cy.contains('Open in Data Visualizer app') | ||
.invoke('removeAttr', 'target') | ||
.invoke( | ||
'attr', | ||
'href', | ||
`${Cypress.config().baseUrl}/${chartItemVisUrl}` | ||
) | ||
.click() | ||
}) | ||
|
||
Then('the chart is opened in the Data Visualizer app', () => { | ||
// This url is a 404, but the goal is to confirm that | ||
// clicking on the link actually navigates to another url. | ||
cy.url().should('include', chartItemVisUrl) | ||
}) | ||
|
||
/* | ||
Scenario: Open the interpretations panel | ||
*/ | ||
|
||
When( | ||
'I click Show interpretations and details on a chart dashboard item', | ||
() => { | ||
clickMenuButton(chartItemUid) | ||
cy.contains('Show interpretations and details').click() | ||
} | ||
) | ||
Then('the interpretations panel is displayed', () => { | ||
getDashboardItem(chartItemUid) | ||
.find(itemDetailsSel) | ||
.contains('Chart details') | ||
.scrollIntoView() | ||
.should('be.visible') | ||
|
||
getDashboardItem(chartItemUid) | ||
.find(itemDetailsSel) | ||
.contains('Interpretations') | ||
.scrollIntoView() | ||
.should('be.visible') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.