Skip to content

Commit a8bb380

Browse files
Merge pull request xiaoluoboding#91 from CMarzin/add-playwright-test
Add playwright test from Sonner package and fix dismiss function
2 parents 27f1159 + 4b73dd2 commit a8bb380

29 files changed

+3349
-339
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ https://user-images.githubusercontent.com/6118824/228208185-be5aefd4-7fa8-4f95-a
3232
- [Introduction](#introduction)
3333
- [Table of Contents](#table-of-contents)
3434
- [Installation](#installation)
35+
- [Test](#test)
3536
- [Usage](#usage)
3637
- [For Vue 3](#for-vue-3)
3738
- [For Nuxt 3](#for-nuxt-3)
@@ -74,6 +75,33 @@ or
7475
yarn add vue-sonner
7576
```
7677

78+
## Test
79+
80+
To run the test you need two separate CLI window :
81+
82+
### Launching the test
83+
84+
To launch the test, you need to go in the test directory
85+
86+
```bash
87+
cd ./test
88+
```
89+
90+
and launch the following command
91+
92+
```bash
93+
cd ./test
94+
pnpm test:e2e --ui
95+
```
96+
97+
### Build and watch for change in order to fix the test
98+
99+
This command will build the vue-sonner library in lib mode, and add a watch so every time you modify the code of the library, you will have a new bundle and can run the test again.
100+
101+
```bash
102+
pnpm build:dev
103+
```
104+
77105
## Usage
78106

79107
### For Vue 3

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "xiaoluoboding <xiaoluoboding@gmail.com>",
66
"scripts": {
77
"dev": "vite",
8+
"build:dev": "vite build --mode lib --watch",
89
"build:docs": "vite build --mode docs",
910
"build:lib": "vite build --mode lib && pnpm run build:types",
1011
"build:types": "vue-tsc -p tsconfig.build.json && api-extractor run",

packages/Toast.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
<script lang="ts" setup>
168168
import './styles.css'
169169
170-
import { computed, onMounted, onUnmounted, ref, watchEffect } from 'vue'
170+
import { computed, onMounted, onUnmounted, ref, watch, watchEffect } from 'vue'
171171
import { type HeightT, type ToastProps, type ToastT, isAction } from './types'
172172
import { useIsDocumentHidden } from './hooks'
173173
@@ -407,11 +407,14 @@ watchEffect((onInvalidate) => {
407407
})
408408
})
409409
410-
// watchEffect(() => {
411-
// if (props.toast.delete) {
412-
// deleteToast()
413-
// }
414-
// })
410+
watch(
411+
() => props.toast.delete,
412+
(value) => {
413+
if (value) {
414+
deleteToast()
415+
}
416+
}
417+
)
415418
416419
onMounted(() => {
417420
if (toastRef.value) {

packages/Toaster.vue

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,13 @@ watch(
343343
}
344344
)
345345
346-
watch(
347-
() => listRef.value,
348-
() => {
349-
if (listRef.value) {
350-
return () => {
351-
if (lastFocusedElementRef.value) {
352-
lastFocusedElementRef.value.focus({ preventScroll: true })
353-
lastFocusedElementRef.value = null
354-
isFocusWithinRef.value = false
355-
}
356-
}
357-
}
346+
watchEffect(() => {
347+
if (listRef.value && lastFocusedElementRef.value) {
348+
lastFocusedElementRef.value.focus({ preventScroll: true })
349+
lastFocusedElementRef.value = null
350+
isFocusWithinRef.value = false
358351
}
359-
)
352+
})
360353
361354
watchEffect(() => {
362355
// Ensure expanded is always false when no toasts are present / only one left

playwright-report/index.html

Lines changed: 68 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)