diff --git a/tests/e2e/default/contacts/add-new-district.wdio-spec.js b/tests/e2e/default/contacts/add-new-district.wdio-spec.js index 0995c8c60be..ca5fcee55d0 100644 --- a/tests/e2e/default/contacts/add-new-district.wdio-spec.js +++ b/tests/e2e/default/contacts/add-new-district.wdio-spec.js @@ -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 diff --git a/tests/factories/cht/contacts/place.js b/tests/factories/cht/contacts/place.js index 4290fc119d5..b9987a2ec66 100644 --- a/tests/factories/cht/contacts/place.js +++ b/tests/factories/cht/contacts/place.js @@ -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', ''); };