Repository: freeCodeCamp/freeCodeCamp
File: e2e/completion-modal.spec.ts (TypeScript)

Code before:
    .click();
});

test.describe('Challenge Completion Modal Tests (Signed Out)', () => {
  test('should render the modal correctly', async ({ page }) => {
    await expect(page.getByRole('heading')).toBeVisible();
    await expect(page.getByRole('button', { name: 'close' })).toBeVisible();
    await expect(page.getByTestId('completion-success-icon')).toBeVisible();
    await expect(page.getByTestId('progress-bar-container')).toBeVisible();
    await expect(
      page.getByRole('link', { name: translations.learn['sign-in-save'] })
    ).toBeVisible();
    await expect(
      page.getByRole('button', { name: translations.buttons['go-to-next'] })
    ).toBeVisible();
  });

  test('should close the modal after user click on close', async ({ page }) => {
    await page.getByRole('button', { name: 'close' }).click();
    await expect(page.getByTestId('completion-success-icon')).not.toBeVisible();
  });

  test('should close the modal after user presses escape if user is not signed in', async ({
    page
  }) => {
    await page.keyboard.press('Escape');
    await expect(page.getByRole('dialog')).not.toBeVisible();
  });

  test('should display the text of go to next challenge button accordingly based on device type', async ({
    page,
    isMobile,
    browserName
  }) => {
    if (isMobile) {
      await expect(
        page.getByRole('button', {
          name: 'Go to next challenge',
          exact: true
        })
      ).toBeVisible();
    } else if (browserName === 'webkit') {
      await expect(
        page.getByRole('button', {
          name: 'Go to next challenge (Command + Enter)'
        })
      ).toBeVisible();
    } else {
      await expect(
        page.getByRole('button', {
          name: 'Go to next challenge (Ctrl + Enter)'

Review comment (security):
We should ensure that there is a dialog on the screen before pressing Escape.

```suggestion
  }) => {
    await expect(page.getByRole('dialog')).toBeVisible();
    await page.keyboard.press('Escape');
```

Code after:
    .click();
});

test.describe('Challenge Completion Modal Tests (Signed Out)', () => {
  test('should render the modal correctly', async ({ page }) => {
    await expect(page.getByRole('heading')).toBeVisible();
    await expect(page.getByRole('button', { name: 'close' })).toBeVisible();
    await expect(page.getByTestId('completion-success-icon')).toBeVisible();
    await expect(page.getByTestId('progress-bar-container')).toBeVisible();
    await expect(
      page.getByRole('link', { name: translations.learn['sign-in-save'] })
    ).toBeVisible();
    await expect(
      page.getByRole('button', { name: translations.buttons['go-to-next'] })
    ).toBeVisible();
  });

  test('should close the modal after user click on close', async ({ page }) => {
    await page.getByRole('button', { name: 'close' }).click();
    await expect(page.getByTestId('completion-success-icon')).not.toBeVisible();
  });

  test('should close the modal after user presses escape', async ({ page }) => {
    await expect(page.getByRole('dialog')).toBeVisible();
    await page.keyboard.press('Escape');
    await expect(page.getByRole('dialog')).not.toBeVisible();
  });

  test('should display the text of go to next challenge button accordingly based on device type', async ({
    page,
    isMobile,
    browserName
  }) => {
    if (isMobile) {
      await expect(
        page.getByRole('button', {
          name: 'Go to next challenge',
          exact: true
        })
      ).toBeVisible();
    } else if (browserName === 'webkit') {
      await expect(
        page.getByRole('button', {
          name: 'Go to next challenge (Command + Enter)'
        })
      ).toBeVisible();
    } else {
      await expect(
        page.getByRole('button', {
          name: 'Go to next challenge (Ctrl + Enter)'
        })