From 6a58c8ac8a67d971eb34178688be8c9d50d7b34d Mon Sep 17 00:00:00 2001 From: Radi Totev Date: Mon, 30 Oct 2023 14:17:55 +0200 Subject: [PATCH] test(e2e,playwright): hotkeys (#52158) Co-authored-by: Oliver Eyton-Williams --- e2e/hotkeys.spec.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 e2e/hotkeys.spec.ts diff --git a/e2e/hotkeys.spec.ts b/e2e/hotkeys.spec.ts new file mode 100644 index 00000000000..60c1d163e7a --- /dev/null +++ b/e2e/hotkeys.spec.ts @@ -0,0 +1,51 @@ +import { test, expect } from '@playwright/test'; + +import translations from '../client/i18n/locales/english/translations.json'; + +const course = + '/learn/javascript-algorithms-and-data-structures/basic-javascript/comment-your-javascript-code'; +const editorPaneLabel = + 'Editor content;Press Alt+F1 for Accessibility Options.'; + +test.use({ storageState: 'playwright/.auth/certified-user.json' }); + +test('User can interact with the app using the keyboard', async ({ + page, + browserName +}) => { + test.skip( + browserName === 'webkit', + 'Failing on webkit for no apparent reason. Can not reproduce locally.' + ); + + // Enable keyboard shortcuts + await page.goto('/settings'); + const keyboardShortcutGroup = page.getByRole('group', { + name: translations.settings.labels['keyboard-shortcuts'] + }); + await keyboardShortcutGroup + .getByRole('button', { name: translations.buttons.on, exact: true }) + .click(); + + await page.goto(course); + + await expect(page.getByLabel(editorPaneLabel)).toBeFocused(); + await page.getByLabel(editorPaneLabel).press('Escape'); + await expect(page.getByLabel(editorPaneLabel)).not.toBeFocused(); + + await page.keyboard.press('n'); + const nextCourse = '**/declare-javascript-variables'; + await page.waitForURL(nextCourse); + + await page.keyboard.press('p'); + const previousCourse = '**/comment-your-javascript-code'; + await page.waitForURL(previousCourse); + + await page.keyboard.press('e'); + await expect(page.getByLabel(editorPaneLabel)).toBeFocused(); + + await page.keyboard.press('Control+Enter'); + await expect(page.getByText('running test')).toBeVisible(); + + // Show shortcuts (shift+/) is covered by the shortcuts-modal tests +});