|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import { login } from "../../utils/auth.ts"; |
| 3 | +import { formatNumber } from '../../utils/common.ts'; |
| 4 | +import fixtureData from "./fieldReport.json"; |
| 5 | + |
| 6 | +test.describe("test suite for Field report", async () => { |
| 7 | + test.beforeEach("login credentials", async ({ page }) => { |
| 8 | + await login( |
| 9 | + page, |
| 10 | + process.env.APP_URL, |
| 11 | + process.env.USER_NAME, |
| 12 | + process.env.PASSWORD |
| 13 | + ); |
| 14 | + }); |
| 15 | + |
| 16 | + test("Field report for Event", async ({ page }) => { |
| 17 | + |
| 18 | + const { formName, |
| 19 | + country, |
| 20 | + district, |
| 21 | + disasterType, |
| 22 | + date, |
| 23 | + title, |
| 24 | + govRequest, |
| 25 | + nationalsocietyRequest, |
| 26 | + num_injured, |
| 27 | + gov_num_injured, |
| 28 | + other_num_injured, |
| 29 | + num_dead, |
| 30 | + gov_num_dead, |
| 31 | + other_num_dead, |
| 32 | + num_missing, |
| 33 | + gov_num_missing, |
| 34 | + other_num_missing, |
| 35 | + num_affected, |
| 36 | + gov_num_affected, |
| 37 | + other_num_affected, |
| 38 | + num_displaced, |
| 39 | + other_num_displaced, |
| 40 | + gov_num_displaced, |
| 41 | + other_sources, |
| 42 | + gov_num_assisted, |
| 43 | + num_assisted, |
| 44 | + num_localstaff, |
| 45 | + num_volunteers, |
| 46 | + num_expats_delegates, |
| 47 | + actionHuman, |
| 48 | + actionEvacuation, |
| 49 | + actionHealth, |
| 50 | + actionShelter, |
| 51 | + actionCamp, |
| 52 | + actionFirst, |
| 53 | + actionPsychosocial, |
| 54 | + actionFood, |
| 55 | + nationalSocietySummary, |
| 56 | + federationSummary, |
| 57 | + rcrcSummary, |
| 58 | + informationBulletin, |
| 59 | + actionOther, |
| 60 | + interventionOptionOne, |
| 61 | + interventionOptionTwo, |
| 62 | + interventionOptionThree, |
| 63 | + drefRequested, |
| 64 | + emergencyAppeal, |
| 65 | + rapidResponse, |
| 66 | + emergencyResponse, |
| 67 | + originatorName, |
| 68 | + originatorTitle, |
| 69 | + originatorEmail, |
| 70 | + originatorPhone, |
| 71 | + nationalName, |
| 72 | + nationalTitle, |
| 73 | + nationalEmail, |
| 74 | + nationalPhone, |
| 75 | + ifrcName, |
| 76 | + ifrcTitle, |
| 77 | + ifrcEmail, |
| 78 | + ifrcPhone, |
| 79 | + mediaName, |
| 80 | + mediaTitle, |
| 81 | + mediaEmail, |
| 82 | + mediaPhone, |
| 83 | + visibiltyOptOne, |
| 84 | + visibiltyOptTwo |
| 85 | + } = fixtureData; |
| 86 | + |
| 87 | + await page.getByRole("button", { name: "Create a Report" }).click(); |
| 88 | + await page.getByRole("link", { name: "New Field Report" }).click(); |
| 89 | + await expect(page.locator('h1')).toContainText(formName); |
| 90 | + // Context Page |
| 91 | + await page.locator('input[name="country"]').fill(country); |
| 92 | + await page.getByRole("button", { name: country }).click(); |
| 93 | + await page.locator('input[name="districts"]').fill(district); |
| 94 | + await page.getByRole("button", { name: district }).click(); |
| 95 | + await page.locator('input[name="dtype"]').fill(disasterType); |
| 96 | + await page.getByRole("button", { name: disasterType }).click(); |
| 97 | + await page.locator('input[name="start_date"]').fill(date); |
| 98 | + const newtitle = await page.inputValue('input[type="text"]'); |
| 99 | + await page.getByPlaceholder("Example: Cyclone Cody").fill(title); |
| 100 | + await page.locator('label').filter({ hasText: govRequest }).nth(1).click(); |
| 101 | + await page.locator('label').filter({ hasText: nationalsocietyRequest }).nth(2).click(); |
| 102 | + await page.getByRole("button", { name: "Continue" }).click(); |
| 103 | + // Situation Page |
| 104 | + await page.locator('input[name="num_injured"]').fill(num_injured); |
| 105 | + await page.locator('input[name="gov_num_injured"]').fill(gov_num_injured); |
| 106 | + await page.locator('input[name="other_num_injured"]').fill(other_num_injured); |
| 107 | + await page.locator('input[name="num_dead"]').fill(num_dead); |
| 108 | + await page.locator('input[name="gov_num_dead"]').fill(gov_num_dead); |
| 109 | + await page.locator('input[name="other_num_dead"]').fill(other_num_dead); |
| 110 | + await page.locator('input[name="num_missing"]').fill(num_missing); |
| 111 | + await page.locator('input[name="gov_num_missing"]').fill(gov_num_missing); |
| 112 | + await page.locator('input[name="other_num_missing"]').fill(other_num_missing); |
| 113 | + await page.locator('input[name="num_affected"]').fill(num_affected); |
| 114 | + await page.locator('input[name="gov_num_affected"]').fill(gov_num_affected); |
| 115 | + await page.locator('input[name="other_num_affected"]').fill(other_num_affected); |
| 116 | + await page.locator('input[name="num_displaced"]').fill(num_displaced); |
| 117 | + await page.locator('input[name="gov_num_displaced"]').fill(gov_num_displaced); |
| 118 | + await page.locator('input[name="other_num_displaced"]').fill(other_num_displaced); |
| 119 | + await page.locator('textarea[name="other_sources"]').fill(other_sources); |
| 120 | + // await page.frameLocator('iframe[title="Rich Text Area"]').locator('html').fill("Just the random data"); |
| 121 | + // issue in Situational overview textbox |
| 122 | + await page.getByRole("button", { name: "Continue" }).click(); |
| 123 | + // Action Page |
| 124 | + await page.locator('input[name="gov_num_assisted"]').fill(gov_num_assisted); |
| 125 | + await page.locator('input[name="num_assisted"]').fill(num_assisted); |
| 126 | + await page.locator('input[name="num_localstaff"]').fill(num_localstaff); |
| 127 | + await page.locator('input[name="num_volunteers"]').fill(num_volunteers); |
| 128 | + await page.locator('input[name="num_expats_delegates"]').fill(num_expats_delegates); |
| 129 | + // Action taken by National red cross society |
| 130 | + await page.locator('label').filter({ hasText: actionHuman }).first().click(); |
| 131 | + await page.locator('label').filter({ hasText: actionShelter }).first().click(); |
| 132 | + await page.locator('label').filter({ hasText: actionEvacuation }).first().click(); |
| 133 | + await page.getByPlaceholder('Brief description of the action').first() |
| 134 | + .fill(nationalSocietySummary); |
| 135 | + // Action Taken by IFRC |
| 136 | + await page.locator('label').filter({ hasText: actionHealth }).nth(1).click(); |
| 137 | + await page.locator('label').filter({ hasText: actionShelter }).nth(1).click(); |
| 138 | + await page.locator('label').filter({ hasText: actionCamp }).nth(1).click(); |
| 139 | + await page.getByPlaceholder('Brief description of the').nth(1).fill(federationSummary); |
| 140 | + // Action Taken By any other RCRC movement actors |
| 141 | + await page.locator('label').filter({ hasText: actionFirst }).nth(2).click(); |
| 142 | + await page.locator('label').filter({ hasText: actionPsychosocial }).nth(2).click(); |
| 143 | + await page.locator('label').filter({ hasText: actionFood }).nth(2).click(); |
| 144 | + await page.getByPlaceholder('Brief description of the').nth(2).fill(rcrcSummary); |
| 145 | + await page.locator('label').filter({ hasText: informationBulletin }).click(); |
| 146 | + await page.locator('textarea[name="actions_others"]').fill(actionOther); |
| 147 | + await page.getByRole("button", { name: "Continue" }).click(); |
| 148 | + // Response Page |
| 149 | + // DREF Requested |
| 150 | + await page.locator('label').filter({ hasText: interventionOptionOne }).first().click(); |
| 151 | + await page.locator('input[name="dref_amount"]').fill(drefRequested); |
| 152 | + //Emergency Appeal |
| 153 | + await page.locator('label').filter({ hasText: interventionOptionTwo }).nth(1).click(); |
| 154 | + await page.locator('input[name="appeal_amount"]').fill(emergencyAppeal); |
| 155 | + //Rapid Response Personnel |
| 156 | + await page.locator('label').filter({ hasText: interventionOptionThree }).nth(2).click(); |
| 157 | + await page.locator('input[name="num_fact"]').fill(rapidResponse); |
| 158 | + // Emergency Response Units |
| 159 | + await page.locator('label').filter({ hasText: interventionOptionTwo }).nth(3).click(); |
| 160 | + await page.locator('input[name="num_ifrc_staff"]').fill(emergencyResponse); |
| 161 | + // Originator |
| 162 | + await page.locator('input[name="name"]').nth(0).fill(originatorName); |
| 163 | + await page.locator('input[name="title"]').nth(0).fill(originatorTitle); |
| 164 | + await page.locator('input[name="email"]').nth(0).fill(originatorEmail); |
| 165 | + await page.locator('input[name="phone"]').nth(0).fill(originatorPhone); |
| 166 | + // National Society Contact |
| 167 | + await page.locator('input[name="name"]').nth(1).fill(nationalName); |
| 168 | + await page.locator('input[name="title"]').nth(1).fill(nationalTitle); |
| 169 | + await page.locator('input[name="email"]').nth(1).fill(nationalEmail); |
| 170 | + await page.locator('input[name="phone"]').nth(1).fill(nationalPhone); |
| 171 | + // IFRC Focal Point for the Emergency |
| 172 | + await page.locator('input[name="name"]').nth(2).fill(ifrcName); |
| 173 | + await page.locator('input[name="title"]').nth(2).fill(ifrcTitle); |
| 174 | + await page.locator('input[name="email"]').nth(2).fill(ifrcEmail); |
| 175 | + await page.locator('input[name="phone"]').nth(2).fill(ifrcPhone); |
| 176 | + // Media Contact |
| 177 | + await page.locator('input[name="name"]').nth(3).fill(mediaName); |
| 178 | + await page.locator('input[name="title"]').nth(3).fill(mediaTitle); |
| 179 | + await page.locator('input[name="email"]').nth(3).fill(mediaEmail); |
| 180 | + await page.locator('input[name="phone"]').nth(3).fill(mediaPhone); |
| 181 | + // Field report visible |
| 182 | + await page.locator('label').filter({ hasText: visibiltyOptTwo }).click(); |
| 183 | + await page.getByRole("button", { name: "Submit" }).click(); |
| 184 | + await expect(page.locator("body")).toContainText( |
| 185 | + "Field report updated, redirecting..." |
| 186 | + ); |
| 187 | + // Title Assertion |
| 188 | + await expect(page.locator('h1')).toContainText(newtitle + " - " + title); |
| 189 | + // Data Assertion |
| 190 | + await expect(page.getByRole('banner')).toContainText(disasterType); |
| 191 | + await expect(page.getByRole('banner')).toContainText(country); |
| 192 | + const frVisibility = page.getByText('Visibility', { exact: true }).locator('..'); |
| 193 | + await expect(frVisibility).toHaveText("Visibility" + visibiltyOptTwo); |
| 194 | + const frDate = page.getByText('Start Date', { exact: true }).locator('..'); |
| 195 | + await expect(frDate).toHaveText("Start Date" + date); |
| 196 | + // Assertions to verify whether the data inserted on the form are displayed on the UI // Numeric Details |
| 197 | + const numericDetails = [ |
| 198 | + { label: 'Injured (RC)', value: formatNumber(num_injured) }, |
| 199 | + { label: 'Injured (Government)', value: formatNumber(gov_num_injured)}, |
| 200 | + { label: 'Injured (Other)', value: formatNumber(other_num_injured)}, |
| 201 | + { label: 'Missing (RC)', value: formatNumber(num_missing)}, |
| 202 | + { label: 'Missing (Government)', value: formatNumber(gov_num_missing)}, |
| 203 | + { label: 'Missing (Other)', value: formatNumber(other_num_missing)}, |
| 204 | + { label: 'Dead (RC)', value: formatNumber(num_dead)}, |
| 205 | + { label: 'Dead (Government)', value: formatNumber(gov_num_dead)}, |
| 206 | + { label: 'Dead (Other)', value: formatNumber(other_num_dead) }, |
| 207 | + { label: 'Displaced (RC)', value: formatNumber(num_displaced) }, |
| 208 | + { label: 'Displaced (Government)', value: formatNumber(gov_num_displaced) }, |
| 209 | + { label: 'Displaced (Other)', value: formatNumber(other_num_displaced) }, |
| 210 | + { label: 'Affected (RC)', value: formatNumber(num_affected) }, |
| 211 | + { label: 'Affected (Government)', value: formatNumber(gov_num_affected) }, |
| 212 | + { label: 'Affected (Other)', value: formatNumber(other_num_affected) }, |
| 213 | + { label: 'Assisted (RC)', value: formatNumber(num_assisted) }, |
| 214 | + { label: 'Assisted (Government)', value: formatNumber(gov_num_assisted) }, |
| 215 | + { label: 'Local Staff', value: formatNumber(num_localstaff) }, |
| 216 | + { label: 'Volunteers', value: formatNumber(num_volunteers) }, |
| 217 | + { label: 'IFRC Staff', value: formatNumber(emergencyResponse) }, |
| 218 | + { label: 'Delegates', value: formatNumber(num_expats_delegates) } |
| 219 | + ]; |
| 220 | + for (const detail of numericDetails) { |
| 221 | + const parentElement = page.getByText(detail.label).locator('..'); |
| 222 | + const textContent = parentElement.nth(0); |
| 223 | + await expect(textContent).toContainText(detail.value); |
| 224 | + } |
| 225 | + // Source Marked as Others Assertions |
| 226 | + const sourceChild = page.getByText('Sources for data marked as Other', {exact: true}); |
| 227 | + const sourceParent = sourceChild.locator('..').locator('..').locator('..').locator('..'); |
| 228 | + await expect (sourceParent).toContainText(other_sources); |
| 229 | + // Request for Assistance Assertions |
| 230 | + const govReq = page.getByText('Government Requests International Assistance', { exact: true }).locator('..'); |
| 231 | + await expect(govReq).toHaveText("Government Requests International Assistance" + govRequest); |
| 232 | + const nsReq = page.getByText('NS Requests International Assistance', { exact: true }).locator('..'); |
| 233 | + await expect(nsReq).toHaveText("NS Requests International Assistance" + nationalsocietyRequest); |
| 234 | + // Information Bulletin Published Assertions |
| 235 | + const infoBulletin = page.getByText('Information Bulletin Published', { exact: true }); |
| 236 | + const bulletin = infoBulletin.locator('..').locator('..').locator('..').locator('..'); |
| 237 | + await expect(bulletin).toContainText(informationBulletin); |
| 238 | + // Assertions for actions taken by National Society, Federation and RCRC |
| 239 | + const sections = [ |
| 240 | + { |
| 241 | + childText: 'Actions taken by National Society', |
| 242 | + actions: [actionHuman, actionShelter, actionEvacuation], |
| 243 | + summaryIndex: 0, |
| 244 | + summaryText: nationalSocietySummary |
| 245 | + }, |
| 246 | + { |
| 247 | + childText: 'Actions Taken by Federation', |
| 248 | + actions: [actionHealth, actionShelter, actionCamp], |
| 249 | + summaryIndex: 1, |
| 250 | + summaryText: federationSummary |
| 251 | + }, |
| 252 | + { |
| 253 | + childText: 'Actions Taken by RCRC', |
| 254 | + actions: [actionFirst, actionPsychosocial, actionFood], |
| 255 | + summaryIndex: 2, |
| 256 | + summaryText: rcrcSummary |
| 257 | + } |
| 258 | + ]; |
| 259 | + |
| 260 | + for (const section of sections) { |
| 261 | + const sectionChild = page.getByText(section.childText); |
| 262 | + const sectionParent = sectionChild.locator('..').locator('..').locator('..').locator('..'); |
| 263 | + |
| 264 | + for (const action of section.actions) { |
| 265 | + await expect(sectionParent).toContainText(action); |
| 266 | + } |
| 267 | + |
| 268 | + const summary = page.getByText('Summary').nth(section.summaryIndex).locator('..'); |
| 269 | + await expect(summary).toContainText(section.summaryText); |
| 270 | + } |
| 271 | + // Actions taken by others assertions |
| 272 | + const actionParent = page.getByText('Actions taken by others', {exact: true}); |
| 273 | + const actionChild = actionParent.locator('..').locator('..').locator('..').locator('..'); |
| 274 | + await expect(actionChild).toContainText(actionOther); |
| 275 | + // Planned Intervention Assertions |
| 276 | + const drefPI = page.getByText('DREF', { exact: true }).locator('..'); |
| 277 | + await expect(drefPI).toHaveText("DREF" + interventionOptionOne); |
| 278 | + const emergencyPI = page.getByText('Emergency Appeal', { exact: true }).locator('..'); |
| 279 | + await expect(emergencyPI).toHaveText("Emergency Appeal" + interventionOptionTwo); |
| 280 | + const rapidPI = page.getByText('Rapid Response Personnel', { exact: true }).locator('..'); |
| 281 | + await expect(rapidPI).toHaveText("Rapid Response Personnel" + interventionOptionThree); |
| 282 | + const emergencyResponsePI = page.getByText('Emergency Response Units', { exact: true }).locator('..'); |
| 283 | + await expect(emergencyResponsePI).toHaveText("Emergency Response Units" + interventionOptionTwo); |
| 284 | + // Assertions to verify the contacts |
| 285 | + // Originator |
| 286 | + const originatorDetail = page.getByText('Uday, Project Manager, [email protected], 9802556314'); |
| 287 | + expect(originatorDetail).toContainText(originatorName + ", " + originatorTitle + ", " + originatorEmail + ", " + originatorPhone); |
| 288 | + // National Society |
| 289 | + const nationalSocietyDetail = page.getByText('Navin, Network Engineer, [email protected], 9804115777'); |
| 290 | + expect(nationalSocietyDetail).toContainText(nationalName + ", " + nationalTitle + ", " + nationalEmail + ", " + nationalPhone); |
| 291 | + // Federation |
| 292 | + const federationDetail = page.getByText("Ankit, CEO, [email protected], 9801447523"); |
| 293 | + expect(federationDetail).toContainText(ifrcName + ", " + ifrcTitle + ", " + ifrcEmail + ", " + ifrcPhone); |
| 294 | + // Media |
| 295 | + const mediaDetail = page.getByText("Shreya, Shreya uffu, [email protected], 9805441239"); |
| 296 | + expect(mediaDetail).toContainText(mediaName + ", " + mediaTitle + ", " + mediaEmail + ", " + mediaPhone); |
| 297 | + }); |
| 298 | +}); |
| 299 | + |
| 300 | + |
| 301 | + |
| 302 | + |
0 commit comments