Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/medic/cht-core into 8697-…
Browse files Browse the repository at this point in the history
…consolidate-enketo-common-selectors
  • Loading branch information
tatilepizs committed Dec 11, 2023
2 parents 45efba6 + 34edb11 commit 577c771
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 30 deletions.
86 changes: 86 additions & 0 deletions tests/e2e/default/contacts/fab-actionbar.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const placeFactory = require('@factories/cht/contacts/place');
const userFactory = require('@factories/cht/users/users');
const personFactory = require('@factories/cht/contacts/person');
const utils = require('@utils');
const loginPage = require('@page-objects/default/login/login.wdio.page');
const commonElements = require('@page-objects/default/common/common.wdio.page');
const { genericForm } = require('@page-objects/default/contacts/contacts.wdio.page');

const places = placeFactory.generateHierarchy();
const healthCenter = places.get('health_center');
const onlineUser = userFactory.build({ place: healthCenter._id, roles: [ 'program_officer' ] });
const patient = personFactory.build({ parent: { _id: healthCenter._id, parent: healthCenter.parent } });
describe('FAB + Actionbar', () => {
before(async () => {
await utils.saveDocs([ ...places.values(), patient ]);
await utils.createUsers([ onlineUser ]);
await loginPage.login(onlineUser);
});

afterEach(async () => {
await utils.revertSettings(false);
});

describe('FAB', () => {
it('should show new household and new person create option', async () => {
await commonElements.goToPeople(healthCenter._id);
const fabLabels = await commonElements.getFastActionItemsLabels();

expect(fabLabels).to.have.members(['New household', 'New person']);
});

it('should show fab when user only has can_create_places permission', async () => {
await utils.updatePermissions(onlineUser.roles, [], ['can_create_people']);
await commonElements.goToPeople(healthCenter._id);

await commonElements.clickFastActionFAB({ waitForList: false });
const formTitle = await genericForm.getFormTitle();
expect(formTitle).to.equal('New household');
});

it('should show fab when user only has can_create_people permission', async () => {
await utils.updatePermissions(onlineUser.roles, [], ['can_create_places']);
await commonElements.goToPeople(healthCenter._id);

await commonElements.clickFastActionFAB({ waitForList: false });
const formTitle = await genericForm.getFormTitle();
expect(formTitle).to.equal('New person');
});
});

describe('Action bar', () => {
it('should show new household and new person create option', async () => {
await utils.updatePermissions(onlineUser.roles, ['can_view_old_action_bar']);
await commonElements.goToPeople(healthCenter._id);
const actionBarLabels = await commonElements.getActionBarLabels();

expect(actionBarLabels).to.have.members([
'New household',
'New person',
'New action',
]);
});

it('should not show new person when missing permission', async () => {
await utils.updatePermissions(onlineUser.roles, ['can_view_old_action_bar'], ['can_create_people']);
await commonElements.goToPeople(healthCenter._id);
const actionBarLabels = await commonElements.getActionBarLabels();

expect(actionBarLabels).to.have.members([
'New household',
'New action',
]);
});

it('should not show new place when missing permission', async () => {
await utils.updatePermissions(onlineUser.roles, ['can_view_old_action_bar'], ['can_create_places']);
await commonElements.goToPeople(healthCenter._id);
const actionBarLabels = await commonElements.getActionBarLabels();

expect(actionBarLabels).to.have.members([
'New person',
'New action',
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const userFactory = require('@factories/cht/users/users');
const placeFactory = require('@factories/cht/contacts/place');
const personFactory = require('@factories/cht/contacts/person');
const messagesPage = require('@page-objects/default/sms/messages.wdio.page');
const contactsPage = require('@page-objects/default/contacts/contacts.wdio.page');

describe('Message tab breadcrumbs', () => {
describe('Message Tab - Sender Data', () => {
const places = placeFactory.generateHierarchy();
const clinic = places.get('clinic');
const health_center = places.get('health_center');
Expand Down Expand Up @@ -84,4 +85,19 @@ describe('Message tab breadcrumbs', () => {
expect(lineage).to.equal(expectedLineage);
});

it('should display conversation with link and navigate to contact', async () => {
await loginPage.login(offlineUser);
await commonElements.waitForPageLoaded();
await commonElements.goToMessages();

await messagesPage.openMessage(patient._id);
const header = await messagesPage.getMessageHeader();
expect(header.name).to.equal(patient.name);
expect(header.phone).to.equal(patient.phone);

await messagesPage.navigateFromConversationToContact();
const title = await contactsPage.getContactInfoName();
expect(title).to.equal(patient.name);
});

});
2 changes: 1 addition & 1 deletion tests/e2e/default/tasks/forms/home-visit.properties.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"context": {
"expression": "!contact || contact.type === 'person'",
"expression": "false",
"person": true,
"place": false
},
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/default/tasks/tasks-breadcrumbs.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ describe('Tasks tab breadcrumbs', () => {
},
]);
});

it('should open task with expression', async () => {
await tasksPage.goToTasksTab();
const task = await tasksPage.getTaskByContactAndForm('patient1', 'person_create');
await task.click();
await tasksPage.waitForTaskContentLoaded('Home Visit');
});
});

describe('for supervisor', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/tasks/tasks.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const compileTasks = async (tasksFileName) => {
return await chtConfUtils.compileNoolsConfig({ tasks: tasksFilePath });
};

describe('Task list', () => {
describe('Tasks', () => {
const places = placeFactory.generateHierarchy();
const clinic = places.get('clinic');
const healthCenter = places.get('health_center');
Expand Down
28 changes: 28 additions & 0 deletions tests/page-objects/default/common/common.wdio.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const FAST_ACTION_LIST_CONTAINER = '.fast-action-content-wrapper';
const fastActionListContainer = () => $(FAST_ACTION_LIST_CONTAINER);
const fastActionListCloseButton = () => $(`${FAST_ACTION_LIST_CONTAINER} .panel-header .panel-header-close`);
const fastActionById = (id) => $(`${FAST_ACTION_LIST_CONTAINER} .fast-action-item[test-id="${id}"]`);
const fastActionItems = () => $$(`${FAST_ACTION_LIST_CONTAINER} .fast-action-item`);
const moreOptionsMenu = () => $('.more-options-menu-container>.mat-mdc-menu-trigger');
const hamburgerMenuItemSelector = '#header-dropdown li';
const logoutButton = () => $(`${hamburgerMenuItemSelector} .fa-power-off`);
Expand All @@ -28,6 +29,9 @@ const syncSuccess = () => $(`${hamburgerMenuItemSelector}.sync-status .success`)
const syncRequired = () => $(`${hamburgerMenuItemSelector}.sync-status .required`);
const jsonError = async () => (await $('pre')).getText();

const actionBar = () => $('.detail-actions.right-pane');
const actionBarActions = () => $$('.detail-actions.right-pane span');

//languages
const activeSnackbar = () => $('#snackbar.active');
const inactiveSnackbar = () => $('#snackbar:not(.active)');
Expand Down Expand Up @@ -82,6 +86,20 @@ const clickFastActionFAB = async ({ actionId, waitForList }) => {
}
};

const getFastActionItemsLabels = async () => {
await closeHamburgerMenu();
await (await fastActionFAB()).waitForDisplayed();
await (await fastActionFAB()).waitForClickable();
await (await fastActionFAB()).click();

await browser.pause(500);
await (await fastActionListContainer()).waitForDisplayed();

const items = await fastActionItems();
const fastActionItemLabels = await Promise.all(items.map(item => item.getText()));
return fastActionItemLabels;
};

const clickFastActionFlat = async ({ actionId, waitForList }) => {
await (await fastActionFlat()).waitForDisplayed();
await (await fastActionFlat()).waitForClickable();
Expand Down Expand Up @@ -406,6 +424,14 @@ const loadNextInfiniteScrollPage = async () => {
await waitForLoaderToDisappear(await $('.left-pane'));
};

const getActionBarLabels = async () => {
await (await actionBar()).waitForDisplayed();
await (await actionBarActions())[0].waitForDisplayed();
const items = await actionBarActions();
const labels = await Promise.all(items.map(item => item.getText()));
return labels.filter(label => !!label);
};

module.exports = {
openMoreOptionsMenu,
closeFastActionList,
Expand Down Expand Up @@ -466,4 +492,6 @@ module.exports = {
getAllButtonLabelsNames,
loadNextInfiniteScrollPage,
goToUrl,
getFastActionItemsLabels,
getActionBarLabels,
};
7 changes: 7 additions & 0 deletions tests/page-objects/default/sms/messages.wdio.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const getMessageHeader = async () => {
};
};

const navigateFromConversationToContact = async () => {
await $(`${MESSAGE_HEADER} a.name`).waitForClickable();
await $(`${MESSAGE_HEADER} a.name`).click();
await commonPage.waitForPageLoaded();
};

const getMessageContent = async (index = 1) => {
const sms = await $(`${MESSAGE_CONTENT} li:nth-child(${index})`);
await sms.waitForDisplayed();
Expand Down Expand Up @@ -140,5 +146,6 @@ module.exports = {
sendReply,
replyAddRecipients,
getAmountOfMessagesByPhone,
navigateFromConversationToContact,
getMessagesModalDetails,
};
8 changes: 4 additions & 4 deletions webapp/src/ts/components/actionbar/actionbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
</div>

<div class="col-sm-4 general-actions left-pane" *ngIf="currentTab === 'contacts'">
<div test-id='create_places' class="actions dropup" mmAuth [mmAuthAny]="[ actionBar?.left?.childPlaces && 'can_create_places' ]">
<div test-id='create_places' class="actions dropup" mmAuth [mmAuthAny]="[ 'can_export_all', 'can_export_contacts', 'can_create_places', 'can_create_people' ]">
<a
*ngIf="actionBar?.left?.childPlaces?.length > 1"
mmAuth="can_edit,can_create_places"
mmAuth="can_edit" [mmAuthAny]="['can_create_places', 'can_create_people']"
class="mm-icon mm-icon-inverse mm-icon-caption dropdown-toggle create-place"
data-toggle="dropdown"
>
Expand All @@ -51,7 +51,7 @@

<ul
*ngIf="actionBar?.left?.childPlaces?.length > 1"
mmAuth="can_edit,can_create_places"
mmAuth="can_edit" [mmAuthAny]="['can_create_places', 'can_create_people']"
class="dropdown-menu mm-dropdown-menu with-icon"
>
<li *ngFor="let child of actionBar.left.childPlaces; trackBy: trackById">
Expand All @@ -66,7 +66,7 @@

<a
*ngIf="actionBar?.left?.childPlaces?.length === 1"
mmAuth="can_edit,can_create_places"
mmAuth="can_edit" [mmAuthAny]="['can_create_places', 'can_create_people']"
class="mm-icon mm-icon-inverse mm-icon-caption create-place"
[routerLink]="actionBar.left.userFacilityId ? ['/', 'contacts', actionBar.left.userFacilityId, 'add', actionBar.left.childPlaces[0]?.id] : ['/', 'contacts', 'add', actionBar.left.childPlaces[0]?.id]"
[queryParams]="{ from: 'list' }"
Expand Down
14 changes: 8 additions & 6 deletions webapp/src/ts/components/sender/sender.component.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<div class="sender" [ngClass]="{ 'small-font': sentBy }" *ngIf="message">
<div>
<span *ngIf="sentBy && (message.doc?.name || message.contact?.name || (!message.form && message.name) || message.from || message.sent_by || message.doc?.from)"
<span *ngIf="sentBy && getName()"
class="name"
translate
[translateParams]="{ senderName: message.doc?.name || message.contact?.name || (!message.form && message.name) || message.from || message.sent_by || message.doc?.from || ('messages.unknown.sender' | translate) }">
[translateParams]="{ senderName: getName() || ( 'messages.unknown.sender' | translate ) }">
messages.sent.by
</span>
<span class="name"
*ngIf="!sentBy || !(message.doc?.name || message.contact?.name || (!message.form && message.name) || message.from || message.sent_by || message.doc?.from)">
{{ message.doc?.name || message.contact?.name || (!message.form && message.name) || message.from || message.sent_by || ('messages.unknown.sender' | translate) }}
</span>

<a class="name" *ngIf="!sentBy && getId() && getName(); else noLinkLabel" [routerLink]="[ '/contacts', getId() ]">{{ getName() }}</a>
<ng-template #noLinkLabel>
<span class="name">{{ getName() || ( 'messages.unknown.sender' | translate ) }}</span>
</ng-template>

<span class="phone" *ngIf="!(message.name && message.name === message.facility?.contact?.phone)">
{{ message.doc?.phone || message.contact?.phone || message.phone }}
</span>
Expand Down
13 changes: 12 additions & 1 deletion webapp/src/ts/components/sender/sender.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,16 @@ export class SenderComponent {
@Input() sentBy;
@Input() hideLineage;

constructor() { }
getName() {
return this.message.doc?.name
|| this.message.contact?.name
|| (!this.message.form && this.message.name)
|| this.message.from
|| this.message.sent_by
|| this.message.doc?.from;
}

getId() {
return this.message.contact?._id || this.message.doc?._id;
}
}
4 changes: 4 additions & 0 deletions webapp/src/ts/services/enketo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ export class EnketoFormContext {
}

shouldEvaluateExpression() {
if (this.type === 'task') {
return false;
}

if (this.type === 'report' && this.editing) {
return false;
}
Expand Down
11 changes: 7 additions & 4 deletions webapp/src/ts/services/fast-action-button.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class FastActionButtonService {
return xmlForms
.map(form => ({
id: form.code,
label: this.getFormTitle(form.titleKey, form.title) || form.code,
label: this.getFormTitle(form.titleKey, form.title) ?? form.code,
icon: { name: form.icon, type: IconType.RESOURCE },
alwaysOpenInPanel: true,
canDisplay: () => this.authService.has('can_edit'),
Expand All @@ -88,9 +88,12 @@ export class FastActionButtonService {
return childContactTypes
.map(contactType => ({
id: contactType.id,
label: this.getFormTitle(contactType.create_key) || contactType.id,
label: this.getFormTitle(contactType.create_key) ?? contactType.id,
icon: { name: contactType.icon, type: IconType.RESOURCE },
canDisplay: () => this.authService.has(['can_edit', 'can_create_places']),
canDisplay: () => this.authService.has([
'can_edit',
contactType.person ? 'can_create_people' : 'can_create_places'
]),
execute: () => {
const route = ['/contacts', 'add', contactType.id];
if (parentFacilityId) {
Expand Down Expand Up @@ -124,7 +127,7 @@ export class FastActionButtonService {
this.executeMailto(`sms:${sendTo?.phone}`);
return;
}
callbackOpenSendMessage && callbackOpenSendMessage(sendTo?._id);
callbackOpenSendMessage?.(sendTo?._id);
},
};
}
Expand Down
Loading

0 comments on commit 577c771

Please sign in to comment.