ronantakizawa/codereview-bench huggingface dataset:
Repository: freeCodeCamp/freeCodeCamp
File: e2e/academic-honesty.spec.ts (TypeScript)

Code before:
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.describe('When the user has not accepted the Academic Honesty Policy', () => {
  test.use({ storageState: 'playwright/.auth/development-user.json' });

  test.beforeAll(() => {
    execSync('node ./tools/scripts/seed/seed-demo-user');
  });

  test('Should validate Academy Honesty Settings', async ({ page }) => {
    await page.goto('/settings');
    await expect(
      page.getByRole('heading', {
        name: translations.settings.headings.honesty
      })
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p1)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p2)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p3)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p4)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p5)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p6)
    ).toBeVisible();
    const agreeButton = page.getByRole('button', {

Review comment (suggestion):
```suggestion
  test('they should be able to accept it', async ({ page }) => {
```

Code after:
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.describe('When the user has not accepted the Academic Honesty Policy', () => {
  test.use({ storageState: 'playwright/.auth/development-user.json' });

  test.beforeEach(() => {
    execSync('node ./tools/scripts/seed/seed-demo-user');
  });

  test('they should be able to accept it', async ({ page }) => {
    await page.goto('/settings');
    await expect(
      page.getByRole('heading', {
        name: translations.settings.headings.honesty
      })
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p1)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p2)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p3)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p4)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p5)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p6)
    ).toBeVisible();
    const agreeButton = page.getByRole('button', {
Repository: freeCodeCamp/freeCodeCamp
File: e2e/academic-honesty.spec.ts (TypeScript)

Code before:
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.describe('When the user has not accepted the Academic Honesty Policy', () => {
  test.use({ storageState: 'playwright/.auth/development-user.json' });

  test.beforeAll(() => {
    execSync('node ./tools/scripts/seed/seed-demo-user');
  });

  test('Should validate Academy Honesty Settings', async ({ page }) => {
    await page.goto('/settings');
    await expect(
      page.getByRole('heading', {
        name: translations.settings.headings.honesty
      })
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p1)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p2)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p3)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p4)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p5)
    ).toBeVisible();

Review comment (suggestion):
```suggestion
  test.beforeEach(() => {
```
See below for reasoning.

Code after:
import { execSync } from 'child_process';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.describe('When the user has not accepted the Academic Honesty Policy', () => {
  test.use({ storageState: 'playwright/.auth/development-user.json' });

  test.beforeEach(() => {
    execSync('node ./tools/scripts/seed/seed-demo-user');
  });

  test('they should be able to accept it', async ({ page }) => {
    await page.goto('/settings');
    await expect(
      page.getByRole('heading', {
        name: translations.settings.headings.honesty
      })
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p1)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p2)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p3)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p4)
    ).toBeVisible();
    await expect(
      page.getByText(translations.settings.honesty.p5)
    ).toBeVisible();
Repository: freeCodeCamp/freeCodeCamp
File: e2e/header.spec.ts (TypeScript)

Code before:
  await expect(page.getByTestId(headerComponentElements.examNav)).toBeVisible();
  await expect(
    page.getByTestId(headerComponentElements.examNavLogo)
  ).toBeVisible();
});

test('The Sign In button should redirect to api/signin', async ({
  browser
}) => {
  // Sign out user in order to test Sign In button
  const context = await browser.newContext({
    storageState: { cookies: [], origins: [] }
  });
  const page = await context.newPage();
  await page.goto('/');

  const signInButton = page.getByRole('link', {
    name: translations.buttons['sign-in']
  });

  const apiLocation = process.env.API_LOCATION || 'http://localhost:3000';

  await expect(signInButton).toHaveAttribute('href', `${apiLocation}/signin`);
});

test('When the user is signed out, only certain elements should be visibvle', async ({
  browser
}) => {
  const context = await browser.newContext({
    storageState: { cookies: [], origins: [] }
  });
  const page = await context.newPage();
  await page.goto('/');
  const signInButton = page
    .getByTestId(headerComponentElements.signInButton)
    .nth(0);
  await expect(signInButton).toBeVisible();
  await expect(page.locator('.avatar-nav-link')).toBeHidden();
  await expect(page.locator('.avatar-container')).toBeHidden();
});


Review comment (suggestion):
```suggestion
test('When the user is signed out, only certain elements should be visible', async ({
```

