Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.4.1 #28

Merged
merged 6 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notivue-monorepo",
"version": "1.4.0",
"version": "1.4.1",
"private": true,
"workspaces": [
"packages/*",
Expand All @@ -14,12 +14,13 @@
"build:demo": "bun run build && bun install && cd demo && bun run build",
"test": "bun run build && bun install && cd tests && bun run test",
"test:gui": "bun run build && concurrently \"cd packages/notivue && bun run watch\" \"bun install && cd tests && bun run test:gui\"",
"prepare": "bunx husky install"
"prepare": "bun x husky install"
},
"devDependencies": {
"concurrently": "^8.2.1",
"lint-staged": "^14.0.1",
"prettier": "^2.8.8"
"prettier": "^2.8.8",
"husky": "^8.0.3"
},
"trustedDependencies": [
"husky"
Expand Down
6 changes: 3 additions & 3 deletions packages/notivue/core/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function useStore() {
* for the fact that each property is a [shallowRef](https://vuejs.org/api/reactivity-advanced.html#shallowref)
* that allows for reactive updates and side effects.
*
* Documentation: https://notivue.netlify.app/api/use-notivue
* Documentation: https://notivuedocs.netlify.app/api/use-notivue
*/
export function useNotivue(): ConfigSlice {
if (isSSR) {
Expand All @@ -36,7 +36,7 @@ export function useNotivue(): ConfigSlice {
*
* Portion of the store matching the actions to create notifications.
*
* Documentation: https://notivue.netlify.app/api/use-push
* Documentation: https://notivuedocs.netlify.app/api/use-push
*/
export function usePush() {
if (isSSR) return createPushSSR()
Expand All @@ -52,7 +52,7 @@ export function usePush() {
* - `entries` - read-only reactive array of all the current displayed notifications
* - `queue` - read-only reactive array of all the notifications waiting to be displayed
*
* Documentation: https://notivue.netlify.app/api/use-notifications
* Documentation: https://notivuedocs.netlify.app/api/use-notifications
*/
export function useNotifications(): NotivueComputedEntries {
if (isSSR) {
Expand Down
1 change: 1 addition & 0 deletions packages/notivue/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ export function mergeNotificationOptions<T extends Obj = Obj>(
...(mergedConfigOptions[optionsFromPush.type] ?? mergedConfigOptions.success),
...mergedConfigOptions.global,
...optionsFromPush,
...(optionsFromPush.type === 'promise' ? { duration: Infinity } : {}), // Force duration infinity
}
}
2 changes: 1 addition & 1 deletion packages/notivue/nuxt/module.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "notivue/nuxt",
"configKey": "notivue",
"version": "1.4.0"
"version": "1.4.1"
}
2 changes: 1 addition & 1 deletion packages/notivue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notivue",
"version": "1.4.0",
"version": "1.4.1",
"private": false,
"description": "Fully-featured toast notification system for Vue and Nuxt",
"keywords": [
Expand Down
24 changes: 5 additions & 19 deletions tests/Notivue/components/Notivue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type Push,
} from 'notivue'

import { GENERIC_UPDATE_DELAY, RESOLVE_REJECT_DELAY } from '@/support/utils'
import { RESOLVE_REJECT_DELAY } from '@/support/utils'

export type CyNotivueProps = {
class?: string
Expand All @@ -35,22 +35,9 @@ watchEffect(() => {
if (enqueue?.value) config.enqueue.value = enqueue.value
})

async function randomPromise() {
const promise = push.promise(cyProps.options ?? {})

try {
await new Promise((resolve, reject) =>
setTimeout(Math.random() > 0.5 ? resolve : reject, GENERIC_UPDATE_DELAY)
)
promise.resolve(cyProps.options ?? {})
} catch (error) {
promise.reject(cyProps.options ?? {})
}
}

function pushAndClear() {
const notification = push.success(cyProps.options ?? {})
setTimeout(() => notification.clear(), GENERIC_UPDATE_DELAY)
setTimeout(() => notification.clear(), RESOLVE_REJECT_DELAY)
}

function pushAriaLiveOnly() {
Expand Down Expand Up @@ -95,22 +82,22 @@ function pushAndRenderClear() {

function pushAndDestroy() {
const notification = push.success(cyProps.options ?? {})
setTimeout(() => notification.destroy(), GENERIC_UPDATE_DELAY)
setTimeout(() => notification.destroy(), RESOLVE_REJECT_DELAY)
}

function pushSkipQueue() {
push.success(cyProps.options ?? { skipQueue: true })
}

async function pushPromiseAndResolve() {
const promise = push.promise({ ...cyProps.options, duration: Infinity } ?? {})
const promise = push.promise(cyProps.options ?? {})
await new Promise((resolve) => setTimeout(resolve, RESOLVE_REJECT_DELAY))

promise.resolve(cyProps.newOptions ?? cyProps.options ?? {})
}

async function pushPromiseAndReject() {
const promise = push.promise({ ...cyProps.options, duration: Infinity } ?? {})
const promise = push.promise(cyProps.options ?? {})
await new Promise((resolve) => setTimeout(resolve, RESOLVE_REJECT_DELAY))

promise.reject(cyProps.newOptions ?? cyProps.options ?? {})
Expand Down Expand Up @@ -143,7 +130,6 @@ async function pushPromiseAndReject() {
<button class="PushAndRenderClear" @click="pushAndRenderClear">Push and Render Clear</button>
<button v-if="toBeCleared" class="RenderedClear" @click="toBeCleared.clear">Clear</button>

<button class="RandomPromise" @click="randomPromise">Push and Resolve/Reject Promise</button>
<button class="PushPromiseAndResolve" @click="pushPromiseAndResolve">
Push Promise and Resolve
</button>
Expand Down
18 changes: 8 additions & 10 deletions tests/Notivue/config-animations.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Notivue from './components/Notivue.vue'

import type { VueWrapper } from '@vue/test-utils'

// In cypress/support/styles.css
Expand All @@ -19,14 +17,14 @@ describe('Animations', () => {
})

it('Custom animations are merged properly with defaults', () => {
const _customAnimations = { ...customAnims } as Partial<typeof customAnims>
delete _customAnimations.enter

cy.mountNotivue({ config: { animations: _customAnimations } }).checkAnimations(
'.Notivue__enter',
'.fade-out',
'.fade-all'
)
cy.mountNotivue({
config: {
animations: {
leave: customAnims.leave,
clearAll: customAnims.clearAll,
},
},
}).checkAnimations('.Notivue__enter', '.fade-out', '.fade-all')
})

it('Should update animations config dynamically', () => {
Expand Down
14 changes: 13 additions & 1 deletion tests/Notivue/push-methods.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DEFAULT_DURATION } from '@/core/constants'
import { DEFAULT_ENTER_LEAVE_ANIM_DURATION, RESOLVE_REJECT_DELAY } from '@/support/utils'

describe('Push', () => {
it('Can push any type of notification', () => {
Expand All @@ -25,9 +26,17 @@ describe('Push', () => {
it('Updates and dismisses promises', () => {
cy.mountNotivue()

.get('.RandomPromise')
.get('.PushPromiseAndResolve')
.click()
.wait(RESOLVE_REJECT_DELAY)
.wait(DEFAULT_DURATION)

.getNotifications()
.should('have.length', 0)

.get('.PushPromiseAndReject')
.click()
.wait(RESOLVE_REJECT_DELAY)
.wait(DEFAULT_DURATION)

.getNotifications()
Expand Down Expand Up @@ -61,6 +70,8 @@ describe('Push', () => {

.get('.PushAndClear')
.click()
.wait(RESOLVE_REJECT_DELAY)
.wait(DEFAULT_ENTER_LEAVE_ANIM_DURATION)

.getNotifications()
.should('have.length', 0)
Expand All @@ -71,6 +82,7 @@ describe('Push', () => {

.get('.PushAndDestroy')
.click()
.wait(RESOLVE_REJECT_DELAY)

.getNotifications()
.should('have.length', 0)
Expand Down
8 changes: 4 additions & 4 deletions tests/Notivue/slot-custom-push-options.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ describe('Push notification options have higher priority over config', () => {
.checkSlotAgainst(options)
})

it('Promise', () => {
it('Promise - Besides duration', () => {
cy.mountNotivue(componentConf)

.get('.Promise')
.click()
.checkSlotAgainst(options)
.checkSlotAgainst({ ...options, duration: null })
})

it('Promise - Resolve', () => {
Expand Down Expand Up @@ -141,12 +141,12 @@ describe('Push notification options are merged properly with config', () => {
.checkSlotAgainst(expectedOptions)
})

it('Promise', () => {
it('Promise - Besides duration', () => {
cy.mountNotivue(componentConf)

.get('.Promise')
.click()
.checkSlotAgainst(expectedOptions)
.checkSlotAgainst({ ...expectedOptions, duration: null })
})
})

Expand Down
9 changes: 6 additions & 3 deletions tests/Notivue/slot-default-options.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { DEFAULT_NOTIFICATION_OPTIONS as DEFAULT_OPTIONS } from '@/core/constant
import { RESOLVE_REJECT_DELAY } from '@/support/utils'

describe('Default options match the slot content', () => {
const { success, error, warning, info, promise } = DEFAULT_OPTIONS
const { success, error, warning, info, promise } = DEFAULT_OPTIONS as Record<
keyof typeof DEFAULT_OPTIONS,
Record<string, unknown>
>

describe('First-level notifications', () => {
it('Success', () => {
Expand Down Expand Up @@ -47,8 +50,8 @@ describe('Default options match the slot content', () => {
})

describe('Promise - Resolve / Reject', () => {
const promiseResolve = DEFAULT_OPTIONS['promise-resolve']
const promiseReject = DEFAULT_OPTIONS['promise-reject']
const promiseResolve = DEFAULT_OPTIONS['promise-resolve'] as Record<string, unknown>
const promiseReject = DEFAULT_OPTIONS['promise-reject'] as Record<string, unknown>

it('Promise - Resolve', () => {
cy.mountNotivue()
Expand Down
8 changes: 4 additions & 4 deletions tests/Notivue/slot-global-options.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ describe('Global options have higher priority over defaults', () => {
.checkSlotAgainst(globalOptions)
})

it('Promise', () => {
it('Promise - Should not override duration', () => {
cy.mountNotivue(customConfig)

.get('.Promise')
.click()
.checkSlotAgainst(globalOptions)
.checkSlotAgainst({ ...globalOptions, duration: null })
})
})

Expand Down Expand Up @@ -128,12 +128,12 @@ describe('Push options have higher priority over globals', () => {
.checkSlotAgainst(options)
})

it('Promise', () => {
it('Promise - Besides duration', () => {
cy.mountNotivue(componentConf)

.get('.Promise')
.click()
.checkSlotAgainst(options)
.checkSlotAgainst({ ...options, duration: null })
})
})

Expand Down
1 change: 0 additions & 1 deletion tests/cypress/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const RESOLVE_REJECT_DELAY = 2000
*
* Needed just to see the change in the UI
*/
export const GENERIC_UPDATE_DELAY = 1000

export const SWIPE_NOTIFICATION_WIDTH = 300

Expand Down