-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kasper/redirect-boundary-and-fixes
- Loading branch information
Showing
13 changed files
with
1,574 additions
and
879 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"next/babel", | ||
{ | ||
"preset-env": { | ||
"targets": { "chrome": 117 } | ||
} | ||
} | ||
] | ||
] | ||
} |
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,28 @@ | ||
import { TestRunnerConfig, getStoryContext } from '@storybook/test-runner'; | ||
import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport'; | ||
|
||
const DEFAULT_VIEWPORT_SIZE = { width: 1280, height: 720 }; | ||
|
||
const config: TestRunnerConfig = { | ||
async preVisit(page, story) { | ||
const context = await getStoryContext(page, story); | ||
const viewportName = context.parameters?.viewport?.defaultViewport; | ||
const viewportParameter = MINIMAL_VIEWPORTS[viewportName]; | ||
|
||
if (viewportParameter) { | ||
const viewportSize = Object.entries(viewportParameter.styles).reduce( | ||
(acc, [screen, size]) => ({ | ||
...acc, | ||
// make sure your viewport config in Storybook only uses numbers, not percentages | ||
[screen]: parseInt(size), | ||
}), | ||
{} | ||
); | ||
|
||
page.setViewportSize(viewportSize); | ||
} else { | ||
page.setViewportSize(DEFAULT_VIEWPORT_SIZE); | ||
} | ||
}, | ||
}; | ||
export default config; |
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
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 |
---|---|---|
@@ -1,11 +1,48 @@ | ||
import { getRouter } from '@storybook/nextjs/navigation.mock' | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import Search from "./search"; | ||
import Search from './search' | ||
import { expect, fireEvent, userEvent, within } from '@storybook/test' | ||
|
||
const meta = { | ||
component: Search, | ||
} satisfies Meta<typeof Search> | ||
|
||
export default meta; | ||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
export const Default: Story = {} | ||
export const Default: Story = {} | ||
|
||
export const WithInput: Story = { | ||
name: 'With input ▶️', | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement) | ||
const input = canvas.getByRole('textbox') | ||
|
||
await step('Search', async () => { | ||
await fireEvent.change(input, { target: { value: 'Some search query' } }) | ||
expect(getRouter().replace).toHaveBeenCalledWith( | ||
expect.stringContaining('q=Some+search+query'), | ||
) | ||
}) | ||
}, | ||
} | ||
|
||
export const InputCleared: Story = { | ||
name: 'Input cleared ▶️', | ||
play: async (playContext) => { | ||
await WithInput.play!(playContext) | ||
|
||
const { canvasElement, step } = playContext | ||
const canvas = within(canvasElement) | ||
const input = canvas.getByRole('textbox') | ||
|
||
getRouter().replace.mockClear() | ||
|
||
await step('Clear', async () => { | ||
await fireEvent.change(input, { target: { value: '' } }) | ||
expect(getRouter().replace).toHaveBeenCalledWith( | ||
expect.not.stringContaining('q='), | ||
) | ||
}) | ||
}, | ||
} |
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 |
---|---|---|
@@ -1,23 +1,107 @@ | ||
import { useState, useEffect } from 'react' | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import Sidebar from "./sidebar"; | ||
import { createNotes } from '#mocks/notes'; | ||
import Sidebar from './sidebar' | ||
import { createNotes } from '#mocks/notes' | ||
import { expect, fireEvent, userEvent, within, waitFor } from '@storybook/test' | ||
|
||
const meta = { | ||
component: Sidebar, | ||
args: { | ||
notes: createNotes(), | ||
children: null, | ||
}, | ||
} satisfies Meta<typeof Sidebar> | ||
|
||
export default meta; | ||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
export const Default: Story = { | ||
args: { | ||
notes: createNotes(), | ||
children: null | ||
} | ||
} | ||
export const Default: Story = {} | ||
export const Empty: Story = { | ||
args: { | ||
notes: [], | ||
children: null | ||
}, | ||
} | ||
|
||
export const NotesExpanded: Story = { | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement) | ||
const expanders = canvas.getAllByAltText(/expand/i) | ||
|
||
expanders.forEach(async (expander) => { | ||
await userEvent.click(expander) | ||
}) | ||
}, | ||
} | ||
|
||
|
||
//@ts-expect-error -- doesn't know about the Promise.withResolvers function | ||
const changeNoteGate = Promise.withResolvers(); | ||
|
||
export const NoteChangedAnimation: Story = { | ||
render: () => { | ||
const [notes, setNotes] = useState(createNotes()) | ||
useEffect(() => { | ||
setTimeout(() => { | ||
setNotes((prevNotes) => { | ||
return [ | ||
{ | ||
...prevNotes[0], | ||
title: 'New title', | ||
}, | ||
...prevNotes.slice(1), | ||
] | ||
}) | ||
changeNoteGate.resolve(); | ||
}, 1000) | ||
}, []) | ||
return <Sidebar notes={notes} /> | ||
}, | ||
play: async () => { | ||
await changeNoteGate.promise; | ||
} | ||
} | ||
} | ||
|
||
export const ToggleSidebarOnMobile: Story = { | ||
parameters: { | ||
viewport: { | ||
defaultViewport: 'mobile1', | ||
}, | ||
chromatic: { viewports: [320] }, | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement) | ||
const searchInput = canvas.getByRole('menubar') | ||
|
||
await step('Sidebar is initially visible', async () => { | ||
expect(searchInput).toBeVisible() | ||
expect(isElementInView(searchInput)).toBe(true) | ||
}) | ||
|
||
await step('Select note', async () => { | ||
const note = canvas.getAllByRole('button', { | ||
name: /Open note for preview/i, | ||
})[0] | ||
note.click() | ||
}) | ||
|
||
await waitFor(function sidebarIsNotVisible() { | ||
expect(isElementInView(searchInput)).toBe(false) | ||
}) | ||
}, | ||
} | ||
|
||
/** | ||
* assertion to check if an element is in or out of the viewport, | ||
* regardless of being in the DOM or not | ||
*/ | ||
function isElementInView(element: Element) { | ||
var rect = element.getBoundingClientRect() | ||
var html = document.documentElement | ||
|
||
return ( | ||
rect.bottom >= 0 && | ||
rect.top <= (window.innerHeight || html.clientHeight) && | ||
rect.right >= 0 && | ||
rect.left <= (window.innerWidth || html.clientWidth) | ||
) | ||
} |
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
Oops, something went wrong.