mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 18:18:27 -05:00
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: DanielRosa74 <58576743+DanielRosa74@users.noreply.github.com>
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('Fill in the blanks challenge', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto(
|
|
'/learn/a2-english-for-developers/learn-greetings-in-your-first-day-at-the-office/task-47'
|
|
);
|
|
});
|
|
|
|
test('should display feedback if there is an incorrect answer', async ({
|
|
page
|
|
}) => {
|
|
const blanks = page.getByRole('textbox', { name: 'blank' });
|
|
|
|
await blanks.first().fill('this'); // Answer the first blank correctly
|
|
await blanks.last().fill('bar'); // Answer the second blank incorrectly
|
|
await page.getByRole('button', { name: 'Check your answer' }).click();
|
|
|
|
await expect(
|
|
page.getByText("Sorry, that's not the right answer. Give it another try?")
|
|
).toBeVisible();
|
|
|
|
// Once a blank is answered correctly, it is no longer rendered as an input field
|
|
await expect(blanks).toHaveCount(1);
|
|
|
|
await expect(blanks.last()).toHaveAttribute('aria-invalid', 'true');
|
|
});
|
|
|
|
test('should not display feedback if all blanks are answered correctly', async ({
|
|
page
|
|
}) => {
|
|
const blanks = page.getByRole('textbox', { name: 'blank' });
|
|
|
|
await blanks.first().fill('this');
|
|
await blanks.last().fill('those');
|
|
await page.getByRole('button', { name: 'Check your answer' }).click();
|
|
|
|
// Close the completion modal
|
|
await page
|
|
.getByRole('dialog')
|
|
.getByRole('button', { name: 'Close' })
|
|
.click();
|
|
|
|
await expect(
|
|
page.getByText("Sorry, that's not the right answer. Give it another try?")
|
|
).toBeHidden();
|
|
|
|
// There aren't any blanks as all the inputs are rendered as text
|
|
await expect(blanks).toBeHidden();
|
|
});
|
|
});
|