diff --git a/packages/utils/__tests__/vue/global-node.test.ts b/packages/utils/__tests__/vue/global-node.test.ts index 7649c8e3b0..e023142bf2 100644 --- a/packages/utils/__tests__/vue/global-node.test.ts +++ b/packages/utils/__tests__/vue/global-node.test.ts @@ -41,4 +41,13 @@ describe('global-nodes', () => { expect(el.parentElement).toBe(target) }) + + it('should create node with id', () => { + const myId = 'my-id' + const el = createGlobalNode(myId) + + expect(el).not.toBeNull() + + expect(el.getAttribute('id')).toBe(myId) + }) }) diff --git a/packages/utils/__tests__/vue/icon.test.ts b/packages/utils/__tests__/vue/icon.test.ts new file mode 100644 index 0000000000..b8d898caa5 --- /dev/null +++ b/packages/utils/__tests__/vue/icon.test.ts @@ -0,0 +1,42 @@ +import { shallowMount } from '@vue/test-utils' +import { describe, expect, it } from 'vitest' +import { TypeComponentsMap, ValidateComponentsMap } from '../..' + +describe('TypeComponentsMap', () => { + it('Given a type "success", it should return SuccessFilled component', () => { + const component = shallowMount(TypeComponentsMap.success) + expect(component.exists()).toBe(true) + }) + + it('Given a type "warning", it should return WarningFilled component', () => { + const component = shallowMount(TypeComponentsMap.warning) + expect(component.exists()).toBe(true) + }) + + it('Given a type "error", it should return CircleCloseFilled component', () => { + const component = shallowMount(TypeComponentsMap.error) + expect(component.exists()).toBe(true) + }) + + it('Given a type "info", it should return InfoFilled component', () => { + const component = shallowMount(TypeComponentsMap.info) + expect(component.exists()).toBe(true) + }) +}) + +describe('ValidateComponentsMap', () => { + it('Given a validation state "validating", it should return Loading component', () => { + const component = shallowMount(ValidateComponentsMap.validating) + expect(component.exists()).toBe(true) + }) + + it('Given a validation state "success", it should return CircleCheck component', () => { + const component = shallowMount(ValidateComponentsMap.success) + expect(component.exists()).toBe(true) + }) + + it('Given a validation state "error", it should return CircleClose component', () => { + const component = shallowMount(ValidateComponentsMap.error) + expect(component.exists()).toBe(true) + }) +}) diff --git a/packages/utils/__tests__/vue/install.test.ts b/packages/utils/__tests__/vue/install.test.ts new file mode 100644 index 0000000000..ef4d5041b1 --- /dev/null +++ b/packages/utils/__tests__/vue/install.test.ts @@ -0,0 +1,98 @@ +import { createApp } from 'vue' +import { describe, expect, it } from 'vitest' +import { withInstall, withInstallDirective } from '../..' + +describe('withInstall', () => { + it('it should add an install method to the main component', () => { + const mainComponent = { + name: 'MainComponent', + render: () => null, + } + + const componentWithInstall = withInstall(mainComponent) + expect(typeof componentWithInstall.install).toBe('function') + }) + + it('it should register the main component and extra components when calling install', () => { + const mainComponent = { + name: 'MainComponent', + render: () => null, + } + + const extraComponents = { + ExtraComponent: { + name: 'ExtraComponent', + render: () => null, + }, + } + + const app = createApp({}) + const componentWithInstall = withInstall(mainComponent, extraComponents) + + componentWithInstall.install?.(app) + + expect(app.component('MainComponent')).toBeTruthy() + expect(app.component('ExtraComponent')).toBeTruthy() + }) + + it('it should add extra components to the main component when provided', () => { + const mainComponent = { + name: 'MainComponent', + render: () => null, + } + + const extraComponents = { + ExtraComponent: { + name: 'ExtraComponent', + render: () => null, + }, + } + + const componentWithInstall = withInstall(mainComponent, extraComponents) + + expect(componentWithInstall.ExtraComponent).toBeTruthy() + }) + + it('it should not add extra components if none provided', () => { + const mainComponent = { + name: 'MainComponent', + render: () => null, + } + + const componentWithInstall = withInstall(mainComponent) + + expect(componentWithInstall.ExtraComponent).toBeFalsy() + }) +}) + +describe('withInstallDirective', () => { + it('it should add an install method to the directive', () => { + const directive = { + mounted: () => null, + unmounted: () => null, + } + + const directiveWithInstall = withInstallDirective( + directive, + 'test-directive' + ) + expect(typeof directiveWithInstall.install).toBe('function') + }) + + it('it should register the directive when calling install', () => { + const directive = { + mounted: () => null, + unmounted: () => null, + } + + const app = createApp({}) + const directiveWithInstall = withInstallDirective( + directive, + 'test-directive' + ) + + directiveWithInstall.install?.(app) + + expect(app.directive('test-directive')).toBeTruthy() + }) +}) diff --git a/packages/utils/__tests__/vue/vnode.test.ts b/packages/utils/__tests__/vue/vnode.test.ts new file mode 100644 index 0000000000..607ca02864 --- /dev/null +++ b/packages/utils/__tests__/vue/vnode.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'vitest' +import { ensureOnlyChild } from '../..' + +describe('ensureOnlyChild', () => { + it('it should throw an error if input is not an array or undefined', () => { + expect(() => { + ensureOnlyChild('not an array' as any) + }).toThrow('expect to receive a single Vue element child') + }) + + it('it should throw an error if input array has more than one element', () => { + expect(() => { + ensureOnlyChild([1, 2]) + }).toThrow('expect to receive a single Vue element child') + }) + + it('it should return the only child if input is an array with one element', () => { + const child = { type: 'div' } + expect(ensureOnlyChild([child as any])).toEqual(child) + }) +})