Skip to content

Commit

Permalink
chore(#8264): restructured add-new-district.wdio-spec.js test (#8531)
Browse files Browse the repository at this point in the history
Re-structured the add-new-district.wdio-spec.js test to make it more stable.
  • Loading branch information
tatilepizs authored Sep 13, 2023
1 parent 08ec4d7 commit b8b7d42
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 55 deletions.
106 changes: 52 additions & 54 deletions tests/e2e/default/contacts/add-new-district.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,81 @@
const commonElements = require('@page-objects/default/common/common.wdio.page.js');
const contactPage = require('@page-objects/default/contacts/contacts.wdio.page.js');
const utils = require('@utils');
const sentinelUtils = require('@utils/sentinel');
const placeFactory = require('@factories/cht/contacts/place');
const personFactory = require('@factories/cht/contacts/person');
const commonPage = require('@page-objects/default/common/common.wdio.page');
const contactPage = require('@page-objects/default/contacts/contacts.wdio.page');
const loginPage = require('@page-objects/default/login/login.wdio.page');


describe('Add new district tests : ', () => {
before(async () => await loginPage.cookieLogin());
afterEach(() => sentinelUtils.waitForSentinel());
afterEach(async () => {
sentinelUtils.waitForSentinel();
await utils.revertDb([/^form:/], true);
});

it('should add new district with a new person', async () => {
await commonElements.goToPeople();
await commonPage.goToPeople();
const district = 'TestDistrict';
await contactPage.addPlace({ placeName: 'TestDistrict', contactName: 'Tester' }, false);

await sentinelUtils.waitForSentinel();
await commonPage.waitForPageLoaded();

expect(await (await contactPage.contactCard()).getText()).to.equal(district);
expect(await contactPage.getContactCardText()).to.equal(district);
expect(await contactPage.getPrimaryContactName()).to.equal('Tester');
});

it('should edit district', async () => {
const contacts = [
{
_id: 'one_district',
type: 'district_hospital',
name: 'Caroline\'s district',
contact: { _id: 'one_person' },
reported_at: new Date().getTime(),
},
{
_id: 'one_person',
type: 'person',
name: 'Caroline',
parent: { _id: 'one_district' },
reported_at: new Date().getTime(),
},
];
const district = placeFactory.place().build({
_id: 'dist1',
type: 'district_hospital',
name: 'Caroline\'s district',
contact: { _id: 'first_person' },
});

await utils.saveDocs(contacts);
await commonElements.goToPeople();
const person = personFactory.build({
_id: 'first_person',
name: 'Caroline',
parent: { _id: district._id }
});

await utils.saveDocs([ district, person ]);
await commonPage.goToPeople();
await contactPage.editDistrict('Caroline\'s district', 'Edited Caroline\'s');
expect(await (await contactPage.contactCard()).getText()).to.equal('Edited Caroline\'s');
await commonPage.waitForPageLoaded();
expect(await contactPage.getContactCardText()).to.equal('Edited Caroline\'s');
});

it('should edit district with contact_type', async () => {
const contacts = [
{
_id: 'other_district',
type: 'district_hospital',
contact_type: 'not a district_hospital',
name: 'Tudor\'s district',
contact: { _id: 'other_person' },
reported_at: new Date().getTime(),
},
{
_id: 'other_person',
type: 'person',
contact_type: 'something',
name: 'Tudor',
parent: { _id: 'other_district' },
reported_at: new Date().getTime(),
},
{
_id: 'third_person',
type: 'person',
name: 'Ginny',
parent: { _id: 'other_district' },
reported_at: new Date().getTime(),
},
];
const district = placeFactory.place().build({
_id: 'dist2',
type: 'district_hospital',
name: 'Tudor\'s district',
contact: { _id: 'second_person' },
contact_type: 'not a district_hospital',
});

const person1 = personFactory.build({
_id: 'second_person',
name: 'Tudor',
parent: { _id: district._id }
});

await utils.saveDocs(contacts);
await commonElements.goToPeople();
const person2 = personFactory.build({
_id: 'third_person',
name: 'Ginny',
parent: { _id: district._id }
});

await utils.saveDocs([ district, person1, person2 ]);
await commonPage.goToPeople();
await contactPage.editDistrict('Tudor\'s district', 'At Tudor\'s');
expect(await (await contactPage.contactCard()).getText()).to.equal('At Tudor\'s');
await commonPage.waitForPageLoaded();

await commonElements.waitForLoaders();
expect(await (await contactPage.contactCard()).getText()).to.equal('At Tudor\'s');

const updatedDistrict = await utils.getDoc('other_district');
const updatedDistrict = await utils.getDoc(district._id);
expect(updatedDistrict.contact_type).to.equal('not a district_hospital'); // editing didn't overwrite

// expect to have a single children section
Expand Down
3 changes: 2 additions & 1 deletion tests/factories/cht/contacts/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const place = () => {
.attr('notes', '')
.attr('place_id', uuid.v4)
.attr('reported_date', () => new Date())
.attr('contact');
.attr('contact')
.attr('contact_type', '');
};


Expand Down

0 comments on commit b8b7d42

Please sign in to comment.