|
| 1 | +// Copyright 2026 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +import {test, expect} from '@playwright/test'; |
| 5 | +import {login_user, load_logged_in_context} from './utils_e2e.ts'; |
| 6 | + |
| 7 | +test.beforeAll(async ({browser}, workerInfo) => { |
| 8 | + await login_user(browser, workerInfo, 'user2'); |
| 9 | +}); |
| 10 | + |
| 11 | +test.describe('Repository Keyboard Shortcuts', () => { |
| 12 | + test('T key focuses file search input', async ({browser}, workerInfo) => { |
| 13 | + const context = await load_logged_in_context(browser, workerInfo, 'user2'); |
| 14 | + const page = await context.newPage(); |
| 15 | + |
| 16 | + // Navigate to a repository page with file listing |
| 17 | + await page.goto('/user2/repo1'); |
| 18 | + await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle |
| 19 | + |
| 20 | + // Verify the file search input exists and has the keyboard hint |
| 21 | + const fileSearchInput = page.locator('.repo-file-search-container input'); |
| 22 | + await expect(fileSearchInput).toBeVisible(); |
| 23 | + |
| 24 | + // Verify the keyboard hint is visible |
| 25 | + const kbdHint = page.locator('.repo-file-search-input-wrapper kbd'); |
| 26 | + await expect(kbdHint).toBeVisible(); |
| 27 | + await expect(kbdHint).toHaveText('T'); |
| 28 | + |
| 29 | + // Press T key to focus the file search input |
| 30 | + await page.keyboard.press('t'); |
| 31 | + |
| 32 | + // Verify the input is focused |
| 33 | + await expect(fileSearchInput).toBeFocused(); |
| 34 | + }); |
| 35 | + |
| 36 | + test('T key does not trigger when typing in input', async ({browser}, workerInfo) => { |
| 37 | + const context = await load_logged_in_context(browser, workerInfo, 'user2'); |
| 38 | + const page = await context.newPage(); |
| 39 | + |
| 40 | + // Navigate to a repository page |
| 41 | + await page.goto('/user2/repo1'); |
| 42 | + await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle |
| 43 | + |
| 44 | + // Focus on file search first |
| 45 | + const fileSearchInput = page.locator('.repo-file-search-container input'); |
| 46 | + await fileSearchInput.click(); |
| 47 | + |
| 48 | + // Type something including 't' |
| 49 | + await page.keyboard.type('test'); |
| 50 | + |
| 51 | + // Verify the input still has focus and contains the typed text |
| 52 | + await expect(fileSearchInput).toBeFocused(); |
| 53 | + await expect(fileSearchInput).toHaveValue('test'); |
| 54 | + }); |
| 55 | + |
| 56 | + test('S key focuses code search input on repo home', async ({browser}, workerInfo) => { |
| 57 | + const context = await load_logged_in_context(browser, workerInfo, 'user2'); |
| 58 | + const page = await context.newPage(); |
| 59 | + |
| 60 | + // Navigate to repo home page where code search is available |
| 61 | + await page.goto('/user2/repo1'); |
| 62 | + await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle |
| 63 | + |
| 64 | + // The code search input is in the sidebar |
| 65 | + const codeSearchInput = page.locator('.code-search-input'); |
| 66 | + await expect(codeSearchInput).toBeVisible(); |
| 67 | + |
| 68 | + // Verify the keyboard hint is visible |
| 69 | + const kbdHint = page.locator('.repo-code-search-input-wrapper .repo-search-shortcut-hint'); |
| 70 | + await expect(kbdHint).toBeVisible(); |
| 71 | + await expect(kbdHint).toHaveText('S'); |
| 72 | + |
| 73 | + // Press S key to focus the code search input |
| 74 | + await page.keyboard.press('s'); |
| 75 | + |
| 76 | + // Verify the input is focused |
| 77 | + await expect(codeSearchInput).toBeFocused(); |
| 78 | + }); |
| 79 | + |
| 80 | + test('File search keyboard hint hides when input has value', async ({browser}, workerInfo) => { |
| 81 | + const context = await load_logged_in_context(browser, workerInfo, 'user2'); |
| 82 | + const page = await context.newPage(); |
| 83 | + |
| 84 | + // Navigate to a repository page |
| 85 | + await page.goto('/user2/repo1'); |
| 86 | + await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle |
| 87 | + |
| 88 | + // Check file search kbd hint |
| 89 | + const fileSearchInput = page.locator('.repo-file-search-container input'); |
| 90 | + const fileKbdHint = page.locator('.repo-file-search-input-wrapper kbd'); |
| 91 | + |
| 92 | + // Initially the hint should be visible |
| 93 | + await expect(fileKbdHint).toBeVisible(); |
| 94 | + |
| 95 | + // Focus and type in the file search |
| 96 | + await fileSearchInput.click(); |
| 97 | + await page.keyboard.type('test'); |
| 98 | + |
| 99 | + // The hint should now be hidden (Vue component handles this with v-show) |
| 100 | + await expect(fileKbdHint).toBeHidden(); |
| 101 | + }); |
| 102 | + |
| 103 | + test('Code search keyboard hint hides when input has value', async ({browser}, workerInfo) => { |
| 104 | + const context = await load_logged_in_context(browser, workerInfo, 'user2'); |
| 105 | + const page = await context.newPage(); |
| 106 | + |
| 107 | + // Navigate to a repository page |
| 108 | + await page.goto('/user2/repo1'); |
| 109 | + await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle |
| 110 | + |
| 111 | + const codeSearchInput = page.locator('.code-search-input'); |
| 112 | + await expect(codeSearchInput).toBeVisible(); |
| 113 | + |
| 114 | + const codeKbdHint = page.locator('.repo-code-search-input-wrapper .repo-search-shortcut-hint'); |
| 115 | + |
| 116 | + // Initially the hint should be visible |
| 117 | + await expect(codeKbdHint).toBeVisible(); |
| 118 | + |
| 119 | + // Focus and type in the code search |
| 120 | + await codeSearchInput.click(); |
| 121 | + await page.keyboard.type('search'); |
| 122 | + |
| 123 | + // The hint should now be hidden |
| 124 | + await expect(codeKbdHint).toBeHidden(); |
| 125 | + }); |
| 126 | + |
| 127 | + test('Shortcuts do not trigger with modifier keys', async ({browser}, workerInfo) => { |
| 128 | + const context = await load_logged_in_context(browser, workerInfo, 'user2'); |
| 129 | + const page = await context.newPage(); |
| 130 | + |
| 131 | + // Navigate to a repository page |
| 132 | + await page.goto('/user2/repo1'); |
| 133 | + await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle |
| 134 | + |
| 135 | + const fileSearchInput = page.locator('.repo-file-search-container input'); |
| 136 | + |
| 137 | + // Click somewhere else first to ensure nothing is focused |
| 138 | + await page.locator('body').click(); |
| 139 | + |
| 140 | + // Press Ctrl+T (should not focus file search - this is typically "new tab" in browsers) |
| 141 | + await page.keyboard.press('Control+t'); |
| 142 | + |
| 143 | + // The file search input should NOT be focused |
| 144 | + await expect(fileSearchInput).not.toBeFocused(); |
| 145 | + }); |
| 146 | +}); |
0 commit comments