Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7346 - Adding "no target found." message to targets (#7377)
Ticket: #7346 This commit adds a message for when an user doesn't have targets in the view.
- Loading branch information
1 parent
c50dd5e
commit 81a95db
Showing
6 changed files
with
193 additions
and
5 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
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,109 @@ | ||
const path = require('path'); | ||
const expect = require('chai').expect; | ||
|
||
const utils = require('../../utils'); | ||
const sentinelUtils = require('../sentinel/utils'); | ||
const analyticsPage = require('../../page-objects/analytics/analytics.wdio.page'); | ||
const loginPage = require('../../page-objects/login/login.wdio.page'); | ||
const commonPage = require('../../page-objects/common/common.wdio.page'); | ||
const chtConfUtils = require('../../cht-conf-utils'); | ||
|
||
const contacts = [ | ||
{ | ||
_id: 'fixture:district', | ||
type: 'district_hospital', | ||
name: 'District', | ||
place_id: 'district', | ||
reported_date: new Date().getTime(), | ||
}, | ||
{ | ||
_id: 'fixture:center', | ||
type: 'health_center', | ||
name: 'Health Center', | ||
parent: { _id: 'fixture:district' }, | ||
place_id: 'health_center', | ||
reported_date: new Date().getTime(), | ||
}, | ||
]; | ||
|
||
const chw = { | ||
username: 'bob', | ||
password: 'medic.123', | ||
place: 'fixture:center', | ||
contact: { _id: 'fixture:user:bob', name: 'Bob' }, | ||
roles: [ 'chw' ], | ||
}; | ||
|
||
const updateSettings = async (settings) => { | ||
await utils.updateSettings(settings, 'api'); | ||
await commonPage.sync(true); | ||
await browser.refresh(); | ||
}; | ||
|
||
const compileTargets = async (configDirectory) => { | ||
await chtConfUtils.initializeConfigDir(); | ||
const targetFilePath = path.join(__dirname, configDirectory, 'targets.js'); | ||
|
||
return chtConfUtils.compileNoolsConfig({ targets: targetFilePath }); | ||
}; | ||
|
||
describe('Targets', () => { | ||
before(async () => { | ||
await utils.saveDocs(contacts); | ||
await utils.createUsers([ chw ]); | ||
await sentinelUtils.waitForSentinel(); | ||
|
||
await loginPage.login({ username: chw.username, password: chw.password }); | ||
await commonPage.closeTour(); | ||
await (await commonPage.analyticsTab()).waitForDisplayed(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await utils.revertSettings(true); | ||
}); | ||
|
||
it('should display targets from default config', async () => { | ||
await analyticsPage.goToTargets(); | ||
|
||
const targets = await analyticsPage.getTargets(); | ||
|
||
expect(targets).to.have.deep.members([ | ||
{ title: 'Deaths', goal: '0', count: '0' }, | ||
{ title: 'New pregnancies', goal: '20', count: '0' }, | ||
{ title: 'Live births', count: '1' }, // This is CHW Bob, the target counts any contact type 'person'. | ||
{ title: 'Active pregnancies', count: '0' }, | ||
{ title: 'Active pregnancies with 1+ routine facility visits', count: '0' }, | ||
{ title: 'In-facility deliveries', percent: '0%', percentCount: '(0 of 0)' }, | ||
{ title: 'Active pregnancies with 4+ routine facility visits', count: '0' }, | ||
{ title: 'Active pregnancies with 8+ routine contacts', count: '0' }, | ||
]); | ||
}); | ||
|
||
it('should display correct message when no target found', async () => { | ||
const settings = await compileTargets('no-targets-config'); | ||
await updateSettings(settings); | ||
await analyticsPage.goToTargets(); | ||
|
||
const emptySelection = await analyticsPage.noSelectedTarget(); | ||
await (emptySelection).waitForDisplayed(); | ||
await commonPage.waitForLoaderToDisappear(emptySelection); | ||
|
||
expect(await emptySelection.getText()).to.equal('No target found.'); | ||
}); | ||
|
||
it('should display correct message when targets are disabled', async () => { | ||
const tasks = { | ||
targets: { enabled: false } | ||
}; | ||
await updateSettings({ tasks }); | ||
await analyticsPage.goToTargets(); | ||
|
||
const emptySelection = await analyticsPage.noSelectedTarget(); | ||
await (emptySelection).waitForDisplayed(); | ||
await commonPage.waitForLoaderToDisappear(emptySelection); | ||
|
||
expect(await emptySelection.getText()).to.equal( | ||
'Targets are disabled for admin users. If you need to see targets, login as a normal user.' | ||
); | ||
}); | ||
}); |
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,9 @@ | ||
module.exports = [ | ||
{ | ||
id: 'deaths-this-month', | ||
context: 'user.parent.type === "district_hospital"', | ||
type: 'count', | ||
goal: 0, | ||
appliesTo: 'contacts' | ||
}, | ||
]; |
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,61 @@ | ||
const goToTargets = () => browser.url('/#/analytics/targets'); | ||
|
||
const noSelectedTarget = () => $('.empty-selection'); | ||
|
||
const targets = () => $$('.target'); | ||
|
||
const targetWrap = () => $('.page .targets'); | ||
|
||
const targetTitle = (targetElement) => targetElement.$('.heading .title h2'); | ||
|
||
const targetGoal = (targetElement) => targetElement.$('.body .count .goal'); | ||
|
||
const targetCountNumber = (targetElement) => targetElement.$('.body .count .number'); | ||
|
||
const targetProgressNumber = (targetElement) => targetElement.$('.body .target-progress .number'); | ||
|
||
const targetNumberPercent = (targetElement) => targetElement.$('.body .target-progress .number .value'); | ||
|
||
const targetNumberPercentCount = (targetElement) => targetElement.$('.body .target-progress .number span:nth-child(2)'); | ||
|
||
const targetGoalValue = (targetElement) => targetElement.$('.body .count .goal p'); | ||
|
||
const getTargetInfo = async (targetElement) => { | ||
const target = { | ||
title: await (await targetTitle(targetElement)).getText() | ||
}; | ||
|
||
if (await (await targetGoal(targetElement)).isExisting()) { | ||
target.goal = await (await targetGoalValue(targetElement)).getText(); | ||
} | ||
|
||
if (await (await targetCountNumber(targetElement)).isExisting()) { | ||
target.count = await (await targetCountNumber(targetElement)).getText(); | ||
} | ||
|
||
if (await (await targetProgressNumber(targetElement)).isExisting()) { | ||
target.percent = await (await targetNumberPercent(targetElement)).getText(); | ||
target.percentCount = await (await targetNumberPercentCount(targetElement)).getText(); | ||
} | ||
|
||
return target; | ||
}; | ||
|
||
const getTargets = async () => { | ||
await (await targetWrap()).waitForDisplayed(); | ||
const displayedTargets = await targets(); | ||
|
||
const targetList = []; | ||
for (const target of displayedTargets) { | ||
const info = await getTargetInfo(target); | ||
targetList.push(info); | ||
} | ||
|
||
return targetList; | ||
}; | ||
|
||
module.exports = { | ||
noSelectedTarget, | ||
goToTargets, | ||
getTargets, | ||
}; |
14 changes: 9 additions & 5 deletions
14
webapp/src/ts/modules/analytics/analytics-targets.component.html
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