From 57da5295fb77c1162560a12782dd01df6f179e06 Mon Sep 17 00:00:00 2001 From: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> Date: Wed, 3 Apr 2024 07:58:57 +0700 Subject: [PATCH] test(playwright): add exam-results-modal tests (#54091) --- e2e/exam-results-modal.spec.ts | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 e2e/exam-results-modal.spec.ts diff --git a/e2e/exam-results-modal.spec.ts b/e2e/exam-results-modal.spec.ts new file mode 100644 index 00000000000..6d58d81708f --- /dev/null +++ b/e2e/exam-results-modal.spec.ts @@ -0,0 +1,63 @@ +import { test, expect } from '@playwright/test'; + +test.use({ storageState: 'playwright/.auth/certified-user.json' }); + +test.describe('Exam results modal', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/settings'); + }); + + test('should display the content correctly', async ({ page }) => { + const viewButton = page.getByRole('button', { + name: 'View Results for Foundational C# with Microsoft Certification Exam' + }); + + await expect(viewButton).toBeVisible(); + await viewButton.click(); + + await expect(page.getByRole('dialog')).toHaveCount(2); + + await expect( + page.getByRole('heading', { + name: 'Results for Foundational C# with Microsoft Certification Exam' + }) + ).toBeVisible(); + await expect(page.getByText('Number of questions: 80')).toBeVisible(); + await expect(page.getByText('Correct answers: 70')).toBeVisible(); + await expect(page.getByText('Percent correct: 87.5%')).toBeVisible(); + await expect(page.getByText('Time: 36:35')).toBeVisible(); + await expect(page.getByRole('button', { name: 'Close' })).toHaveCount(2); + }); + + test('should close when the x button is clicked', async ({ page }) => { + const viewButton = page.getByRole('button', { + name: 'View Results for Foundational C# with Microsoft Certification Exam' + }); + await expect(viewButton).toBeVisible(); + await viewButton.click(); + + await expect(page.getByRole('dialog')).toHaveCount(2); + + // There are 2 close buttons on the page, and the x button is the first + const closeButton = page.getByRole('button', { name: 'Close' }).first(); + await closeButton.click(); + + await expect(page.getByRole('dialog')).toHaveCount(0); + }); + + test('should close when the close button is clicked', async ({ page }) => { + const viewButton = page.getByRole('button', { + name: 'View Results for Foundational C# with Microsoft Certification Exam' + }); + await expect(viewButton).toBeVisible(); + await viewButton.click(); + + await expect(page.getByRole('dialog')).toHaveCount(2); + + // There are 2 close buttons on the page, and the close button is the last + const closeButton = page.getByRole('button', { name: 'Close' }).last(); + await closeButton.click(); + + await expect(page.getByRole('dialog')).toHaveCount(0); + }); +});