Skip to content

Commit

Permalink
test: improve project preview modal spec (freeCodeCamp#54528)
Browse files Browse the repository at this point in the history
Co-authored-by: Naomi <[email protected]>
  • Loading branch information
ojeytonwilliams and Naomi authored Apr 25, 2024
1 parent cf2485f commit 0fa65de
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions e2e/project-preview-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,26 @@ import { test, expect } from '@playwright/test';

import translations from '../client/i18n/locales/english/translations.json';

const currentUrlPath =
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-1';

test.beforeEach(async ({ page }) => {
await page.goto(currentUrlPath);
});

test.describe('Exit Project Preview Modal E2E Test Suite', () => {
test('Verifies the Correct Rendering of the Project Preview Modal', async ({
page
}) => {
await expect(
page.getByRole('button', {
name: translations.buttons.close
})
).toBeVisible();

const dialog = page.getByRole('dialog', {
name: translations.learn['project-preview-title']
});
await expect(dialog).toBeVisible();
await expect(dialog.getByTitle('CatPhotoApp preview')).toBeVisible();
await expect(
page.getByRole('button', { name: 'Start Coding!' })
).toBeVisible();
test.describe('When it renders', () => {
test.beforeEach(async ({ page }) => {
const urlWithProjectPreview =
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-1';
await page.goto(urlWithProjectPreview);
});

test('Closes the Project Preview Modal When the User clicks on the close Button', async ({
page
}) => {
test('it can be closed by the Start Coding! button', async ({ page }) => {
const dialog = page.getByRole('dialog', {
name: translations.learn['project-preview-title']
});

await expect(dialog).toBeVisible();
await expect(dialog.getByTitle('CatPhotoApp preview')).toBeVisible();

await page.getByRole('button', { name: 'Start Coding!' }).click();

await expect(dialog).not.toBeVisible();
});

test('Closes the Project Preview Modal when the User clicks on X button', async ({
page
}) => {
test('it can be closed by the close button', async ({ page }) => {
const dialog = page.getByRole('dialog', {
name: translations.learn['project-preview-title']
});
Expand All @@ -60,26 +36,24 @@ test.describe('Exit Project Preview Modal E2E Test Suite', () => {
});
});

test.describe('Project Preview Modal Conditional Rendering', () => {
test('Does not render on second step of a project', async ({ page }) => {
test.describe('It should on appear', () => {
test('on the second step of a project', async ({ page }) => {
await page.goto(
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-2'
);
const dialog = page.getByRole('dialog', {
name: translations.learn['project-preview-title']
});
await expect(dialog).toHaveCount(0);
await expect(dialog).not.toBeVisible();
});

test('Does not render on first step of a project without a preview', async ({
page
}) => {
test('on first step of a project without a preview', async ({ page }) => {
await page.goto(
'/learn/javascript-algorithms-and-data-structures-v8/learn-introductory-javascript-by-building-a-pyramid-generator/step-1'
);
const dialog = page.getByRole('dialog', {
name: translations.learn['project-preview-title']
});
await expect(dialog).toHaveCount(0);
await expect(dialog).not.toBeVisible();
});
});

0 comments on commit 0fa65de

Please sign in to comment.