From b99fa63bf6b22d4a47a5812e4cd65625f8564948 Mon Sep 17 00:00:00 2001 From: Ramzo Date: Sun, 6 Aug 2023 03:33:18 +0400 Subject: [PATCH 1/3] direction component unit test --- .../direction/src/direction.test.ts | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 packages/components/direction/src/direction.test.ts diff --git a/packages/components/direction/src/direction.test.ts b/packages/components/direction/src/direction.test.ts new file mode 100644 index 000000000..87d496a65 --- /dev/null +++ b/packages/components/direction/src/direction.test.ts @@ -0,0 +1,61 @@ +import { describe, expect, it } from 'vitest' +import { mount } from '@vue/test-utils' +import { type Component } from 'vue' +import { DirectionContextSymbol, DirectionProvider, useDirection } from './Direction.ts' + +describe('direction', () => { + function propsTest(dir: string) { + it(`props ${dir}`, () => { + const wrapper = mount(DirectionProvider, { + props: { + dir, + }, + }) + expect(wrapper.props().dir).toBe(dir) + }) + } + + propsTest('ltr') + propsTest('rtl') + + it('slot', () => { + const wrapper = mount(DirectionProvider, { + slots: { + default: 'test', + }, + }) + expect(wrapper.html()).toContain('test') + }) + it('provide, inject and slot', () => { + const ChildComponent = { + setup() { + const dir = useDirection() + return { + dir, + } + }, + template: '
{{ dir }}
', + } as Component + + const childWrapper = mount(ChildComponent, { + global: { + provide: { + [DirectionContextSymbol]: 'ltr', + }, + }, + }) + + const main = { + components: { DirectionProvider, ChildComponent }, + template: ` + + + + `, + } + + const wrapper = mount(main, {}) + expect(wrapper.html()).toContain('ltr') + expect(childWrapper.html()).toContain('ltr') + }) +}) From de9998bce3ffef9b16a3034fdad98894b5e999d7 Mon Sep 17 00:00:00 2001 From: Ramzo <115036895+ramzzo@users.noreply.github.com> Date: Sun, 6 Aug 2023 03:38:56 +0400 Subject: [PATCH 2/3] direction package test completed --- packages/components/direction/src/direction.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/direction/src/direction.test.ts b/packages/components/direction/src/direction.test.ts index 87d496a65..827becfbc 100644 --- a/packages/components/direction/src/direction.test.ts +++ b/packages/components/direction/src/direction.test.ts @@ -52,7 +52,7 @@ describe('direction', () => { `, - } + } as Component const wrapper = mount(main, {}) expect(wrapper.html()).toContain('ltr') From 920ac85225a114040787b9f429d36744b460c33c Mon Sep 17 00:00:00 2001 From: Ramzo <115036895+ramzzo@users.noreply.github.com> Date: Mon, 7 Aug 2023 01:24:33 +0400 Subject: [PATCH 3/3] typecheck fixed --- packages/components/direction/src/direction.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/components/direction/src/direction.test.ts b/packages/components/direction/src/direction.test.ts index 827becfbc..8f949f7ec 100644 --- a/packages/components/direction/src/direction.test.ts +++ b/packages/components/direction/src/direction.test.ts @@ -1,10 +1,12 @@ import { describe, expect, it } from 'vitest' import { mount } from '@vue/test-utils' import { type Component } from 'vue' -import { DirectionContextSymbol, DirectionProvider, useDirection } from './Direction.ts' +import { DirectionProvider, useDirection } from './Direction' + +const DirectionContextSymbol = Symbol('DirectionContext') describe('direction', () => { - function propsTest(dir: string) { + function propsTest(dir: any) { it(`props ${dir}`, () => { const wrapper = mount(DirectionProvider, { props: {