-
-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
234 additions
and
5 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/varlet-ui/src/snackbar/__tests__/__snapshots__/component.spec.js.snap
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,67 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`test snackbar example 1`] = ` | ||
"<div class=\\"snackbar-demo\\"> | ||
<div class=\\"app-type\\">组件调用</div><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">基本使用</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">垂直排列</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">底部显示</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">显示时长</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">禁止穿透点击</div> | ||
</button> | ||
</div> | ||
<div class=\\"snackbar-demo\\"> | ||
<div class=\\"app-type\\">函数调用</div><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">基本使用</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">显示时长</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">底部显示</div> | ||
</button> | ||
</div> | ||
<div class=\\"snackbar-demo\\"> | ||
<div class=\\"app-type\\">Snackbar 类型</div> | ||
<div class=\\"snackbar-demo__type-block\\"><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">成功</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">警告</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">消息</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">错误</div> | ||
</button><button class=\\"var-button var--box var-button--normal var--flex var-button--primary var-elevation--1\\" style=\\"width: 100%;\\"> | ||
<!--v-if--> | ||
<div class=\\"var-button__content\\">加载</div> | ||
</button></div> | ||
</div> | ||
<div class=\\"snackbar-demo\\"> | ||
<!--teleport start--> | ||
<!--teleport end--> | ||
<!--teleport start--> | ||
<!--teleport end--> | ||
<!--teleport start--> | ||
<!--teleport end--> | ||
<!--teleport start--> | ||
<!--teleport end--> | ||
<!--teleport start--> | ||
<!--teleport end--> | ||
</div>" | ||
`; | ||
|
||
exports[`test snackbar style 1`] = `"<transition-stub><div class=\\"var-snackbar var-snackbar-transition\\" style=\\"pointer-events: auto; z-index: 2001;\\"><div class=\\"var-snackbar__wrapper var-snackbar__wrapper-center var-elevation--4 var-snackbar__vertical var-snackbar__wrapper-loading\\" style=\\"z-index: 2001;\\"><div class=\\"var-snackbar__content test-snackbar\\">test snackbar</div><div class=\\"var-snackbar__action\\"><!--v-if--><div class=\\"var--box var-loading\\"><!--v-if--><div class=\\"var-loading__wave var-loading__wave-large\\"><div style=\\"background-color: currentColor;\\" class=\\"var-loading__wave-item var-loading__wave-item-large\\"></div><div style=\\"background-color: currentColor;\\" class=\\"var-loading__wave-item var-loading__wave-item-large\\"></div><div style=\\"background-color: currentColor;\\" class=\\"var-loading__wave-item var-loading__wave-item-large\\"></div><div style=\\"background-color: currentColor;\\" class=\\"var-loading__wave-item var-loading__wave-item-large\\"></div><div style=\\"background-color: currentColor;\\" class=\\"var-loading__wave-item var-loading__wave-item-large\\"></div></div><!--v-if--><!--v-if--><!--v-if--></div></div></div></div></transition-stub>"`; |
52 changes: 52 additions & 0 deletions
52
packages/varlet-ui/src/snackbar/__tests__/component.spec.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,52 @@ | ||
import Snackbar from '..' | ||
import VarSnackbar from '../Snackbar' | ||
import example from '../example' | ||
import { mount } from '@vue/test-utils' | ||
import { createApp } from 'vue' | ||
import { delay } from '../../utils/jest' | ||
|
||
test('test snackbar example', () => { | ||
const wrapper = mount(example) | ||
expect(wrapper.html()).toMatchSnapshot() | ||
wrapper.unmount() | ||
}) | ||
|
||
test('test snackbar component plugin', () => { | ||
const app = createApp({}).use(Snackbar.Component) | ||
expect(app.component(Snackbar.Component.name)).toBeTruthy() | ||
}) | ||
|
||
test('test snackbar style', async () => { | ||
const template = ` | ||
<var-snackbar | ||
v-model:show="show" | ||
type="loading" | ||
position="center" | ||
content-class="test-snackbar" | ||
vertical | ||
:duration="500" | ||
loading-type="wave" | ||
loading-size="large" | ||
content="test snackbar" | ||
forbid-click | ||
lock-scroll | ||
/> | ||
` | ||
mount({ | ||
components: { | ||
[VarSnackbar.name]: VarSnackbar | ||
}, | ||
data() { | ||
return { | ||
show: true | ||
} | ||
}, | ||
template | ||
}) | ||
|
||
await delay(200) | ||
expect(document.body.innerHTML).toMatchSnapshot() | ||
|
||
await delay(500) | ||
expect(document.querySelector('.var-snackbar').style.display).toBe('none') | ||
}) |
112 changes: 112 additions & 0 deletions
112
packages/varlet-ui/src/snackbar/__tests__/index.spec.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,112 @@ | ||
import Snackbar from '../index' | ||
import VarSnackbar from '../Snackbar' | ||
import { createApp } from 'vue' | ||
import { delay } from '../../utils/jest' | ||
|
||
test('test snackbar plugin', () => { | ||
const app = createApp({}).use(Snackbar) | ||
expect(app.component(VarSnackbar.name)).toBeTruthy() | ||
}) | ||
|
||
test('test snackbar functional', async () => { | ||
expect(document.body.querySelector('.var-snackbar')).toBeFalsy() | ||
|
||
const { clear } = Snackbar('test snackbar') | ||
|
||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar')).toBeTruthy() | ||
|
||
clear() | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar')).toBeFalsy() | ||
|
||
Snackbar.clear() | ||
}) | ||
|
||
test('test snackbar type', async () => { | ||
Snackbar.success('test snackbar') | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-success')).toBeTruthy() | ||
|
||
Snackbar.warning('test snackbar') | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-warning')).toBeTruthy() | ||
|
||
Snackbar.error('test snackbar') | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-error')).toBeTruthy() | ||
|
||
Snackbar.info({ | ||
content: 'test snackbar', | ||
forbidClick: true | ||
}) | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-info')).toBeTruthy() | ||
|
||
Snackbar.loading('test snackbar') | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-loading')).toBeTruthy() | ||
|
||
Snackbar.clear() | ||
}) | ||
|
||
test('test snackbar event', async () => { | ||
const open = jest.fn() | ||
const opened = jest.fn() | ||
const close = jest.fn() | ||
const closed = jest.fn() | ||
|
||
const { clear } = Snackbar({ | ||
content: 'test snackbar', | ||
duration: 500, | ||
onOpen: open, | ||
onOpened: opened, | ||
onClose: close, | ||
onClosed: closed | ||
}) | ||
|
||
await delay(200) | ||
|
||
clear() | ||
|
||
await delay(200) | ||
|
||
expect(open).toHaveBeenCalledTimes(1) | ||
expect(opened).toHaveBeenCalled() | ||
expect(close).toHaveBeenCalledTimes(1) | ||
expect(closed).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('test snackbar allowMultiple and clear', async () => { | ||
Snackbar.success('test snackbar') | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-success')).toBeTruthy() | ||
|
||
Snackbar.warning('test snackbar') | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-success')).toBeFalsy() | ||
|
||
Snackbar.allowMultiple(true) | ||
await delay(0) | ||
expect(Snackbar.isAllowMultiple).toBe(true) | ||
|
||
const { clear } = Snackbar.info('test snackbar') | ||
await delay(200) | ||
clear() | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-info')).toBeFalsy() | ||
|
||
Snackbar.success('test snackbar') | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-success')).toBeTruthy() | ||
|
||
Snackbar.warning('test snackbar') | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-success')).toBeTruthy() | ||
expect(document.body.querySelector('.var-snackbar__wrapper-warning')).toBeTruthy() | ||
|
||
Snackbar.clear() | ||
await delay(200) | ||
expect(document.body.querySelector('.var-snackbar__wrapper-success')).toBeFalsy() | ||
expect(document.body.querySelector('.var-snackbar__wrapper-warning')).toBeFalsy() | ||
}) |
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