|
| 1 | +const { test, expect } = require('@playwright/test'); |
| 2 | + |
| 3 | +const config = require('../../../config'); |
| 4 | +const common = require('../../../common'); |
| 5 | + |
| 6 | +// These values represent the data values used for the conditions and are initialised in pyDefault DT |
| 7 | +const isDisabled = true; |
| 8 | +const isVisible = true; |
| 9 | + |
| 10 | +test.beforeEach(async ({ page }) => { |
| 11 | + await page.setViewportSize({ width: 1920, height: 1080 }); |
| 12 | + await page.goto(config.config.baseUrl, { waitUntil: 'networkidle' }); |
| 13 | +}); |
| 14 | + |
| 15 | +test.describe('E2E test', () => { |
| 16 | + let attributes; |
| 17 | + |
| 18 | + test('should login, create case and run the RichText tests', async ({ page }) => { |
| 19 | + await common.login(config.config.apps.digv2.user.username, config.config.apps.digv2.user.password, page); |
| 20 | + |
| 21 | + /** Testing announcement banner presence */ |
| 22 | + const announcementBanner = page.locator('h2:has-text("Announcements")'); |
| 23 | + await expect(announcementBanner).toBeVisible(); |
| 24 | + |
| 25 | + /** Testing worklist presence */ |
| 26 | + const worklist = page.locator('div[id="worklist"]:has-text("My Worklist")'); |
| 27 | + await expect(worklist).toBeVisible(); |
| 28 | + |
| 29 | + /** Click on the Create Case button */ |
| 30 | + const createCase = page.locator('mat-list-item[id="create-case-button"]'); |
| 31 | + await createCase.click(); |
| 32 | + |
| 33 | + /** Creating a Form Field case-type */ |
| 34 | + const formFieldCase = page.locator('mat-list-item[id="case-list-item"] > span:has-text("Form Field")'); |
| 35 | + await formFieldCase.click(); |
| 36 | + |
| 37 | + /** Selecting RichText from the Category dropdown */ |
| 38 | + const selectedCategory = page.locator('mat-select[data-test-id="76729937a5eb6b0fd88c42581161facd"]'); |
| 39 | + await selectedCategory.click(); |
| 40 | + await page.getByRole('option', { name: 'RichText' }).click(); |
| 41 | + |
| 42 | + /** Selecting Required from the Sub Category dropdown */ |
| 43 | + let selectedSubCategory = page.locator('mat-select[data-test-id="9463d5f18a8924b3200b56efaad63bda"]'); |
| 44 | + await selectedSubCategory.click(); |
| 45 | + await page.getByRole('option', { name: 'Required' }).click(); |
| 46 | + |
| 47 | + /** Required tests */ |
| 48 | + const requiredRichTextContainer = page.locator('div[data-test-id="98a97d9fe6d092900021587f62ab8637"]'); |
| 49 | + const requiredRichTextLabel = requiredRichTextContainer.locator('label'); |
| 50 | + expect(await requiredRichTextLabel.innerText()).toEqual('RichText Required'); |
| 51 | + await page.locator('button:has-text("submit")').click(); |
| 52 | + let canNotBeBlankMsg = await requiredRichTextContainer.locator('p:has-text("Cannot be blank")'); |
| 53 | + expect(canNotBeBlankMsg).toBeVisible(); |
| 54 | + |
| 55 | + const notRequiredRichTextContainer = page.locator('div[data-test-id="913fcb2ea3513d1f0dd357aa1766757f"]'); |
| 56 | + const notRequiredRichTextLabel = notRequiredRichTextContainer.locator('label'); |
| 57 | + expect(await notRequiredRichTextLabel.innerText()).toEqual('RichText Not Required'); |
| 58 | + await page.locator('button:has-text("submit")').click(); |
| 59 | + canNotBeBlankMsg = await notRequiredRichTextContainer.locator('p:has-text("Cannot be blank")'); |
| 60 | + expect(canNotBeBlankMsg).not.toBeVisible(); |
| 61 | + |
| 62 | + /** Selecting Disable from the Sub Category dropdown */ |
| 63 | + selectedSubCategory = page.locator('mat-select[data-test-id="9463d5f18a8924b3200b56efaad63bda"]'); |
| 64 | + await selectedSubCategory.click(); |
| 65 | + await page.getByRole('option', { name: 'Disable' }).click(); |
| 66 | + |
| 67 | + /** Disable tests */ |
| 68 | + // Always Disabled RichText |
| 69 | + const alwaysDisabledRichTextContainer = page.locator('div[data-test-id="f8a6fa176e492f0b2c3a2ecce916a1cc"]'); |
| 70 | + const alwaysDisabledRichTextLabel = alwaysDisabledRichTextContainer.locator('label'); |
| 71 | + expect(await alwaysDisabledRichTextLabel.innerText()).toEqual('RichText Disabled Always'); |
| 72 | + const alwaysDisabledRichTextBox = alwaysDisabledRichTextContainer.locator('div[role="application"]'); |
| 73 | + attributes = await common.getAttributes(alwaysDisabledRichTextBox); |
| 74 | + await expect(attributes.includes('aria-disabled')).toBeTruthy(); |
| 75 | + |
| 76 | + // Conditionally Disabled RichText |
| 77 | + const conditionallyDisabledRichTextContainer = page.locator('div[data-test-id="a1f1fed886e4277998358560643d5b80"]'); |
| 78 | + const conditionallyDisabledRichTextLabel = conditionallyDisabledRichTextContainer.locator('label'); |
| 79 | + expect(await conditionallyDisabledRichTextLabel.innerText()).toEqual('RichText Disabled Condition'); |
| 80 | + const conditionallyDisabledRichTextBox = conditionallyDisabledRichTextContainer.locator('div[role="application"]'); |
| 81 | + attributes = await common.getAttributes(conditionallyDisabledRichTextBox); |
| 82 | + if (isDisabled) { |
| 83 | + await expect(attributes.includes('aria-disabled')).toBeTruthy(); |
| 84 | + } else { |
| 85 | + await expect(attributes.includes('aria-disabled')).toBeFalsy(); |
| 86 | + } |
| 87 | + |
| 88 | + // Never Disabled RichText |
| 89 | + const neverDisabledRichTextContainer = page.locator('div[data-test-id="0706d1c3117909bba5dc3b11282c84c1"]'); |
| 90 | + const neverDisabledRichTextLabel = neverDisabledRichTextContainer.locator('label'); |
| 91 | + expect(await neverDisabledRichTextLabel.innerText()).toEqual('RichText Disabled Never'); |
| 92 | + const neverDisabledRichTextBox = neverDisabledRichTextContainer.locator('div[role="application"]'); |
| 93 | + const disabledValue = await neverDisabledRichTextBox.getAttribute('aria-disabled'); |
| 94 | + await expect(disabledValue).toBe('false'); |
| 95 | + |
| 96 | + /** Selecting Update from the Sub Category dropdown */ |
| 97 | + selectedSubCategory = page.locator('mat-select[data-test-id="9463d5f18a8924b3200b56efaad63bda"]'); |
| 98 | + await selectedSubCategory.click(); |
| 99 | + await page.getByRole('option', { name: 'Update' }).click(); |
| 100 | + |
| 101 | + /** Update tests */ |
| 102 | + const readOnlyRichTextContainer = page.locator('div[data-test-id="2698790fe2608356645f7f37e47d4017"]'); |
| 103 | + const readOnlyRichTextLabel = readOnlyRichTextContainer.locator('label'); |
| 104 | + expect(await readOnlyRichTextLabel.innerText()).toEqual('RichText ReadOnly'); |
| 105 | + const readOnlyRTEDiv = readOnlyRichTextContainer.locator('div[class="readonly-richtext-editor"]'); |
| 106 | + expect(readOnlyRTEDiv).toBeVisible(); |
| 107 | + |
| 108 | + const editableRichTextContainer = page.locator('div[data-test-id="c5f3892e688f607040637162ef2d61e2"]'); |
| 109 | + const editableRichTextLabel = editableRichTextContainer.locator('label'); |
| 110 | + expect(await editableRichTextLabel.innerText()).toEqual('RichText Editable'); |
| 111 | + const editableRichTextDiv = editableRichTextContainer.locator('div[role="application"]'); |
| 112 | + expect(editableRichTextDiv).toBeVisible(); |
| 113 | + |
| 114 | + /** Selecting Visibility from the Sub Category dropdown */ |
| 115 | + selectedSubCategory = page.locator('mat-select[data-test-id="9463d5f18a8924b3200b56efaad63bda"]'); |
| 116 | + await selectedSubCategory.click(); |
| 117 | + await page.getByRole('option', { name: 'Visibility' }).click(); |
| 118 | + |
| 119 | + /** Visibility tests */ |
| 120 | + await expect(page.locator('div[data-test-id="4094af7d82d8e88494423b891852cfb3"]')).toBeVisible(); |
| 121 | + |
| 122 | + const neverVisibleRichText = await page.locator('div[data-test-id="be4eec910ae6fd21f9ff706a3d64dc58"]'); |
| 123 | + await expect(neverVisibleRichText).not.toBeVisible(); |
| 124 | + |
| 125 | + const conditionallyVisibleRichText = await page.locator('div[data-test-id="c50c684046dd7f7ca04fd9e35ed0ec92"]'); |
| 126 | + |
| 127 | + if (isVisible) { |
| 128 | + await expect(conditionallyVisibleRichText).toBeVisible(); |
| 129 | + } else { |
| 130 | + await expect(conditionallyVisibleRichText).not.toBeVisible(); |
| 131 | + } |
| 132 | + }, 10000); |
| 133 | +}); |
| 134 | + |
| 135 | +test.afterEach(async ({ page }) => { |
| 136 | + await page.close(); |
| 137 | +}); |
0 commit comments