Code after:
  await expect(page.getByTestId(headerComponentElements.examNav)).toBeVisible();
  await expect(
    page.getByTestId(headerComponentElements.examNavLogo)
  ).toBeVisible();
});

test('The Sign In button should redirect to api/signin', async ({
  browser
}) => {
  // Sign out user in order to test Sign In button
  const context = await browser.newContext({
    storageState: { cookies: [], origins: [] }
  });
  const page = await context.newPage();
  await page.goto('/');

  const signInButton = page.getByRole('link', {
    name: translations.buttons['sign-in']
  });

  const apiLocation = process.env.API_LOCATION || 'http://localhost:3000';

  await expect(signInButton).toHaveAttribute('href', `${apiLocation}/signin`);
});

test('When the user is signed out, only certain elements should be visible', async ({
  browser
}) => {
  const context = await browser.newContext({
    storageState: { cookies: [], origins: [] }
  });
  const page = await context.newPage();
  await page.goto('/');
  const signInButton = page
    .getByTestId(headerComponentElements.signInButton)
    .nth(0);
  await expect(signInButton).toBeVisible();
  await expect(page.locator('.avatar-nav-link')).toBeHidden();
  await expect(page.locator('.avatar-container')).toBeHidden();
});
Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/settings.test.ts (TypeScript)

Code before:
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import {
  devLogin,
  setupServer,
  superRequest,
  createSuperRequest,
  defaultUserId
} from '../../jest.utils';
import { createUserInput } from '../utils/create-user';

import { isPictureWithProtocol, getWaitMessage } from './settings';

const baseProfileUI = {
  isLocked: false,
  showAbout: false,
  showCerts: false,
  showDonation: false,
  showHeatMap: false,
  showLocation: false,
  showName: false,
  showPoints: false,
  showPortfolio: false,
  showTimeLine: false
};

const profileUI = {
  ...baseProfileUI,
  isLocked: true,
  showAbout: true,
  showDonation: true,
  showLocation: true,
  showName: true,
  showPortfolio: true
};


Review comment (suggestion):
```suggestion
import { API_LOCATION } from '../utils/env';
```

Code after:
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import {
  devLogin,
  setupServer,
  superRequest,
  createSuperRequest,
  defaultUserId
} from '../../jest.utils';
import { createUserInput } from '../utils/create-user';
import { API_LOCATION } from '../utils/env';
import { isPictureWithProtocol, getWaitMessage } from './settings';

const baseProfileUI = {
  isLocked: false,
  showAbout: false,
  showCerts: false,
  showDonation: false,
  showHeatMap: false,
  showLocation: false,
  showName: false,
  showPoints: false,
  showPortfolio: false,
  showTimeLine: false
};

const profileUI = {
  ...baseProfileUI,
  isLocked: true,
  showAbout: true,
  showDonation: true,
  showLocation: true,
  showName: true,
  showPortfolio: true
};
Repository: freeCodeCamp/freeCodeCamp
File: e2e/hotkeys.spec.ts (TypeScript)

Code before:

test('User can use shortcuts to navigate between projects', async ({
  page
}) => {
  await page.goto(links.frontEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.frontEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.frontEnd1);
});

test('User can use shortcuts to navigate backend projects', async ({
  page
}) => {
  await page.goto(links.backEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.backEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.backEnd1);
});

test('User can use shortcuts to navigate videos', async ({ page }) => {
  await page.goto(links.video1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.video2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.video1);
});


Review comment (suggestion):
```suggestion
  await expect(getEditors(page)).toBeFocused();
```

Code after:

test('User can use shortcuts to navigate between frontend projects', async ({
  page
}) => {
  await page.goto(links.frontEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.frontEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.frontEnd1);
});

test('User can use shortcuts to navigate between backend projects', async ({
  page
}) => {
  await page.goto(links.backEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.backEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.backEnd1);
});

test('User can use shortcuts to navigate between video-based challenges', async ({
  page
}) => {
  await page.goto(links.video1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.video2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.video1);
});
Repository: freeCodeCamp/freeCodeCamp
File: e2e/hotkeys.spec.ts (TypeScript)

Code before:
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.frontEnd1);
});

test('User can use shortcuts to navigate backend projects', async ({
  page
}) => {
  await page.goto(links.backEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.backEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.backEnd1);
});

test('User can use shortcuts to navigate videos', async ({ page }) => {
  await page.goto(links.video1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.video2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.video1);
});


Review comment (suggestion):
```suggestion
  await expect(getEditors(page)).toBeFocused();
```

