-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Svelte: Support v5 prereleases
- Loading branch information
Showing
26 changed files
with
583 additions
and
73 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
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
38 changes: 38 additions & 0 deletions
38
code/frameworks/sveltekit/template/stories_svelte-kit-prerelease-ts/ButtonTypeScript.svelte
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,38 @@ | ||
<script lang="ts"> | ||
/** | ||
* @component Button TypeScript | ||
* @wrapper | ||
*/ | ||
import { global as globalThis } from '@storybook/global'; | ||
// @ts-ignore | ||
const Button = globalThis.Components?.Button; | ||
/** | ||
* Rounds the button | ||
*/ | ||
export let primary: boolean = false; | ||
/** | ||
* Displays the count | ||
*/ | ||
export let count: number = 0; | ||
/** | ||
* Button text | ||
* @slot | ||
*/ | ||
export let text: string = 'You clicked'; | ||
function handleClick(_event: MouseEvent) { | ||
count += 1; | ||
} | ||
</script> | ||
|
||
<h1>Button TypeScript</h1> | ||
|
||
<Button {primary} on:click on:click={handleClick} label="{text}: {count}" /> | ||
|
||
<p>A little text to show this is a view.</p> | ||
<p>If we need to test components in a Svelte environment, for instance to test slot behaviour,</p> | ||
<p>then wrapping the component up in a view</p> | ||
<p>made just for the story is the simplest way to achieve this.</p> |
7 changes: 7 additions & 0 deletions
7
code/frameworks/sveltekit/template/stories_svelte-kit-prerelease-ts/Forms.svelte
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,7 @@ | ||
<script> | ||
import { enhance } from '$app/forms'; | ||
</script> | ||
|
||
<form use:enhance> | ||
<button>enhance</button> | ||
</form> |
8 changes: 8 additions & 0 deletions
8
code/frameworks/sveltekit/template/stories_svelte-kit-prerelease-ts/Hrefs.svelte
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,8 @@ | ||
<ul> | ||
<li><a href="/basic-href">Link to <code>/basic-href</code></a></li> | ||
<li> | ||
<a href="/deep/nested/link?with=true&multiple-params=200#and-an-id" | ||
>Link to <code>/deep/nested/link?with=true&multiple-params=200#and-an-id</code></a | ||
> | ||
</li> | ||
</ul> |
25 changes: 25 additions & 0 deletions
25
code/frameworks/sveltekit/template/stories_svelte-kit-prerelease-ts/Navigation.svelte
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,25 @@ | ||
<script> | ||
import { goto, invalidate, invalidateAll, afterNavigate } from '$app/navigation'; | ||
export let afterNavigateFn; | ||
afterNavigate(afterNavigateFn); | ||
</script> | ||
|
||
<button | ||
on:click={() => { | ||
goto('/storybook-goto'); | ||
}}>goto</button | ||
> | ||
|
||
<button | ||
on:click={() => { | ||
invalidate('/storybook-invalidate'); | ||
}}>invalidate</button | ||
> | ||
|
||
<button | ||
on:click={() => { | ||
invalidateAll(); | ||
}}>invalidateAll</button | ||
> |
17 changes: 17 additions & 0 deletions
17
code/frameworks/sveltekit/template/stories_svelte-kit-prerelease-ts/Stores.svelte
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 @@ | ||
<script> | ||
import { page, navigating, updated, getStores } from '$app/stores'; | ||
let { navigating: navigatingStore, page: pageStore, updated: updatedStore } = getStores(); | ||
updated.check(); | ||
</script> | ||
|
||
<p>Directly importing</p> | ||
<pre>{JSON.stringify($page, null, 2)}</pre> | ||
<pre>{JSON.stringify($navigating, null, 2)}</pre> | ||
<pre>{JSON.stringify($updated, null, 2)}</pre> | ||
|
||
<p>With getStores</p> | ||
<pre>{JSON.stringify($pageStore, null, 2)}</pre> | ||
<pre>{JSON.stringify($navigatingStore, null, 2)}</pre> | ||
<pre>{JSON.stringify($updatedStore, null, 2)}</pre> |
26 changes: 26 additions & 0 deletions
26
code/frameworks/sveltekit/template/stories_svelte-kit-prerelease-ts/forms.stories.js
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,26 @@ | ||
import { expect, fn, within } from '@storybook/test'; | ||
import Forms from './Forms.svelte'; | ||
|
||
export default { | ||
title: 'stories/sveltekit/modules/forms', | ||
component: Forms, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
const enhance = fn(); | ||
|
||
export const Enhance = { | ||
async play({ canvasElement }) { | ||
const canvas = within(canvasElement); | ||
const button = canvas.getByText('enhance'); | ||
button.click(); | ||
expect(enhance).toHaveBeenCalled(); | ||
}, | ||
parameters: { | ||
sveltekit_experimental: { | ||
forms: { | ||
enhance, | ||
}, | ||
}, | ||
}, | ||
}; |
53 changes: 53 additions & 0 deletions
53
code/frameworks/sveltekit/template/stories_svelte-kit-prerelease-ts/hrefs.stories.js
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,53 @@ | ||
import { expect, fn, within } from '@storybook/test'; | ||
import Hrefs from './Hrefs.svelte'; | ||
|
||
export default { | ||
title: 'stories/sveltekit/modules/hrefs', | ||
component: Hrefs, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export const DefaultActions = { | ||
async play({ canvasElement }) { | ||
const canvas = within(canvasElement); | ||
// eslint-disable-next-line no-undef | ||
const initialUrl = window.location.toString(); | ||
|
||
const basicHref = canvas.getByText('/basic-href'); | ||
basicHref.click(); | ||
|
||
const complexHref = canvas.getByText( | ||
'/deep/nested/link?with=true&multiple-params=200#and-an-id' | ||
); | ||
complexHref.click(); | ||
|
||
// eslint-disable-next-line no-undef | ||
const finalUrl = window.location.toString(); | ||
expect(finalUrl).toBe(initialUrl); | ||
}, | ||
}; | ||
|
||
const basicStringMatch = fn(); | ||
const noMatch = fn(); | ||
const exactStringMatch = fn(); | ||
const regexMatch = fn(); | ||
|
||
export const Callbacks = { | ||
parameters: { | ||
sveltekit_experimental: { | ||
hrefs: { | ||
'/basic-href': basicStringMatch, | ||
'/basic': noMatch, | ||
'/deep/nested/link?with=true&multiple-params=200#and-an-id': exactStringMatch, | ||
'nested/link\\?with': { callback: regexMatch, asRegex: true }, | ||
}, | ||
}, | ||
}, | ||
play: async (ctx) => { | ||
await DefaultActions.play(ctx); | ||
expect(basicStringMatch).toHaveBeenCalledTimes(1); | ||
expect(noMatch).not.toHaveBeenCalled(); | ||
expect(exactStringMatch).toHaveBeenCalledTimes(1); | ||
expect(regexMatch).toHaveBeenCalledTimes(1); | ||
}, | ||
}; |
84 changes: 84 additions & 0 deletions
84
code/frameworks/sveltekit/template/stories_svelte-kit-prerelease-ts/navigation.stories.js
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,84 @@ | ||
import { expect, fn, within } from '@storybook/test'; | ||
import Navigation from './Navigation.svelte'; | ||
|
||
export default { | ||
title: 'stories/sveltekit/modules/navigation', | ||
component: Navigation, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
const goto = fn(); | ||
|
||
export const Goto = { | ||
async play({ canvasElement }) { | ||
const canvas = within(canvasElement); | ||
const button = canvas.getByText('goto'); | ||
button.click(); | ||
expect(goto).toHaveBeenCalledWith('/storybook-goto'); | ||
}, | ||
parameters: { | ||
sveltekit_experimental: { | ||
navigation: { | ||
goto, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const DefaultActions = {}; | ||
|
||
const invalidate = fn(); | ||
|
||
export const Invalidate = { | ||
async play({ canvasElement }) { | ||
const canvas = within(canvasElement); | ||
const button = canvas.getByText('invalidate', { exact: true }); | ||
button.click(); | ||
expect(invalidate).toHaveBeenCalledWith('/storybook-invalidate'); | ||
}, | ||
parameters: { | ||
sveltekit_experimental: { | ||
navigation: { | ||
invalidate, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const invalidateAll = fn(); | ||
|
||
export const InvalidateAll = { | ||
async play({ canvasElement }) { | ||
const canvas = within(canvasElement); | ||
const button = canvas.getByText('invalidateAll'); | ||
button.click(); | ||
expect(invalidateAll).toHaveBeenCalledWith(); | ||
}, | ||
parameters: { | ||
sveltekit_experimental: { | ||
navigation: { | ||
invalidateAll, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const afterNavigateFn = fn(); | ||
|
||
export const AfterNavigate = { | ||
async play() { | ||
expect(afterNavigateFn).toHaveBeenCalledWith({ test: 'passed' }); | ||
}, | ||
args: { | ||
afterNavigateFn, | ||
}, | ||
parameters: { | ||
sveltekit_experimental: { | ||
navigation: { | ||
afterNavigate: { | ||
test: 'passed', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.