Repository: freeCodeCamp/freeCodeCamp
File: e2e/link-ms-user.spec.ts (TypeScript)

Code before:
    ).toBeVisible();

    // There are 2 sign in button on the page: one in the navbar, and one in the page content
    const signInButtons = await page
      .getByRole('link', { name: translations.buttons['sign-in'] })
      .all();
    expect(signInButtons).toHaveLength(2);
  });
});

test.describe('Link MS user component (signed-in user)', () => {
  test.afterEach(() => {
    execSync('node ./tools/scripts/seed/seed-ms-username');
  });
  test.use({ storageState: 'playwright/.auth/certified-user.json' });

  test("should recognize the user's MS account", async ({ page }) => {
    await expect(
      page.getByRole('heading', {
        name: 'Trophy - Write Your First Code Using C#',
        level: 1
      })
    ).toBeVisible();

    await expect(page.locator('main')).toHaveText(
      /The Microsoft account with username "certifieduser" is currently linked to your freeCodeCamp account. If this is not your Microsoft username, remove the link./
    );
  });

  test('should allow the user to unlink their MS account and display a form for re-link', async ({
    page
  }) => {
    const unlinkButton = page.getByRole('button', {
      name: translations.buttons['unlink-account']
    });
    await expect(unlinkButton).toBeVisible();
    await unlinkButton.click();

    await expect(
      page
        .getByRole('alert')
        .filter({ hasText: translations.flash.ms.transcript.unlinked })
    ).toBeVisible();

    await expect(
      page.getByRole('heading', {
        name: translations.learn.ms['link-header'],
        level: 2
      })
    ).toBeVisible();
    await expect(page.getByText(translations.learn.ms.unlinked)).toBeVisible();

Review comment (suggestion):
```suggestion
      /The Microsoft account with username "certifieduser" is currently linked to your freeCodeCamp account\. If this is not your Microsoft username, remove the link\./
```

Code after:
    ).toBeVisible();

    // There are 2 sign in button on the page: one in the navbar, and one in the page content
    const signInButtons = await page
      .getByRole('link', { name: translations.buttons['sign-in'] })
      .all();
    expect(signInButtons).toHaveLength(2);
  });
});

test.describe('Link MS user component (signed-in user)', () => {
  test.afterEach(() => {
    execSync('node ./tools/scripts/seed/seed-ms-username');
  });
  test.use({ storageState: 'playwright/.auth/certified-user.json' });

  test("should recognize the user's MS account", async ({ page }) => {
    await expect(
      page.getByRole('heading', {
        name: 'Trophy - Write Your First Code Using C#',
        level: 1
      })
    ).toBeVisible();

    await expect(page.locator('main')).toHaveText(
      /The Microsoft account with username "certifieduser" is currently linked to your freeCodeCamp account\. If this is not your Microsoft username, remove the link\./
    );
  });

  test('should allow the user to unlink their MS account and display a form for re-link', async ({
    page
  }) => {
    const unlinkButton = page.getByRole('button', {
      name: translations.buttons['unlink-account']
    });
    await expect(unlinkButton).toBeVisible();
    await unlinkButton.click();

    await expect(
      page
        .getByRole('alert')
        .filter({ hasText: translations.flash.ms.transcript.unlinked })
    ).toBeVisible();

    await expect(
      page.getByRole('heading', {
        name: translations.learn.ms['link-header'],
        level: 2
      })
    ).toBeVisible();
    await expect(page.getByText(translations.learn.ms.unlinked)).toBeVisible();