Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html): mirror query clearing in URL #33689

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/html-reporter/src/headerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ export const HeaderView: React.FC<React.PropsWithChildren<{
<form className='subnav-search' onSubmit={
event => {
event.preventDefault();
navigate(`#?q=${filterText ? encodeURIComponent(filterText) : ''}`);
if (filterText)
navigate(`#?` + new URLSearchParams({ q: filterText }));
else
navigate('#');
}
}>
{icons.search()}
{/* Use navigationId to reset defaultValue */}
<input type='search' spellCheck={false} className='form-control subnav-search-input input-contrast width-full' value={filterText} onChange={e => {
setFilterText(e.target.value);
const filterText = e.target.value;
if (filterText)
setFilterText(filterText);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the value state synchronously and unconditionally would bring me great comfort. My React could be better, but isn't it a general requirement?

else
navigate('#');
Copy link
Member

@pavelfeldman pavelfeldman Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I'm mostly using keyboard and do Select all + Backspace or press and hold Backspace you want me to have an unusual history treatment? Not sure it is within the accepted UX guidelines. Why does Input have no "clearedUsingMouse" event for that use case?

}}></input>
</form>
</div>
Expand Down
19 changes: 19 additions & 0 deletions tests/playwright-test/reporter-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,25 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await expect(page.getByText('a.test.js:4', { exact: true })).toBeVisible();
});

test('filter should be mirrored in URL', async ({ runInlineTest, showReport, page }) => {
const result = await runInlineTest({
'a.test.js': `
const { test, expect } = require('@playwright/test');
test('test1', async ({}) => { expect(1).toBe(1); });
`,
}, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' });

expect(result.exitCode).toBe(0);

await showReport();
const searchInput = page.locator('.subnav-search-input');
await searchInput.fill('a.test.js:3:11');
await searchInput.press('Enter');
await page.waitForURL(url => new URLSearchParams(url.hash.slice(1)).get('q') === 'a.test.js:3:11');
await searchInput.clear();
await page.waitForURL(url => !new URLSearchParams(url.hash.slice(1)).has('q'));
});

test('should properly display beforeEach with and without title', async ({ runInlineTest, showReport, page }) => {
const result = await runInlineTest({
'a.test.js': `
Expand Down