11import { expect , test } from '@playwright/test' ;
2- import { login } from '../../utils/auth.ts' ;
3- import { formatNumber } from '../../utils/common.ts' ;
4- import fixtureData from '../epidemic-field-report/epidemic.json' ;
2+ import { formatNumber } from '#utils/common' ;
3+ import fixtureData from './epidemic.json' ;
54
6- test . describe ( 'Field report flow' , async ( ) => {
7- test . beforeEach ( 'login credentials' , async ( { page } ) => {
8- await login (
9- page ,
10- process . env . APP_URL ,
11- process . env . PLAYWRIGHT_USER_NAME ,
12- process . env . PLAYWRIGHT_USER_PASSWORD ,
13- ) ;
14- } ) ;
5+ test . use ( { storageState : 'playwright/.auth/user.json' } ) ;
156
7+ test . describe ( 'Field report flow' , async ( ) => {
168 test ( 'field report for epidemic type' , async ( { page } ) => {
179 const {
1810 formName,
@@ -24,20 +16,20 @@ test.describe('Field report flow', async () => {
2416 govRequest,
2517 nationalsocietyRequest,
2618 cases,
27- suspected_cases ,
28- probable_cases ,
29- confirmed_cases ,
30- num_dead ,
19+ suspectedCases ,
20+ probableCases ,
21+ confirmedCases ,
22+ numDead ,
3123 source,
32- epi_notes ,
33- epi_date ,
34- other_sources ,
24+ epiNotes ,
25+ epiDate ,
26+ otherSources ,
3527 description,
36- gov_num_assisted ,
37- num_assisted ,
38- num_localstaff ,
39- num_volunteers ,
40- num_expats_delegates ,
28+ govNumAssisted ,
29+ numAssisted ,
30+ numLocalstaff ,
31+ numVolunteers ,
32+ numExpatsDelegates ,
4133 actionVaccination,
4234 actionQuarantine,
4335 actionWater,
@@ -78,6 +70,7 @@ test.describe('Field report flow', async () => {
7870 visibiltyOptOne,
7971 visibiltyOptTwo,
8072 } = fixtureData ;
73+ await page . goto ( '/' ) ;
8174 await page . getByRole ( 'button' , { name : 'Create a Report' } ) . click ( ) ;
8275 await page . getByRole ( 'link' , { name : 'New Field Report' } ) . click ( ) ;
8376 await expect ( page . locator ( 'h1' ) ) . toContainText ( formName ) ;
@@ -109,35 +102,33 @@ test.describe('Field report flow', async () => {
109102 await page . locator ( 'input[name="epi_cases"]' ) . fill ( cases ) ;
110103 await page
111104 . locator ( 'input[name="epi_suspected_cases"]' )
112- . fill ( suspected_cases ) ;
105+ . fill ( suspectedCases ) ;
113106 await page
114107 . locator ( 'input[name="epi_probable_cases"]' )
115- . fill ( probable_cases ) ;
108+ . fill ( probableCases ) ;
116109 await page
117110 . locator ( 'input[name="epi_confirmed_cases"]' )
118- . fill ( confirmed_cases ) ;
119- await page . locator ( 'input[name="epi_num_dead"]' ) . fill ( num_dead ) ;
111+ . fill ( confirmedCases ) ;
112+ await page . locator ( 'input[name="epi_num_dead"]' ) . fill ( numDead ) ;
120113 await page . locator ( 'input[name="epi_figures_source"]' ) . click ( ) ;
121114 await page . getByRole ( 'button' , { name : source } ) . click ( ) ;
122115 await page
123116 . locator ( 'textarea[name="epi_notes_since_last_fr"]' )
124- . fill ( epi_notes ) ;
125- await page . locator ( 'input[name="sit_fields_date"]' ) . fill ( epi_date ) ;
126- await page
127- . locator ( 'textarea[name="other_sources"]' )
128- . fill ( other_sources ) ;
117+ . fill ( epiNotes ) ;
118+ await page . locator ( 'input[name="sit_fields_date"]' ) . fill ( epiDate ) ;
119+ await page . locator ( 'textarea[name="other_sources"]' ) . fill ( otherSources ) ;
129120 await page . locator ( 'textarea[name="description"]' ) . fill ( description ) ;
130121 await page . getByRole ( 'button' , { name : 'Continue' } ) . click ( ) ;
131122 // Action Page
132123 await page
133124 . locator ( 'input[name="gov_num_assisted"]' )
134- . fill ( gov_num_assisted ) ;
135- await page . locator ( 'input[name="num_assisted"]' ) . fill ( num_assisted ) ;
136- await page . locator ( 'input[name="num_localstaff"]' ) . fill ( num_localstaff ) ;
137- await page . locator ( 'input[name="num_volunteers"]' ) . fill ( num_volunteers ) ;
125+ . fill ( govNumAssisted ) ;
126+ await page . locator ( 'input[name="num_assisted"]' ) . fill ( numAssisted ) ;
127+ await page . locator ( 'input[name="num_localstaff"]' ) . fill ( numLocalstaff ) ;
128+ await page . locator ( 'input[name="num_volunteers"]' ) . fill ( numVolunteers ) ;
138129 await page
139130 . locator ( 'input[name="num_expats_delegates"]' )
140- . fill ( num_expats_delegates ) ;
131+ . fill ( numExpatsDelegates ) ;
141132 // Action taken by National red cross society
142133 await page
143134 . locator ( 'label' )
@@ -274,7 +265,7 @@ test.describe('Field report flow', async () => {
274265 const fields = [
275266 { label : 'Visibility' , value : visibiltyOptTwo } ,
276267 { label : 'Start Date' , value : date } ,
277- { label : 'Date of Data' , value : epi_date } ,
268+ { label : 'Date of Data' , value : epiDate } ,
278269 { label : 'Source' , value : source } ,
279270 ] ;
280271 for ( const field of fields ) {
@@ -286,18 +277,18 @@ test.describe('Field report flow', async () => {
286277 // Assertions to verify whether the data inserted on the form are displayed on the UI // Numeric Details
287278 const numericDetails = [
288279 { label : 'Cumulative Cases' , value : formatNumber ( cases ) } ,
289- { label : 'Suspected Cases' , value : formatNumber ( suspected_cases ) } ,
290- { label : 'Probable Cases' , value : formatNumber ( probable_cases ) } ,
291- { label : 'Confirmed Cases' , value : formatNumber ( confirmed_cases ) } ,
292- { label : 'Dead' , value : formatNumber ( num_dead ) } ,
293- { label : 'Assisted (RC)' , value : formatNumber ( num_assisted ) } ,
280+ { label : 'Suspected Cases' , value : formatNumber ( suspectedCases ) } ,
281+ { label : 'Probable Cases' , value : formatNumber ( probableCases ) } ,
282+ { label : 'Confirmed Cases' , value : formatNumber ( confirmedCases ) } ,
283+ { label : 'Dead' , value : formatNumber ( numDead ) } ,
284+ { label : 'Assisted (RC)' , value : formatNumber ( numAssisted ) } ,
294285 {
295286 label : 'Assisted (Government)' ,
296- value : formatNumber ( gov_num_assisted ) ,
287+ value : formatNumber ( govNumAssisted ) ,
297288 } ,
298289 // { label: 'Staff', value: formatNumber(num_localstaff)},
299290 // { label: 'Volunteers', value: formatNumber(num_volunteers) },
300- { label : 'Delegates' , value : formatNumber ( num_expats_delegates ) } ,
291+ { label : 'Delegates' , value : formatNumber ( numExpatsDelegates ) } ,
301292 ] ;
302293 for ( const detail of numericDetails ) {
303294 const parentElement = page . getByText ( detail . label ) . locator ( '..' ) ;
@@ -311,7 +302,7 @@ test.describe('Field report flow', async () => {
311302 . locator ( '..' )
312303 . locator ( '..' )
313304 . locator ( '..' ) ;
314- await expect ( noteParent ) . toContainText ( epi_notes ) ;
305+ await expect ( noteParent ) . toContainText ( epiNotes ) ;
315306 // Source Marked as Others Assertions
316307 const sourceChild = page . getByText ( 'Sources for data marked as Other' , {
317308 exact : true ,
@@ -321,7 +312,7 @@ test.describe('Field report flow', async () => {
321312 . locator ( '..' )
322313 . locator ( '..' )
323314 . locator ( '..' ) ;
324- await expect ( sourceParent ) . toContainText ( other_sources ) ;
315+ await expect ( sourceParent ) . toContainText ( otherSources ) ;
325316 // Description
326317 const descriptionChild = page . getByText (
327318 'Sources for data marked as Other' ,
@@ -332,7 +323,7 @@ test.describe('Field report flow', async () => {
332323 . locator ( '..' )
333324 . locator ( '..' )
334325 . locator ( '..' ) ;
335- await expect ( descriptionParent ) . toContainText ( other_sources ) ;
326+ await expect ( descriptionParent ) . toContainText ( otherSources ) ;
336327 // Request for Assistance Assertions
337328 const govReq = page
338329 . getByText ( 'Government Requests International Assistance' , {
@@ -469,5 +460,222 @@ test.describe('Field report flow', async () => {
469460 await expect ( detailLocator ) . toContainText ( detail . email ) ;
470461 await expect ( detailLocator ) . toContainText ( detail . phone ) ;
471462 }
463+ await page . getByRole ( 'link' , { name : 'Edit Report' } ) . click ( ) ;
464+ // Input Value Assertions
465+ // Context Page
466+ const statusValue = page
467+ . locator ( 'label' )
468+ . filter ( { hasText : 'EventFirst report for this disaster' } ) ;
469+ await expect ( statusValue ) . toBeChecked ( ) ;
470+ // Assertions for Country, Region, Disaster Type, Date and Title
471+ const countryValue = page . locator ( 'input[name="country"]' ) ;
472+ await expect ( countryValue ) . toHaveValue ( country ) ;
473+ const regionValue = page . locator ( 'input[name="districts"]' ) ;
474+ await expect ( regionValue ) . toHaveValue ( region ) ;
475+ const disasterValue = page . locator ( 'input[name="dtype"]' ) ;
476+ await expect ( disasterValue ) . toHaveValue ( disasterType ) ;
477+ const dateValue = page . locator ( 'input[name="start_date"]' ) ;
478+ await expect ( dateValue ) . toHaveValue ( date ) ;
479+ const titleValue = page . getByPlaceholder ( 'Example: Cyclone Cody' ) ;
480+ await expect ( titleValue ) . toHaveValue ( `${ newtitle } - ${ title } ` ) ;
481+ // Government request international assistance
482+ const govReqValue = page
483+ . locator ( 'label' )
484+ . filter ( { hasText : govRequest } )
485+ . nth ( 1 ) ;
486+ await expect ( govReqValue ) . toBeChecked ( ) ;
487+ // National Society requests international assistance?
488+ const nsReqValue = page
489+ . locator ( 'label' )
490+ . filter ( { hasText : nationalsocietyRequest } )
491+ . nth ( 2 ) ;
492+ await expect ( nsReqValue ) . toBeChecked ( ) ;
493+ await page . getByRole ( 'button' , { name : 'Continue' } ) . click ( ) ;
494+ // Situation Page
495+ // Assertion for Numeric Details Value
496+ const numericDetailCases = [
497+ { name : 'epi_cases' , value : cases } ,
498+ { name : 'epi_suspected_cases' , value : suspectedCases } ,
499+ { name : 'epi_probable_cases' , value : probableCases } ,
500+ { name : 'epi_confirmed_cases' , value : confirmedCases } ,
501+ { name : 'epi_num_dead' , value : numDead } ,
502+ ] ;
503+ for ( const caseData of numericDetailCases ) {
504+ const locator = page . locator ( `input[name="${ caseData . name } "]` ) ;
505+ await expect ( locator ) . toHaveValue ( caseData . value ) ;
506+ }
507+ // Assertions for Source Value
508+ const sourceValue = page . locator ( 'input[name="epi_figures_source"]' ) ;
509+ await expect ( sourceValue ) . toHaveValue ( source ) ;
510+ // Assertions for Notes Value
511+ const notesValue = page . locator (
512+ 'textarea[name="epi_notes_since_last_fr"]' ,
513+ ) ;
514+ await expect ( notesValue ) . toHaveValue ( epiNotes ) ;
515+ // Assertions for Date of Data Value
516+ const dataDateValue = page . locator ( 'input[name="sit_fields_date"]' ) ;
517+ await expect ( dataDateValue ) . toHaveValue ( epiDate ) ;
518+ // Assertions for Source Details Value
519+ const otherSourcesValue = page . locator (
520+ 'textarea[name="other_sources"]' ,
521+ ) ;
522+ await expect ( otherSourcesValue ) . toHaveValue ( otherSources ) ;
523+ // Assertions for Situational Overview Value
524+ const overviewValue = page . locator ( 'textarea[name="description"]' ) ;
525+ await expect ( overviewValue ) . toHaveValue ( description ) ;
526+ await page . getByRole ( 'button' , { name : 'Continue' } ) . click ( ) ;
527+ // Actions Page
528+ // Assertions for Actions Taken Value
529+ const inputValues = [
530+ { name : 'gov_num_assisted' , value : govNumAssisted } ,
531+ { name : 'num_assisted' , value : numAssisted } ,
532+ { name : 'num_localstaff' , value : numLocalstaff } ,
533+ { name : 'num_volunteers' , value : numVolunteers } ,
534+ { name : 'num_expats_delegates' , value : numExpatsDelegates } ,
535+ ] ;
536+ for ( const { name, value } of inputValues ) {
537+ const inputValue = page . locator ( `input[name="${ name } "]` ) ;
538+ await expect ( inputValue ) . toHaveValue ( value ) ;
539+ }
540+ // Assertions for Actions Taken by National Red Cross Society Value
541+ const nsActions = [ actionVaccination , actionQuarantine , actionWater ] ;
542+ for ( const action of nsActions ) {
543+ const actionLocator = page
544+ . locator ( 'label' )
545+ . filter ( { hasText : action } )
546+ . first ( ) ;
547+ await expect ( actionLocator ) . toBeChecked ( ) ;
548+ }
549+ const nsActionsValue = page . locator ( 'textarea[name="summary"]' ) . first ( ) ;
550+ await expect ( nsActionsValue ) . toHaveValue ( nationalSocietySummary ) ;
551+ // Assertions for Actions Taken by IFRC Value
552+ const ifrcActions = [ actionSanitation , actionVector , actionAid ] ;
553+ for ( const action of ifrcActions ) {
554+ const actionLocator = page
555+ . locator ( 'label' )
556+ . filter ( { hasText : action } )
557+ . nth ( 1 ) ;
558+ await expect ( actionLocator ) . toBeChecked ( ) ;
559+ }
560+ const ifrcActionsValue = page
561+ . locator ( 'textarea[name="summary"]' )
562+ . nth ( 1 ) ;
563+ await expect ( ifrcActionsValue ) . toHaveValue ( federationSummary ) ;
564+ // Assertions for Actions Taken by Other RCRC Movements Actors Value
565+ const rcrcActions = [ actionAmbulance , actionVolunteer , actionReadiness ] ;
566+ for ( const action of rcrcActions ) {
567+ const actionLocator = page
568+ . locator ( 'label' )
569+ . filter ( { hasText : action } )
570+ . nth ( 2 ) ;
571+ await expect ( actionLocator ) . toBeChecked ( ) ;
572+ }
573+ const rcrcActionsValue = page
574+ . locator ( 'textarea[name="summary"]' )
575+ . nth ( 2 ) ;
576+ await expect ( rcrcActionsValue ) . toHaveValue ( rcrcSummary ) ;
577+ // Assertions for Information Bulletin Value
578+ const informationBulletinValue = page
579+ . locator ( 'label' )
580+ . filter ( { hasText : informationBulletin } ) ;
581+ await expect ( informationBulletinValue ) . toBeChecked ( ) ;
582+ // Actions Taken by Others
583+ const actionOthersValue = page . locator (
584+ 'textarea[name="actions_others"]' ,
585+ ) ;
586+ await expect ( actionOthersValue ) . toHaveValue ( actionOther ) ;
587+ await page . getByRole ( 'button' , { name : 'Continue' } ) . click ( ) ;
588+ // Response Page
589+ // Assertions for Planned Interventions Value
590+ // DREF Requested
591+ const drefValue = page
592+ . locator ( 'label' )
593+ . filter ( { hasText : interventionOptionOne } )
594+ . nth ( 0 ) ;
595+ await expect ( drefValue ) . toBeChecked ( ) ;
596+ const drefSummaryValue = page . locator ( 'input[name="dref_amount"]' ) ;
597+ await expect ( drefSummaryValue ) . toHaveValue ( drefRequested ) ;
598+ // Emmergency Appeal
599+ const emergencyAppealValue = page
600+ . locator ( 'label' )
601+ . filter ( { hasText : interventionOptionTwo } )
602+ . nth ( 1 ) ;
603+ await expect ( emergencyAppealValue ) . toBeChecked ( ) ;
604+ const emergencyAppealSummaryValue = page . locator (
605+ 'input[name="appeal_amount"]' ,
606+ ) ;
607+ await expect ( emergencyAppealSummaryValue ) . toHaveValue ( emergencyAppeal ) ;
608+ // Rapid Response Personnel
609+ const rapidResponseValue = page
610+ . locator ( 'label' )
611+ . filter ( { hasText : interventionOptionThree } )
612+ . nth ( 2 ) ;
613+ await expect ( rapidResponseValue ) . toBeChecked ( ) ;
614+ const rapidResponseSummaryValue = page . locator (
615+ 'input[name="num_fact"]' ,
616+ ) ;
617+ await expect ( rapidResponseSummaryValue ) . toHaveValue ( rapidResponse ) ;
618+ // Emergency Response Unit
619+ const emergencyResponseValue = page
620+ . locator ( 'label' )
621+ . filter ( { hasText : interventionOptionTwo } )
622+ . nth ( 3 ) ;
623+ await expect ( emergencyResponseValue ) . toBeChecked ( ) ;
624+ const emergencyResponseSummaryValue = page . locator (
625+ 'input[name="num_ifrc_staff"]' ,
626+ ) ;
627+ await expect ( emergencyResponseSummaryValue ) . toHaveValue (
628+ emergencyResponse ,
629+ ) ;
630+ // Contacts
631+ // Assertion for Originator Contacts value
632+ const originatorValue = [
633+ { name : 'name' , value : originatorName } ,
634+ { name : 'title' , value : originatorTitle } ,
635+ { name : 'email' , value : originatorEmail } ,
636+ { name : 'phone' , value : originatorPhone } ,
637+ ] ;
638+ for ( const { name, value } of originatorValue ) {
639+ const locator = page . locator ( `input[name="${ name } "]` ) . nth ( 0 ) ;
640+ await expect ( locator ) . toHaveValue ( value ) ;
641+ }
642+ // Assertion for National Society values
643+ const nationalValue = [
644+ { name : 'name' , value : nationalName } ,
645+ { name : 'title' , value : nationalTitle } ,
646+ { name : 'email' , value : nationalEmail } ,
647+ { name : 'phone' , value : nationalPhone } ,
648+ ] ;
649+ for ( const { name, value } of nationalValue ) {
650+ const locator = page . locator ( `input[name="${ name } "]` ) . nth ( 1 ) ;
651+ await expect ( locator ) . toHaveValue ( value ) ;
652+ }
653+ // Assertions for IFRC Focal Points for the Emergency Values
654+ const ifrcValue = [
655+ { name : 'name' , value : ifrcName } ,
656+ { name : 'title' , value : ifrcTitle } ,
657+ { name : 'email' , value : ifrcEmail } ,
658+ { name : 'phone' , value : ifrcPhone } ,
659+ ] ;
660+ for ( const { name, value } of ifrcValue ) {
661+ const locator = page . locator ( `input[name="${ name } "]` ) . nth ( 2 ) ;
662+ await expect ( locator ) . toHaveValue ( value ) ;
663+ }
664+ // Assertions for Emergency Response Units Values
665+ const mediaValue = [
666+ { name : 'name' , value : mediaName } ,
667+ { name : 'title' , value : mediaTitle } ,
668+ { name : 'email' , value : mediaEmail } ,
669+ { name : 'phone' , value : mediaPhone } ,
670+ ] ;
671+ for ( const { name, value } of mediaValue ) {
672+ const locator = page . locator ( `input[name="${ name } "]` ) . nth ( 3 ) ;
673+ await expect ( locator ) . toHaveValue ( value ) ;
674+ }
675+ // Assertions for Field Report Visibility Value
676+ const frVisibilityValue = page
677+ . locator ( 'label' )
678+ . filter ( { hasText : visibiltyOptTwo } ) ;
679+ await expect ( frVisibilityValue ) . toBeChecked ( ) ;
472680 } ) ;
473681} ) ;
0 commit comments