From 3a2f357ec117cc84b1b2a605726b865bbb56d498 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Mon, 14 Oct 2024 15:13:09 +1030 Subject: [PATCH] Add test case for enableWhen multi-checkbox fix --- apps/smart-forms-app/e2e/items.spec.ts | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/apps/smart-forms-app/e2e/items.spec.ts b/apps/smart-forms-app/e2e/items.spec.ts index 62377b2e..c1286bd7 100644 --- a/apps/smart-forms-app/e2e/items.spec.ts +++ b/apps/smart-forms-app/e2e/items.spec.ts @@ -266,3 +266,62 @@ test('enter inputs into OpenChoiceCheckboxAVS questionnaire', async ({ page }) = expect(isACTCheckedAgain).toBe(true); expect(isQueenslandCheckedAgain).toBe(true); }); + +test('enableWhen multi-checkbox (also for repeating items)', async ({ page }) => { + // Select EnableWhenMultiCheckbox questionnaire + await page + .getByTestId('questionnaire-picker-playground') + .locator('input') + .fill('EnableWhenMultiCheckbox'); + await page.keyboard.press('Enter'); + await expect(page.getByTestId('questionnaire-details-playground')).toContainText( + 'EnableWhen Multi-select Checkbox' + ); + await expect(page.getByTestId('questionnaire-details-playground')).toContainText( + 'https://smartforms.csiro.au/docs/behavior/other/enable-when-multi-checkbox' + ); + + // Build OpenChoiceCheckboxAVS questionnaire + await page.getByTestId('picker-build-form-button-playground').click(); + await expect(page.getByText('"resourceType": "Questionnaire"')).toBeInViewport(); + await expect(page.getByText('"id": "EnableWhenMultiCheckbox"')).toBeInViewport(); + + const openChoiceCheckboxLinkId = 'select-conditions-list'; + + // Check on a single option, then check for displayed enableWhen display question + await page + .locator( + `div[data-test="q-item-open-choice-checkbox-answer-option-box"][data-linkid="${openChoiceCheckboxLinkId}"]` + ) + .locator('label:has-text("Condition A (Displays Clinical guidance: Condition A question)")') + .check(); + + await expect(page.getByTestId('q-item-display-box')).toContainText( + 'Clinical guidance: Condition A' + ); + + // Check on options A. B. C, then check for all displayed enableWhen display questions + await page + .locator( + `div[data-test="q-item-open-choice-checkbox-answer-option-box"][data-linkid="${openChoiceCheckboxLinkId}"]` + ) + .locator('label:has-text("Condition B (Displays Clinical guidance: Condition B question)")') + .check(); + + await page + .locator( + `div[data-test="q-item-open-choice-checkbox-answer-option-box"][data-linkid="${openChoiceCheckboxLinkId}"]` + ) + .locator('label:has-text("Condition C (Displays Clinical guidance: Condition C question)")') + .check(); + + await expect(page.getByTestId('q-item-display-box').first()).toContainText( + 'Clinical guidance: Condition A' + ); + await expect(page.getByTestId('q-item-display-box').nth(1)).toContainText( + 'Clinical guidance: Condition B' + ); + await expect(page.getByTestId('q-item-display-box').nth(2)).toContainText( + 'Clinical guidance: Condition C' + ); +});