Skip to content

Commit adb43b0

Browse files
authoredFeb 20, 2024
test(core): add tests for sort order local storage values (#5764)
1 parent c29014a commit adb43b0

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
 

‎packages/sanity/src/structure/components/pane/PaneContextMenuButton.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function PaneContextMenuButton(props: PaneContextMenuButtonProps) {
4343
<ContextMenuButton
4444
// eslint-disable-next-line no-nested-ternary
4545
tone={hasCritical ? 'critical' : hasCaution ? 'caution' : undefined}
46+
data-testid="pane-context-menu-button"
4647
/>
4748
}
4849
id={id}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {expect} from '@playwright/test'
2+
import {test} from '@sanity/test'
3+
4+
//we should also check for custom sort orders`
5+
test('clicking sort order and direction sets value in storage', async ({page}) => {
6+
await page.goto('/test/content/author')
7+
await page.getByTestId('pane').getByTestId('pane-context-menu-button').click()
8+
await page.getByRole('menuitem', {name: 'Sort by Name'}).click()
9+
const localStorage = await page.evaluate(() => window.localStorage)
10+
11+
expect(localStorage['structure-tool::author::sortOrder']).toBe(
12+
'{"by":[{"field":"name","direction":"asc"}],"extendedProjection":"name"}',
13+
)
14+
15+
await page.getByTestId('pane').getByTestId('pane-context-menu-button').click()
16+
await page.getByRole('menuitem', {name: 'Sort by Last Edited'}).click()
17+
const lastEditedLocalStorage = await page.evaluate(() => window.localStorage)
18+
19+
expect(lastEditedLocalStorage['structure-tool::author::sortOrder']).toBe(
20+
'{"by":[{"field":"_updatedAt","direction":"desc"}],"extendedProjection":""}',
21+
)
22+
})
23+
24+
test('clicking list view sets value in storage', async ({page}) => {
25+
await page.goto('/test/content/author')
26+
await page.getByTestId('pane').getByTestId('pane-context-menu-button').click()
27+
await page.getByRole('menuitem', {name: 'Detailed view'}).click()
28+
const localStorage = await page.evaluate(() => window.localStorage)
29+
30+
expect(localStorage['structure-tool::author::layout']).toBe('"detail"')
31+
32+
await page.getByTestId('pane').getByTestId('pane-context-menu-button').click()
33+
await page.getByRole('menuitem', {name: 'Compact view'}).click()
34+
const compactLocalStorage = await page.evaluate(() => window.localStorage)
35+
36+
expect(compactLocalStorage['structure-tool::author::layout']).toBe('"default"')
37+
})
38+
39+
test('values persist after navigating away and back', async ({page}) => {
40+
await page.goto('/test/content/author')
41+
await page.getByTestId('pane').getByTestId('pane-context-menu-button').click()
42+
await page.getByRole('menuitem', {name: 'Detailed view'}).click()
43+
await page.goto('https://example.com')
44+
await page.goto('/test/content/author')
45+
const localStorage = await page.evaluate(() => window.localStorage)
46+
47+
expect(localStorage['structure-tool::author::layout']).toBe('"detail"')
48+
})

0 commit comments

Comments
 (0)
Please sign in to comment.