Skip to content

Commit a8559ee

Browse files
feat: use directive transition wrappers (#574)
# Motivation Implements the transition directives wrappers provided in #573 for the transition that lead the [CI](https://github.com/dfinity/nns-dapp/actions/runs/13129931873/job/36632946426) to fail in the NNS dapp Svelte v5 branch. # Changes - Instead of using `svelte/transition`, use the wrappers that skips the transitions for testing purposes # Tests I asserted this changes has no impact on the test suite of NNS dapp by integrating a manual package and running the CI successfully in dfinity/nns-dapp#6336. We will have to mock the `ResizeObserver` though but, that's something we need for Svelte v5 testing anyway dfinity/nns-dapp#6337
1 parent 0d2e01a commit a8559ee

7 files changed

+33
-20
lines changed

src/lib/components/Backdrop.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { fade } from "svelte/transition";
2+
import { testSafeFade } from "$lib/directives/transition.directives";
33
import { createEventDispatcher } from "svelte";
44
import { i18n } from "$lib/stores/i18n";
55
import { handleKeyPress } from "$lib/utils/keyboard.utils";
@@ -18,8 +18,8 @@
1818
role="button"
1919
tabindex="-1"
2020
aria-label={$i18n.core.close}
21-
in:fade|global={{ duration: FADE_IN_DURATION }}
22-
out:fade|global={{ duration: FADE_OUT_DURATION }}
21+
in:testSafeFade|global={{ duration: FADE_IN_DURATION }}
22+
out:testSafeFade|global={{ duration: FADE_OUT_DURATION }}
2323
class="backdrop"
2424
class:visible={!invisible}
2525
on:click|stopPropagation={close}

src/lib/components/BusyScreen.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script lang="ts">
2-
import { fade } from "svelte/transition";
2+
import { testSafeFade } from "$lib/directives/transition.directives";
33
import { busy, busyMessage } from "$lib/stores/busy.store";
44
import Spinner from "$lib/components/Spinner.svelte";
55
import { nonNullish } from "@dfinity/utils";
66
</script>
77

88
<!-- Display spinner and lock UI if busyStore is not empty -->
99
{#if $busy}
10-
<div data-tid="busy" transition:fade|global>
10+
<div data-tid="busy" transition:testSafeFade|global>
1111
<div class="content">
1212
{#if nonNullish($busyMessage)}
1313
<p>{$busyMessage}</p>

src/lib/components/Modal.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { fade } from "svelte/transition";
2+
import { testSafeFade } from "$lib/directives/transition.directives";
33
import { createEventDispatcher } from "svelte";
44
import { i18n } from "$lib/stores/i18n";
55
import IconClose from "$lib/icons/IconClose.svelte";
@@ -46,7 +46,7 @@
4646
{#if visible}
4747
<div
4848
class="modal"
49-
transition:fade|global={{ duration: 25 }}
49+
transition:testSafeFade|global={{ duration: 25 }}
5050
on:introend
5151
{role}
5252
data-tid={testId}
@@ -56,8 +56,8 @@
5656
>
5757
<Backdrop {disablePointerEvents} on:nnsClose />
5858
<div
59-
in:fade|global={{ duration: FADE_IN_DURATION }}
60-
out:fade|global={{ duration: FADE_OUT_DURATION }}
59+
in:testSafeFade|global={{ duration: FADE_IN_DURATION }}
60+
out:testSafeFade|global={{ duration: FADE_OUT_DURATION }}
6161
class={`wrapper ${role}`}
6262
>
6363
{#if showHeader}

src/lib/components/Popover.svelte

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<!-- https://github.com/papyrs/papyrs/blob/main/src/lib/components/ui/Popover.svelte -->
22
<script lang="ts">
3-
import { fade, scale } from "svelte/transition";
3+
import {
4+
testSafeFade,
5+
testSafeScale,
6+
} from "$lib/directives/transition.directives";
47
import { quintOut } from "svelte/easing";
58
import { i18n } from "$lib/stores/i18n";
69
import Backdrop from "./Backdrop.svelte";
@@ -30,7 +33,7 @@
3033
<div
3134
role="menu"
3235
aria-orientation="vertical"
33-
transition:fade|global
36+
transition:testSafeFade|global
3437
class="popover"
3538
tabindex="-1"
3639
style="--popover-top: {`${bottom}px`}; --popover-left: {`${left}px`}; --popover-right: {`${
@@ -45,7 +48,11 @@
4548
invisible={invisibleBackdrop}
4649
/>
4750
<div
48-
transition:scale|global={{ delay: 25, duration: 150, easing: quintOut }}
51+
transition:testSafeScale|global={{
52+
delay: 25,
53+
duration: 150,
54+
easing: quintOut,
55+
}}
4956
class="wrapper"
5057
class:with-border={invisibleBackdrop}
5158
class:rtl={direction === "rtl"}

src/lib/components/ThemeToggleButton.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { i18n } from "$lib/stores/i18n";
55
import IconLightMode from "$lib/icons/IconLightMode.svelte";
66
import IconDarkMode from "$lib/icons/IconDarkMode.svelte";
7-
import { fade } from "svelte/transition";
7+
import { testSafeFade } from "$lib/directives/transition.directives";
88
99
const switchTheme = () => {
1010
themeStore.select($themeStore === Theme.LIGHT ? Theme.DARK : Theme.LIGHT);
@@ -21,11 +21,11 @@
2121
aria-label={$i18n.theme.switch_theme}
2222
>
2323
{#if isDarkMode}
24-
<span in:fade|global>
24+
<span in:testSafeFade|global>
2525
<IconLightMode />
2626
</span>
2727
{:else}
28-
<span in:fade|global>
28+
<span in:testSafeFade|global>
2929
<IconDarkMode />
3030
</span>
3131
{/if}

src/lib/components/Toast.svelte

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<script lang="ts">
22
import { toastsStore } from "$lib/stores/toasts.store";
3-
import { fade, fly } from "svelte/transition";
3+
import {
4+
testSafeFade,
5+
testSafeFly,
6+
} from "$lib/directives/transition.directives";
47
import { i18n } from "$lib/stores/i18n";
58
import type {
69
ToastLevel,
@@ -92,8 +95,11 @@
9295
data-tid="toast-component"
9396
role="dialog"
9497
class={`toast ${theme ?? "themed"}`}
95-
in:fly|global={{ y: (position === "top" ? -1 : 1) * 100, duration: 200 }}
96-
out:fade|global={{ delay: 100 }}
98+
in:testSafeFly|global={{
99+
y: (position === "top" ? -1 : 1) * 100,
100+
duration: 200,
101+
}}
102+
out:testSafeFade|global={{ delay: 100 }}
97103
>
98104
<div class="icon {level}" aria-hidden="true">
99105
{#if spinner}

src/lib/components/WizardTransition.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { fly } from "svelte/transition";
2+
import { testSafeFly } from "$lib/directives/transition.directives";
33
44
// Instead of a number an object is used to make svelte notice any updates need rerender
55
export let transition: { diff: number } = { diff: 0 };
@@ -19,7 +19,7 @@
1919
{#key transition}
2020
<div
2121
bind:clientWidth={absolutOffset}
22-
in:fly|global={{ x: slideOffset, duration: ANIMATION_DURATION }}
22+
in:testSafeFly|global={{ x: slideOffset, duration: ANIMATION_DURATION }}
2323
class="transition"
2424
>
2525
<slot />

0 commit comments

Comments
 (0)