Skip to content

Commit 5db0ccf

Browse files
Add tests
1 parent 51816b5 commit 5db0ccf

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

src/plugin/__tests__/index.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Utilities
2+
import { describe, it, expect } from 'vitest';
3+
// import { mount } from '@vue/test-utils';
4+
import { createVInlineFields } from '@/plugin';
5+
6+
describe('framework', () => {
7+
describe('install', () => {
8+
it('should return install function', () => {
9+
const vInlineFields = createVInlineFields();
10+
11+
expect('install' in vInlineFields).toBe(true);
12+
});
13+
});
14+
});
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { describe, it, expect } from 'vitest';
2+
import {
3+
useConvertToUnit,
4+
useGetFieldCoordinates,
5+
useTruthyModelValue,
6+
} from '../helpers';
7+
8+
describe('helpers', () => {
9+
10+
describe('useConvertToUnit', () => {
11+
it('should return string with a default px unit', () => {
12+
const unit = useConvertToUnit({ str: '10' });
13+
expect(unit).toBe('10px');
14+
});
15+
16+
it('should return number with a default px unit', () => {
17+
const unit = useConvertToUnit({ str: 10 });
18+
expect(unit).toBe('10px');
19+
});
20+
21+
it('should return string with a supplied unit', () => {
22+
const unit = useConvertToUnit({ str: '10', unit: 'em' });
23+
expect(unit).toBe('10em');
24+
});
25+
26+
it('should return number with a supplied unit', () => {
27+
const unit = useConvertToUnit({ str: 10, unit: 'em' });
28+
expect(unit).toBe('10em');
29+
});
30+
});
31+
32+
33+
describe('useGetFieldCoordinates', () => {
34+
const div = document.createElement('div');
35+
const testInput = { cardOffsetX: 10, cardOffsetY: 10, field: div };
36+
let coordinates = useGetFieldCoordinates(testInput);
37+
38+
it('should return field coordinates as an object', () => {
39+
expect(coordinates).toBeTypeOf('object');
40+
});
41+
42+
it('should return field coordinates as an object equal to coordinates object', () => {
43+
expect(coordinates).toEqual({
44+
bottom: '10px',
45+
height: 0,
46+
left: '10px',
47+
right: '10px',
48+
top: '12px',
49+
width: '0',
50+
x: 0,
51+
y: 0
52+
});
53+
});
54+
55+
it('should return field (as null) coordinates as an object equal to', () => {
56+
coordinates = useGetFieldCoordinates({ cardOffsetX: 10, cardOffsetY: 10, field: null });
57+
58+
expect(coordinates).toEqual({
59+
bottom: 0,
60+
height: 0,
61+
left: 0,
62+
right: 0,
63+
top: 0,
64+
width: 0,
65+
x: 0,
66+
y: 0,
67+
});
68+
});
69+
});
70+
71+
describe('useTruthyModelValue', () => {
72+
it('should return modelValue = "1" as true', () => {
73+
const value = useTruthyModelValue({ modelValue: '1' });
74+
expect(value).toBeTruthy();
75+
});
76+
77+
it('should return modelValue = 1 as true', () => {
78+
const value = useTruthyModelValue({ modelValue: 1 });
79+
expect(value).toBeTruthy();
80+
});
81+
82+
it('should return modelValue = true as true', () => {
83+
const value = useTruthyModelValue({ modelValue: true });
84+
expect(value).toBeTruthy();
85+
});
86+
87+
it('should return modelValue = "true" as true', () => {
88+
const value = useTruthyModelValue({ modelValue: 'true' });
89+
expect(value).toBeTruthy();
90+
});
91+
92+
it('should return modelValue = trueValue as true using numbers', () => {
93+
const value = useTruthyModelValue({ modelValue: 10, trueValue: 10 });
94+
expect(value).toBeTruthy();
95+
});
96+
97+
it('should return modelValue = trueValue as true using number/string', () => {
98+
const value = useTruthyModelValue({ modelValue: 10, trueValue: '10' });
99+
expect(value).toBeTruthy();
100+
});
101+
102+
it('should return modelValue != trueValue as false using numbers', () => {
103+
const value = useTruthyModelValue({ modelValue: 10, trueValue: 20 });
104+
expect(value).toBeFalsy();
105+
});
106+
107+
it('should return modelValue != trueValue as false using number/string', () => {
108+
const value = useTruthyModelValue({ modelValue: 10, trueValue: '20' });
109+
110+
expect(value).toBeFalsy();
111+
});
112+
});
113+
114+
});

0 commit comments

Comments
 (0)