-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(website): preserve RulesTable filters state in searchParams (#6568
) * feat(website): preserve RulesTable filters state in searchParams * Move rules filters state to useLocation * Revert "Move rules filters state to useLocation" This reverts commit 7c2e81a. * Test rules filters in URL * Use .ruleset prop in RulesTable * Use useHistorySelector instead of useIsomorphicLayoutEffect * Move useHistorySelector to src/hooks * Fix lint errors
- Loading branch information
Showing
4 changed files
with
173 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useHistory } from '@docusaurus/router'; | ||
import type * as H from 'history'; | ||
import { useSyncExternalStore } from 'react'; | ||
|
||
export type HistorySelector<T> = (history: H.History<H.LocationState>) => T; | ||
|
||
export function useHistorySelector<T>( | ||
selector: HistorySelector<T>, | ||
getServerSnapshot: () => T, | ||
): T { | ||
const history = useHistory(); | ||
return useSyncExternalStore( | ||
history.listen, | ||
() => selector(history), | ||
getServerSnapshot, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import AxeBuilder from '@axe-core/playwright'; | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Rules Page', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/rules'); | ||
}); | ||
|
||
test('Accessibility', async ({ page }) => { | ||
await new AxeBuilder({ page }).analyze(); | ||
}); | ||
|
||
test('Rules filters are saved to the URL', async ({ page }) => { | ||
await page.getByText('🔧 fixable').first().click(); | ||
await page.getByText('✅ recommended').first().click(); | ||
await page.getByText('✅ recommended').first().click(); | ||
|
||
expect(new URL(page.url()).search).toBe( | ||
'?supported-rules=xrecommended-fixable', | ||
); | ||
}); | ||
|
||
test('Rules filters are read from the URL on page load', async ({ page }) => { | ||
await page.goto('/rules?supported-rules=strict-xfixable'); | ||
|
||
const strict = page.getByText('🔒 strict').first(); | ||
const fixable = page.getByText('🔧 fixable').first(); | ||
|
||
await expect(strict).toHaveAttribute('aria-label', /Current: include/); | ||
await expect(fixable).toHaveAttribute('aria-label', /Current: exclude/); | ||
}); | ||
}); |