From 437c8f9c03f580379cf64cb210875e81e31a2451 Mon Sep 17 00:00:00 2001 From: Drew Del Rosario Date: Wed, 20 Sep 2023 21:11:48 -0700 Subject: [PATCH 1/7] WIP add tests for ER status update --- e2e/tests/erStatus.spec.js | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 e2e/tests/erStatus.spec.js diff --git a/e2e/tests/erStatus.spec.js b/e2e/tests/erStatus.spec.js new file mode 100644 index 00000000..19ca4144 --- /dev/null +++ b/e2e/tests/erStatus.spec.js @@ -0,0 +1,77 @@ +const { test, expect } = require('@playwright/test'); + +test.describe('ER status', () => { + test.describe.configure({ mode: 'serial' }); + test('Update ER status', async ({ context }) => { + const appPage = await context.newPage(); + await appPage.goto('/'); + await appPage.getByLabel('Email').fill('ucsf.parnassus.er@c4sf.me'); + const password = appPage.getByLabel('Password'); + await password.fill('abcd1234'); + await password.press('Enter'); + await expect(appPage).toHaveURL('/er'); + await appPage.getByRole('button', { name: /hospital/i }).click(); + await expect(appPage.getByText(/available beds/i)).toBeVisible(); + await expect(appPage.getByText(/er conditions/i)).toBeVisible(); + await appPage.getByRole('button', { name: /update hospital/i }).click(); + await appPage.getByRole('textbox', { name: /er beds/i }).fill('5'); + await appPage.getByRole('textbox', { name: /behavioral beds/i }).fill('8'); + await appPage.locator('#additionalNotes').fill('scanner broke'); + await appPage.getByRole('button', { name: /confirm/i }).click(); + }); + + test('EMS checks hospital status', async ({ context }) => { + const appPage = await context.newPage(); + await appPage.goto('/'); + await appPage.getByLabel('Email').fill('op.ems@c4sf.me'); + const password = appPage.getByLabel('Password'); + await password.fill('abcd1234'); + await password.press('Enter'); + await expect(appPage).toHaveURL('/ems'); + await appPage.getByRole('button', { name: /hospital info/i }).click(); + // await expect(appPage.locator('.hospitalstatusrow_container') + // .filter({ hasText: /ucsf parnassus/i }) + // .filter({ has: appPage.locator('.hospitalstatusrow__notes').filter({ hasText: 'scanner fixed' })})).toBeVisible(); + const row = appPage.locator('.hospitalstatusrow_container').filter({ hasText: /ucsf parnassus/i }); + + // await expect(row.locator('.hospitalstatusrow__data', { hasText: '5' })).toBeVisible(); + // await expect(row.locator('.hospitalstatusrow__data', { hasText: '8' })).toBeVisible(); + await expect(row.locator('.hospitalstatusrow__notes').filter({ hasText: 'scanner broke' })).toBeVisible(); + await context.close(); + }); + + test('Update ER status reset', async ({ context }) => { + const appPage = await context.newPage(); + await appPage.goto('/'); + await appPage.getByLabel('Email').fill('ucsf.parnassus.er@c4sf.me'); + const password = appPage.getByLabel('Password'); + await password.fill('abcd1234'); + await password.press('Enter'); + await expect(appPage).toHaveURL('/er'); + await appPage.getByRole('button', { name: /hospital/i }).click(); + await expect(appPage.getByText(/available beds/i)).toBeVisible(); + await expect(appPage.getByText(/er conditions/i)).toBeVisible(); + await appPage.getByRole('button', { name: /update hospital/i }).click(); + await appPage.getByRole('textbox', { name: /er beds/i }).fill('0'); + await appPage.getByRole('textbox', { name: /behavioral beds/i }).fill('0'); + await appPage.locator('#additionalNotes').fill(''); + await appPage.getByRole('button', { name: /confirm/i }).click(); + }); + + test('EMS checks hospital status after reset', async ({ context }) => { + const appPage = await context.newPage(); + await appPage.goto('/'); + await appPage.getByLabel('Email').fill('op.ems@c4sf.me'); + const password = appPage.getByLabel('Password'); + await password.fill('abcd1234'); + await password.press('Enter'); + await expect(appPage).toHaveURL('/ems'); + await appPage.getByRole('button', { name: /hospital info/i }).click(); + const row = appPage.locator('.hospitalstatusrow_container', { hasText: /ucsf parnassus/i }); + // console.log("ROW: ", row) + await expect(row.locator('.hospitalstatusrow__data', { hasText: '5' })).not.toBeVisible(); + await expect(row.locator('.hospitalstatusrow__data', { hasText: '8' })).not.toBeVisible(); + await expect(row.locator('.hospitalstatusrow__notes', { hasText: 'scanner broke' })).not.toBeVisible(); + await context.close(); + }); +}); From 6357b10ddb8577490c890e7a38555116eedc0331 Mon Sep 17 00:00:00 2001 From: Drew Del Rosario Date: Wed, 20 Sep 2023 21:13:09 -0700 Subject: [PATCH 2/7] UI changes to class names and readOnly setting --- client/src/Components/Counter.js | 9 ++++++++- client/src/EMS/HospitalStatusRow.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/client/src/Components/Counter.js b/client/src/Components/Counter.js index 059f79a7..56a08719 100644 --- a/client/src/Components/Counter.js +++ b/client/src/Components/Counter.js @@ -33,7 +33,14 @@ function Counter({ label, min, max, name, onChange, value, isEditing }) { − {!Number.isNaN(value) && ( - + )} {!Number.isNaN(value) && ( - + )} - diff --git a/client/src/ER/Beds.js b/client/src/ER/Beds.js index c50ca2d6..73ba1bb3 100644 --- a/client/src/ER/Beds.js +++ b/client/src/ER/Beds.js @@ -17,7 +17,7 @@ function Beds({ statusUpdate, onStatusUpdate, incomingRingdownsCount }) { function handleChange(event) { const newStatusUpdate = new HospitalStatus(statusUpdate); - newStatusUpdate[event.target.name] = parseInt(event.target.value, 10) || 0; + newStatusUpdate[event.target.name] = parseInt(event.target.value, 10); onStatusUpdate(newStatusUpdate); } diff --git a/e2e/tests/erStatus.spec.js b/e2e/tests/erStatus.spec.js index 4c32df51..8896be36 100644 --- a/e2e/tests/erStatus.spec.js +++ b/e2e/tests/erStatus.spec.js @@ -2,6 +2,9 @@ const { test, expect } = require('@playwright/test'); test.describe('ER status', () => { test.describe.configure({ mode: 'serial' }); + let erBeds = 0; + let behaviorBeds = 0; + test('Update ER status', async ({ context }) => { const appPage = await context.newPage(); await appPage.goto('/'); @@ -15,8 +18,20 @@ test.describe('ER status', () => { await expect(appPage.getByText(/available beds/i)).toBeVisible(); await expect(appPage.getByText(/er conditions/i)).toBeVisible(); await appPage.getByRole('button', { name: /update hospital/i }).click(); - await appPage.getByRole('textbox', { name: /er beds/i }).fill('5'); - await appPage.getByRole('textbox', { name: /behavioral beds/i }).fill('8'); + const erBedsRow = appPage.getByTestId('counter_openEdBedCount'); + erBeds = parseInt(await erBedsRow.getByRole('textbox').inputValue(), 10); + for (let i = 0; i < 5; i++) { + await erBedsRow.getByRole('button', { name: '+' }).click(); + erBeds += 1; + } + + const behaviorNode = appPage.getByLabel(/behavioral beds/i); + const behaviorBedsRow = appPage.getByTestId('counter_openPsychBedCount'); + behaviorBeds = parseInt(await behaviorNode.inputValue(), 10); + for (let i = 0; i < 8; i++) { + await behaviorBedsRow.getByRole('button', { name: '+' }).click(); + behaviorBeds += 1; + } await appPage.locator('#additionalNotes').fill('scanner broke'); await appPage.getByRole('button', { name: /confirm/i }).click(); }); @@ -31,8 +46,8 @@ test.describe('ER status', () => { await expect(appPage).toHaveURL('/ems'); await appPage.getByRole('button', { name: /hospital info/i }).click(); const ucsfRow = appPage.locator('.hospitalstatusrow_container').filter({ hasText: /ucsf parnassus/i }); - await expect(ucsfRow.locator('.hospitalstatusrow__data').filter({ hasText: '5' })).toBeVisible(); - await expect(ucsfRow.locator('.hospitalstatusrow__data').filter({ hasText: '8' })).toBeVisible(); + await expect(ucsfRow.locator('.hospitalstatusrow__data').filter({ hasText: `${erBeds}` })).toBeVisible(); + await expect(ucsfRow.locator('.hospitalstatusrow__data').filter({ hasText: `${behaviorBeds}` })).toBeVisible(); await expect(ucsfRow.getByText('scanner broke')).toBeVisible(); await context.close(); }); @@ -50,8 +65,22 @@ test.describe('ER status', () => { await expect(appPage.getByText(/available beds/i)).toBeVisible(); await expect(appPage.getByText(/er conditions/i)).toBeVisible(); await appPage.getByRole('button', { name: /update hospital/i }).click(); - await appPage.getByRole('textbox', { name: /er beds/i }).fill('0'); - await appPage.getByRole('textbox', { name: /behavioral beds/i }).fill('0'); + const erBedsRow = appPage.getByTestId('counter_openEdBedCount'); + erBeds = parseInt(await erBedsRow.getByRole('textbox').inputValue(), 10); + while (erBeds >= 0) { + await erBedsRow.getByTestId('decrement').click(); + erBeds--; + } + const erBedValue = await appPage.getByRole('textbox', { name: /er beds/i }).inputValue(); + expect(erBedValue).toBe('0'); + + const behaviorBedsRow = appPage.getByTestId('counter_openPsychBedCount'); + behaviorBeds = parseInt(await behaviorBedsRow.getByRole('textbox').inputValue(), 10); + while (behaviorBeds >= 0) { + await behaviorBedsRow.getByTestId('decrement').click(); + behaviorBeds--; + } + expect(await appPage.getByRole('textbox', { name: /behavioral beds/i }).inputValue()).toBe('0'); await appPage.locator('#additionalNotes').fill(''); await appPage.getByRole('button', { name: /confirm/i }).click(); }); From d6604c4d4443d51fd17a2f2d4203bdba6df1c588 Mon Sep 17 00:00:00 2001 From: Drew Del Rosario Date: Wed, 18 Oct 2023 19:34:04 -0700 Subject: [PATCH 6/7] Test cleanup --- e2e/tests/erStatus.spec.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/e2e/tests/erStatus.spec.js b/e2e/tests/erStatus.spec.js index 8896be36..7893198d 100644 --- a/e2e/tests/erStatus.spec.js +++ b/e2e/tests/erStatus.spec.js @@ -2,8 +2,8 @@ const { test, expect } = require('@playwright/test'); test.describe('ER status', () => { test.describe.configure({ mode: 'serial' }); - let erBeds = 0; - let behaviorBeds = 0; + let numberErBeds = 0; + let numberBehaviorBeds = 0; test('Update ER status', async ({ context }) => { const appPage = await context.newPage(); @@ -19,18 +19,18 @@ test.describe('ER status', () => { await expect(appPage.getByText(/er conditions/i)).toBeVisible(); await appPage.getByRole('button', { name: /update hospital/i }).click(); const erBedsRow = appPage.getByTestId('counter_openEdBedCount'); - erBeds = parseInt(await erBedsRow.getByRole('textbox').inputValue(), 10); + numberErBeds = parseInt(await erBedsRow.getByRole('textbox').inputValue(), 10); for (let i = 0; i < 5; i++) { await erBedsRow.getByRole('button', { name: '+' }).click(); - erBeds += 1; + numberErBeds++; } const behaviorNode = appPage.getByLabel(/behavioral beds/i); const behaviorBedsRow = appPage.getByTestId('counter_openPsychBedCount'); - behaviorBeds = parseInt(await behaviorNode.inputValue(), 10); + numberBehaviorBeds = parseInt(await behaviorNode.inputValue(), 10); for (let i = 0; i < 8; i++) { await behaviorBedsRow.getByRole('button', { name: '+' }).click(); - behaviorBeds += 1; + numberBehaviorBeds++; } await appPage.locator('#additionalNotes').fill('scanner broke'); await appPage.getByRole('button', { name: /confirm/i }).click(); @@ -46,8 +46,8 @@ test.describe('ER status', () => { await expect(appPage).toHaveURL('/ems'); await appPage.getByRole('button', { name: /hospital info/i }).click(); const ucsfRow = appPage.locator('.hospitalstatusrow_container').filter({ hasText: /ucsf parnassus/i }); - await expect(ucsfRow.locator('.hospitalstatusrow__data').filter({ hasText: `${erBeds}` })).toBeVisible(); - await expect(ucsfRow.locator('.hospitalstatusrow__data').filter({ hasText: `${behaviorBeds}` })).toBeVisible(); + await expect(ucsfRow.locator('.hospitalstatusrow__data').filter({ hasText: `${numberErBeds}` })).toBeVisible(); + await expect(ucsfRow.locator('.hospitalstatusrow__data').filter({ hasText: `${numberBehaviorBeds}` })).toBeVisible(); await expect(ucsfRow.getByText('scanner broke')).toBeVisible(); await context.close(); }); @@ -66,19 +66,19 @@ test.describe('ER status', () => { await expect(appPage.getByText(/er conditions/i)).toBeVisible(); await appPage.getByRole('button', { name: /update hospital/i }).click(); const erBedsRow = appPage.getByTestId('counter_openEdBedCount'); - erBeds = parseInt(await erBedsRow.getByRole('textbox').inputValue(), 10); - while (erBeds >= 0) { + numberErBeds = parseInt(await erBedsRow.getByRole('textbox').inputValue(), 10); + while (numberErBeds >= 0) { await erBedsRow.getByTestId('decrement').click(); - erBeds--; + numberErBeds--; } const erBedValue = await appPage.getByRole('textbox', { name: /er beds/i }).inputValue(); expect(erBedValue).toBe('0'); const behaviorBedsRow = appPage.getByTestId('counter_openPsychBedCount'); - behaviorBeds = parseInt(await behaviorBedsRow.getByRole('textbox').inputValue(), 10); - while (behaviorBeds >= 0) { + numberBehaviorBeds = parseInt(await behaviorBedsRow.getByRole('textbox').inputValue(), 10); + while (numberBehaviorBeds >= 0) { await behaviorBedsRow.getByTestId('decrement').click(); - behaviorBeds--; + numberBehaviorBeds--; } expect(await appPage.getByRole('textbox', { name: /behavioral beds/i }).inputValue()).toBe('0'); await appPage.locator('#additionalNotes').fill(''); From 0aa0cf2fa26a5d5761034f4433e816a65a748178 Mon Sep 17 00:00:00 2001 From: Drew Del Rosario Date: Wed, 18 Oct 2023 20:07:48 -0700 Subject: [PATCH 7/7] Update names for tests --- e2e/tests/erStatus.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/tests/erStatus.spec.js b/e2e/tests/erStatus.spec.js index 7893198d..3a0551f3 100644 --- a/e2e/tests/erStatus.spec.js +++ b/e2e/tests/erStatus.spec.js @@ -52,7 +52,7 @@ test.describe('ER status', () => { await context.close(); }); - test('Update ER status reset', async ({ context }) => { + test('Decrement beds in ER back to 0', async ({ context }) => { const appPage = await context.newPage(); await appPage.goto('/'); await appPage.getByLabel('Email').fill('ucsf.parnassus.er@c4sf.me'); @@ -85,7 +85,7 @@ test.describe('ER status', () => { await appPage.getByRole('button', { name: /confirm/i }).click(); }); - test('EMS checks hospital status after reset', async ({ context }) => { + test('Hospital status matches latest changes after decrementing', async ({ context }) => { const appPage = await context.newPage(); await appPage.goto('/'); await appPage.getByLabel('Email').fill('op.ems.1@c4sf.me');