From 653047406f4f9fe205710a9412e6971664e0f45f Mon Sep 17 00:00:00 2001
From: XieZongChen <46394163+amadeus711@users.noreply.github.com>
Date: Tue, 17 Aug 2021 21:01:36 -0500
Subject: [PATCH] test(NDrawer): add test for placement (#902)
---
src/drawer/tests/Drawer.spec.tsx | 120 ++++++++++++++++++++++---------
1 file changed, 88 insertions(+), 32 deletions(-)
diff --git a/src/drawer/tests/Drawer.spec.tsx b/src/drawer/tests/Drawer.spec.tsx
index 69f4dbdb6..9aa7a8f0d 100644
--- a/src/drawer/tests/Drawer.spec.tsx
+++ b/src/drawer/tests/Drawer.spec.tsx
@@ -1,7 +1,12 @@
import { mount } from '@vue/test-utils'
import { defineComponent, h, nextTick, ref } from 'vue'
import { NButton } from '../../button'
-import { NDrawer, NDrawerContent } from '../index'
+import {
+ DrawerContentProps,
+ DrawerProps,
+ NDrawer,
+ NDrawerContent
+} from '../index'
// It seems due to special handling of transition in naive-ui, the drawer's DOM
// won't disappear even if its `show` prop is false. No time to find out the
@@ -14,42 +19,59 @@ function expectDrawerExists (): void {
).toEqual('none')
}
+// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
+function mountDrawer ({
+ drawerProps,
+ drawerContentProps
+}: {
+ drawerProps?: DrawerProps
+ drawerContentProps?: DrawerContentProps
+}) {
+ return mount(
+ defineComponent({
+ setup () {
+ return {
+ show: ref(false)
+ }
+ },
+ render () {
+ return [
+ {
+ this.show = true
+ }}
+ >
+ {{ default: () => 'Show' }}
+ ,
+ {
+ this.show = show
+ }}
+ {...drawerProps}
+ >
+ {{
+ default: () => (
+
+ )
+ }}
+
+ ]
+ }
+ }),
+ {
+ attachTo: document.body
+ }
+ )
+}
+
describe('n-drawer', () => {
it('should work with import on demand', () => {
mount(NDrawer)
})
+
it('closable', async () => {
- const wrapper = mount(
- defineComponent({
- setup () {
- return {
- show: ref(false)
- }
- },
- render () {
- return [
- {
- this.show = true
- }}
- >
- {{ default: () => 'Show' }}
- ,
- {
- this.show = show
- }}
- >
- {{ default: () => }}
-
- ]
- }
- }),
- {
- attachTo: document.body
- }
- )
+ const wrapper = mountDrawer({ drawerContentProps: { closable: true } })
expect(document.querySelector('.n-drawer')).toEqual(null)
await wrapper.find('button').trigger('click')
expect(document.querySelector('.n-drawer')).not.toEqual(null)
@@ -60,4 +82,38 @@ describe('n-drawer', () => {
expectDrawerExists()
wrapper.unmount()
})
+
+ it('should work with `placement` prop', async () => {
+ let wrapper = mountDrawer({ drawerProps: { placement: 'top' } })
+ await wrapper.find('button').trigger('click')
+ expect(document.querySelector('.n-drawer')?.className).toContain(
+ 'n-drawer--top-placement'
+ )
+ expectDrawerExists()
+ wrapper.unmount()
+
+ wrapper = mountDrawer({ drawerProps: { placement: 'right' } })
+ await wrapper.find('button').trigger('click')
+ expect(document.querySelector('.n-drawer')?.className).toContain(
+ 'n-drawer--right-placement'
+ )
+ expectDrawerExists()
+ wrapper.unmount()
+
+ wrapper = mountDrawer({ drawerProps: { placement: 'bottom' } })
+ await wrapper.find('button').trigger('click')
+ expect(document.querySelector('.n-drawer')?.className).toContain(
+ 'n-drawer--bottom-placement'
+ )
+ expectDrawerExists()
+ wrapper.unmount()
+
+ wrapper = mountDrawer({ drawerProps: { placement: 'left' } })
+ await wrapper.find('button').trigger('click')
+ expect(document.querySelector('.n-drawer')?.className).toContain(
+ 'n-drawer--left-placement'
+ )
+ expectDrawerExists()
+ wrapper.unmount()
+ })
})