Skip to content

Commit 4e0c45a

Browse files
Add tests
1 parent 803197c commit 4e0c45a

File tree

6 files changed

+232
-0
lines changed

6 files changed

+232
-0
lines changed

src/plugin/__tests__/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { createVColorField } from '../';
3+
4+
5+
describe('Plugin Index', () => {
6+
describe('install', () => {
7+
it('should return install function', () => {
8+
const VColorField = createVColorField();
9+
10+
expect('install' in VColorField).toBe(true);
11+
});
12+
});
13+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Classes Composable > should return class object 1`] = `
4+
{
5+
"v-color-field--card": true,
6+
"v-color-field--card-full-width": true,
7+
}
8+
`;
9+
10+
exports[`Classes Composable > useCardClasses > should return class object 1`] = `
11+
{
12+
"v-color-field--card": true,
13+
"v-color-field--card-full-width": false,
14+
}
15+
`;
16+
17+
exports[`Classes Composable > useHintClasses > should return class object 1`] = `
18+
{
19+
"v-color-field--text-field": true,
20+
}
21+
`;
22+
23+
exports[`Classes Composable > usePipClasses > should return class object 1`] = `
24+
{
25+
"v-color-field--pip": true,
26+
}
27+
`;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { describe, it, expect } from 'vitest';
2+
import {
3+
usePipClasses,
4+
useTextFieldClasses,
5+
useHintClasses,
6+
useCardClasses
7+
} from '../classes';
8+
9+
10+
describe('Classes Composable', () => {
11+
12+
describe('usePipClasses', () => {
13+
it('should return class object', () => {
14+
const classes = usePipClasses();
15+
16+
expect(classes).toMatchSnapshot();
17+
});
18+
});
19+
20+
describe('useTextFieldClasses', () => {
21+
it('should return class object', () => {
22+
const classes = useTextFieldClasses({
23+
readonlyInput: false,
24+
});
25+
26+
expect(classes).toMatchInlineSnapshot(`
27+
{
28+
"v-color-field--text-field": true,
29+
"v-color-field--text-field-": false,
30+
"v-color-field--text-field-readonly": false,
31+
"v-color-field--text-field-readonly-input": false,
32+
}
33+
`);
34+
});
35+
36+
it('should return class object', () => {
37+
const classes = useTextFieldClasses({
38+
name: 'foobar',
39+
readonly: true,
40+
readonlyInput: true,
41+
});
42+
43+
expect(classes).toMatchInlineSnapshot(`
44+
{
45+
"v-color-field--text-field": true,
46+
"v-color-field--text-field-foobar": true,
47+
"v-color-field--text-field-readonly": true,
48+
"v-color-field--text-field-readonly-input": false,
49+
}
50+
`);
51+
});
52+
});
53+
54+
describe('useHintClasses', () => {
55+
it('should return class object', () => {
56+
const classes = useHintClasses({
57+
58+
});
59+
60+
expect(classes).toMatchSnapshot();
61+
});
62+
});
63+
64+
describe('useCardClasses', () => {
65+
it('should return class object', () => {
66+
const classes = useCardClasses({
67+
fullWidth: false,
68+
});
69+
70+
expect(classes).toMatchSnapshot();
71+
});
72+
});
73+
74+
it('should return class object', () => {
75+
const classes = useCardClasses({
76+
fullWidth: true,
77+
});
78+
79+
expect(classes).toMatchSnapshot();
80+
});
81+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, it, expect } from 'vitest';
2+
import {
3+
useConvertToUnit,
4+
} from '../helpers';
5+
6+
describe('Helpers Composable', () => {
7+
describe('useConvertToUnit', () => {
8+
it('should return string with a default px unit', () => {
9+
const unit = useConvertToUnit({ value: '10' });
10+
expect(unit).toBe('10px');
11+
});
12+
13+
it('should return number with a default px unit', () => {
14+
const unit = useConvertToUnit({ value: 10 });
15+
expect(unit).toBe('10px');
16+
});
17+
18+
it('should return string with a supplied unit', () => {
19+
const unit = useConvertToUnit({ unit: 'em', value: '10' });
20+
expect(unit).toBe('10em');
21+
});
22+
23+
it('should return number with a supplied unit', () => {
24+
const unit = useConvertToUnit({ unit: 'em', value: 10 });
25+
expect(unit).toBe('10em');
26+
});
27+
});
28+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { describe, it, expect } from 'vitest';
2+
// import { inject } from 'vue';
3+
import {
4+
useGetIcon
5+
} from '../icons';
6+
7+
8+
const iconOptions = {
9+
defaultSet: 'mdi'
10+
};
11+
12+
describe('Icon Composable', () => {
13+
describe('useGetIcon', () => {
14+
it('should return supplied icon value', () => {
15+
16+
const unit = useGetIcon({
17+
icon: 'mdi:mdi-cog',
18+
iconOptions,
19+
name: 'pip',
20+
});
21+
22+
expect(unit).toMatchInlineSnapshot(`"mdi:mdi-cog"`);
23+
});
24+
25+
it('should return icon value using name', () => {
26+
const unit = useGetIcon({
27+
icon: undefined,
28+
iconOptions,
29+
name: 'pip',
30+
});
31+
32+
expect(unit).toMatchInlineSnapshot(`"mdi:mdi-circle"`);
33+
});
34+
35+
it('throws error if vuetify defaultSet is not supplied', () => {
36+
expect(() => useGetIcon({
37+
icon: undefined,
38+
iconOptions: {},
39+
name: 'loading',
40+
})).toThrowError('[VColorField]: No VColorField default undefined icon set found.');
41+
});
42+
43+
it('throws error if supplied name not found', () => {
44+
expect(() => useGetIcon({
45+
icon: undefined,
46+
iconOptions,
47+
name: 'foobar',
48+
})).toThrowError('[VColorField]: No foobar icon found.');
49+
});
50+
});
51+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { usePipStyles } from '../styles';
3+
4+
5+
describe('Styles Composable', () => {
6+
describe('usePipStyles', () => {
7+
it('should return pip styles with border and borderRadius', () => {
8+
const data = usePipStyles({
9+
pipBorder: '1px solid rgb(var(--v-theme-on-surface))',
10+
pipBorderRadius: '50%',
11+
});
12+
expect(data).toMatchInlineSnapshot(`
13+
{
14+
"backgroundColor": "rgb(var(--v-theme-on-surface))",
15+
"border": "1px solid rgb(var(--v-theme-on-surface))",
16+
"borderRadius": "50%",
17+
"overflow": "hidden",
18+
}
19+
`);
20+
});
21+
22+
it('should return pip styles without border and borderRadius', () => {
23+
const data = usePipStyles({});
24+
expect(data).toMatchInlineSnapshot(`
25+
{
26+
"backgroundColor": "transparent",
27+
"overflow": "hidden",
28+
}
29+
`);
30+
});
31+
});
32+
});

0 commit comments

Comments
 (0)