Skip to content

Commit 8715373

Browse files
Add tests
1 parent 9ddffd8 commit 8715373

13 files changed

+666
-0
lines changed

Diff for: src/plugin/__tests__/index.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { createVResizeDrawer } from '../';
3+
4+
5+
describe('Plugin Index', () => {
6+
describe('install', () => {
7+
it('should return install function', () => {
8+
const VResizeDrawer = createVResizeDrawer();
9+
10+
expect('install' in VResizeDrawer).toBe(true);
11+
});
12+
});
13+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Classes Composable > useDrawerClasses > should return class object 1`] = `
4+
{
5+
"v-navigation-drawer--absolute": false,
6+
"v-navigation-drawer--custom-rail": true,
7+
"v-navigation-drawer--fixed": true,
8+
"v-navigation-drawer--floating": null,
9+
"v-navigation-drawer--is-mouseover": false,
10+
"v-navigation-drawer--left": true,
11+
"v-navigation-drawer--open-on-hover": false,
12+
"v-navigation-drawer--rail": false,
13+
"v-navigation-drawer--right": false,
14+
"v-navigation-drawer--temporary": false,
15+
"v-resize-drawer": true,
16+
}
17+
`;
18+
19+
exports[`Classes Composable > useHandleContainerClasses > should return class object 1`] = `
20+
{
21+
"v-resize-drawer--handle-container": true,
22+
"v-resize-drawer--handle-container-parent-start": true,
23+
"v-resize-drawer--handle-container-position-center": true,
24+
}
25+
`;
26+
27+
exports[`Classes Composable > useHandleContainerClasses > should return class object 2`] = `
28+
{
29+
"v-resize-drawer--handle-container": true,
30+
"v-resize-drawer--handle-container-parent-left": true,
31+
"v-resize-drawer--handle-container-position-top": true,
32+
}
33+
`;
34+
35+
exports[`Classes Composable > useHandleIconClasses > should return class object with fa classes as false 1`] = `
36+
{
37+
"v-resize-drawer--handle-container-icon": true,
38+
"v-resize-drawer--handle-container-icon-fa": false,
39+
"v-resize-drawer--handle-container-icon-fa-top": false,
40+
"v-resize-drawer--handle-container-icon-top-start": true,
41+
"v-resize-drawer--handle-container-icon-user-icon": false,
42+
}
43+
`;
44+
45+
exports[`Classes Composable > useHandleIconClasses > should return class object with fa classes as true 1`] = `
46+
{
47+
"v-resize-drawer--handle-container-icon": true,
48+
"v-resize-drawer--handle-container-icon-center-left": true,
49+
"v-resize-drawer--handle-container-icon-fa": true,
50+
"v-resize-drawer--handle-container-icon-fa-center": true,
51+
"v-resize-drawer--handle-container-icon-user-icon": false,
52+
}
53+
`;

Diff for: src/plugin/composables/__tests__/classes.test.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { describe, it, expect } from 'vitest';
2+
import {
3+
useDrawerClasses,
4+
useHandleContainerClasses,
5+
useHandleIconClasses,
6+
} from '../classes';
7+
8+
9+
describe('Classes Composable', () => {
10+
describe('useDrawerClasses', () => {
11+
it('should return class object', () => {
12+
const classes = useDrawerClasses({
13+
absolute: false,
14+
expandOnHover: false,
15+
floating: null,
16+
isMouseover: false,
17+
location: 'start',
18+
rail: false,
19+
railWidth: '8',
20+
temporary: undefined,
21+
});
22+
23+
expect(classes).toMatchSnapshot();
24+
});
25+
});
26+
27+
describe('useHandleContainerClasses', () => {
28+
it('should return class object', () => {
29+
const classes = useHandleContainerClasses({
30+
drawerLocation: 'start',
31+
handlePosition: 'center',
32+
});
33+
34+
expect(classes).toMatchSnapshot();
35+
});
36+
37+
it('should return class object', () => {
38+
const classes = useHandleContainerClasses({
39+
drawerLocation: 'left',
40+
handlePosition: 'top',
41+
});
42+
43+
expect(classes).toMatchSnapshot();
44+
});
45+
});
46+
47+
describe('useHandleIconClasses', () => {
48+
it('should return class object with fa classes as false', () => {
49+
const classes = useHandleIconClasses({
50+
drawerLocation: 'start',
51+
handlePosition: 'top',
52+
iconOptions: {
53+
defaultSet: 'mdi'
54+
},
55+
isUserIcon: false,
56+
});
57+
58+
expect(classes).toMatchSnapshot();
59+
});
60+
61+
it('should return class object with fa classes as true', () => {
62+
const classes = useHandleIconClasses({
63+
drawerLocation: 'left',
64+
handlePosition: 'center',
65+
iconOptions: {
66+
defaultSet: 'fa'
67+
},
68+
isUserIcon: false,
69+
});
70+
71+
expect(classes).toMatchSnapshot();
72+
});
73+
});
74+
});

Diff for: src/plugin/composables/__tests__/colors.test.ts

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import {
2+
describe,
3+
it,
4+
expect,
5+
vi,
6+
} from 'vitest';
7+
import {
8+
useGetColor,
9+
} from '../colors';
10+
import vuetify from '../../../plugins/vuetify';
11+
12+
const theme = vuetify.theme;
13+
14+
15+
describe('Colors Composable', () => {
16+
describe('useGetColor', () => {
17+
it('should return color name as HSL', () => {
18+
const color = useGetColor('red', theme);
19+
expect(color).toMatchInlineSnapshot(`"hsl(0 100% 50%)"`);
20+
});
21+
22+
it('should return hex value as HSL', () => {
23+
const color = useGetColor('#f00', theme);
24+
expect(color).toMatchInlineSnapshot(`"hsl(0 100% 50%)"`);
25+
});
26+
27+
it('should return RGB value as HSL', () => {
28+
const color = useGetColor('rgb(255,0,0)', theme);
29+
expect(color).toMatchInlineSnapshot(`"hsl(0 100% 50%)"`);
30+
});
31+
32+
it('should return HSL value as HSL', () => {
33+
const color = useGetColor('hsl(0 100% 50%)', theme);
34+
expect(color).toMatchInlineSnapshot(`"hsl(0 100% 50%)"`);
35+
});
36+
37+
it('should return theme variable as an RGB', () => {
38+
const color = useGetColor('--v-theme-error', theme);
39+
expect(color).toMatchInlineSnapshot(`"rgb(var(--v-theme-error))"`);
40+
});
41+
42+
it('should return a non theme color option as default HSL color value', () => {
43+
const color = useGetColor('foobar', theme);
44+
45+
expect(color).toMatchInlineSnapshot(`"hsl(0 0% 100% / 12%)"`);
46+
});
47+
48+
it('should return a non theme variable as default HSL color value', () => {
49+
const color = useGetColor('--v-foobar', theme);
50+
51+
expect(color).toMatchInlineSnapshot(`"hsl(0 0% 100% / 12%)"`);
52+
});
53+
54+
// console.warn tests //
55+
const logSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
56+
57+
it('should console warn when color prop "foobar" doesn\'t exist in colors', () => {
58+
logSpy.mockReset();
59+
60+
useGetColor('foobar', theme);
61+
62+
expect(logSpy).toHaveBeenCalled();
63+
expect(logSpy).toHaveBeenCalledTimes(1);
64+
});
65+
66+
it('should console warn when color prop "--v-foobar" doesn\'t exist in colors', () => {
67+
logSpy.mockReset();
68+
69+
useGetColor('--v-foobar', theme);
70+
71+
expect(logSpy).toHaveBeenCalled();
72+
expect(logSpy).toHaveBeenCalledTimes(1);
73+
});
74+
});
75+
});

Diff for: src/plugin/composables/__tests__/helpers.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, it, expect } from 'vitest';
2+
import {
3+
useConvertToUnit,
4+
} from '../helpers';
5+
6+
7+
describe('Helpers Composable', () => {
8+
describe('useConvertToUnit', () => {
9+
it('should return string with a default px unit', () => {
10+
const unit = useConvertToUnit({ value: '10' });
11+
expect(unit).toBe('10px');
12+
});
13+
14+
it('should return number with a default px unit', () => {
15+
const unit = useConvertToUnit({ value: 10 });
16+
expect(unit).toBe('10px');
17+
});
18+
19+
it('should return string with a supplied unit', () => {
20+
const unit = useConvertToUnit({ unit: 'em', value: '10' });
21+
expect(unit).toBe('10em');
22+
});
23+
24+
it('should return number with a supplied unit', () => {
25+
const unit = useConvertToUnit({ unit: 'em', value: 10 });
26+
expect(unit).toBe('10em');
27+
});
28+
});
29+
});

Diff for: src/plugin/composables/__tests__/icons.test.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { useGetIcon } from '../icons';
3+
4+
5+
const iconOptions = {
6+
defaultSet: 'mdi'
7+
};
8+
9+
describe('Icon Composable', () => {
10+
describe('useGetIcon', () => {
11+
it('should return supplied icon value', () => {
12+
13+
const unit = useGetIcon({
14+
icon: 'mdi:mdi-cog',
15+
iconOptions,
16+
name: 'top',
17+
});
18+
19+
expect(unit).toMatchInlineSnapshot(`"mdi:mdi-cog"`);
20+
});
21+
22+
it('should return icon value using name', () => {
23+
const unit = useGetIcon({
24+
icon: undefined,
25+
iconOptions,
26+
name: 'center',
27+
});
28+
29+
expect(unit).toMatchInlineSnapshot(`"mdi:mdi-chevron-double-right"`);
30+
});
31+
32+
it('throws error if vuetify defaultSet is not supplied', () => {
33+
expect(() => useGetIcon({
34+
icon: undefined,
35+
iconOptions: {},
36+
name: 'top',
37+
})).toThrowError('[VResizeDrawer]: No default undefined icon set found.');
38+
});
39+
40+
it('throws error if supplied name not found', () => {
41+
expect(() => useGetIcon({
42+
icon: undefined,
43+
iconOptions,
44+
name: 'foobar',
45+
})).toThrowError('[VResizeDrawer]: No foobar icon found.');
46+
});
47+
});
48+
});

0 commit comments

Comments
 (0)