Code after:
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.frontEnd1);
});

test('User can use shortcuts to navigate between backend projects', async ({
  page
}) => {
  await page.goto(links.backEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.backEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.backEnd1);
});

test('User can use shortcuts to navigate between video-based challenges', async ({
  page
}) => {
  await page.goto(links.video1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.video2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.video1);
});
Repository: freeCodeCamp/freeCodeCamp
File: e2e/hotkeys.spec.ts (TypeScript)

Code before:

test('User can use shortcuts to navigate backend projects', async ({
  page
}) => {
  await page.goto(links.backEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.backEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.backEnd1);
});

test('User can use shortcuts to navigate videos', async ({ page }) => {
  await page.goto(links.video1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.video2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.video1);
});


Review comment (suggestion):
```suggestion
  await expect(getEditors(page)).toBeFocused();
```

Code after:

test('User can use shortcuts to navigate between backend projects', async ({
  page
}) => {
  await page.goto(links.backEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.backEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.backEnd1);
});

test('User can use shortcuts to navigate between video-based challenges', async ({
  page
}) => {
  await page.goto(links.video1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.video2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.video1);
});
Repository: freeCodeCamp/freeCodeCamp
File: e2e/hotkeys.spec.ts (TypeScript)

Code before:
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.frontEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.frontEnd1);
});

test('User can use shortcuts to navigate backend projects', async ({
  page
}) => {
  await page.goto(links.backEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.backEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.backEnd1);
});

test('User can use shortcuts to navigate videos', async ({ page }) => {
  await page.goto(links.video1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.video2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.video1);
});


Review comment (suggestion):
```suggestion
test('User can use shortcuts to navigate between video-based challenges', async ({ page }) => {
```

Code after:
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.frontEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.frontEnd1);
});

test('User can use shortcuts to navigate between backend projects', async ({
  page
}) => {
  await page.goto(links.backEnd1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.backEnd2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.backEnd1);
});

test('User can use shortcuts to navigate between video-based challenges', async ({
  page
}) => {
  await page.goto(links.video1);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('Escape');
  await page.keyboard.press('n');

  await page.waitForURL(links.video2);
  await expect(page.locator('#editor-layout')).toBeFocused();
  await page.keyboard.press('p');
  await page.keyboard.press('Escape');
  await page.waitForURL(links.video1);
});
Repository: freeCodeCamp/freeCodeCamp
File: e2e/legacy-editor.spec.ts (TypeScript)

Code before:
import { test, expect } from '@playwright/test';
import { focusEditor } from './utils/editor';

test.describe('Editor Shortcuts', () => {
  test('Should handle Alt+Enter', async ({ page, isMobile }) => {
    await page.goto(
      'learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements'
    );
    await focusEditor({ page, isMobile });

    await page.keyboard.press('Control+Enter');
    await expect(
      page.getByTestId('editor-container-indexhtml').getByText('<h1>Hello</h1>')
    ).toBeVisible();
  });

  test('Should ignore Ctrl+Enter', async ({ page, isMobile }) => {
    await page.goto(
      'learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements'
    );
    await focusEditor({ page, isMobile });

    await page.keyboard.press('Control+Enter');
    await expect(
      page.getByTestId('editor-container-indexhtml').getByText('<h1>Hello</h1>')
    ).toBeVisible();
  });
});


Review comment (suggestion):
```suggestion
    await page.keyboard.press('Alt+Enter');
```

Code after:
import { test, expect } from '@playwright/test';
import { focusEditor } from './utils/editor';

test.describe('Editor Shortcuts', () => {
  test('Should add a new line if the user presses Alt+Enter', async ({
    page,
    isMobile
  }) => {
    await page.goto(
      'learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements'
    );
    await focusEditor({ page, isMobile });

    await page.keyboard.press('Alt+Enter');
    await expect(
      page
        .getByTestId('editor-container-indexhtml')
        .getByText('<h1>Hello</h1>\n')
    ).toBeVisible();
  });

  test('Should not add a new line if the user presses Ctrl+Enter', async ({
    page,
    isMobile
  }) => {
    await page.goto(
      'learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements'
    );
    await focusEditor({ page, isMobile });

    await page.keyboard.press('Control+Enter');
    await expect(
      page.getByTestId('editor-container-indexhtml').getByText('<h1>Hello</h1>')
    ).toBeVisible();
  });
});