@weni/unnnic-system 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weni/unnnic-system",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "type": "commonjs",
5
5
  "files": [
6
6
  "dist",
@@ -24,7 +24,10 @@
24
24
  "lint": "eslint --ext .js,.vue --ignore-path .gitignore --fix src",
25
25
  "format": "prettier --write src/",
26
26
  "storybook": "storybook dev -p 6006",
27
- "build-storybook": "storybook build"
27
+ "build-storybook": "storybook build",
28
+ "test": "vitest",
29
+ "test:ui": "vitest --ui",
30
+ "coverage": "vitest --coverage"
28
31
  },
29
32
  "publishConfig": {
30
33
  "registry": "https://registry.npmjs.org/"
@@ -60,18 +63,23 @@
60
63
  "@storybook/vue3-vite": "^8.0.10",
61
64
  "@vitejs/plugin-vue": "^4.2.3",
62
65
  "@vitejs/plugin-vue-jsx": "^3.0.1",
66
+ "@vitest/coverage-v8": "^1.6.0",
67
+ "@vitest/ui": "^1.6.0",
63
68
  "@vue/eslint-config-prettier": "^9.0.0",
69
+ "@vue/test-utils": "^2.4.6",
64
70
  "@weni/eslint-config": "^1.0.3",
65
71
  "eslint": "^8.0.0",
66
72
  "eslint-config-prettier": "^9.1.0",
67
73
  "eslint-plugin-prettier": "^5.1.3",
68
74
  "eslint-plugin-storybook": "^0.8.0",
69
75
  "eslint-plugin-vue": "^9.25.0",
76
+ "jsdom": "^24.1.1",
70
77
  "react": "^18.2.0",
71
78
  "react-dom": "^18.2.0",
72
79
  "sass": "^1.62.1",
73
80
  "storybook": "^8.0.10",
74
81
  "vite": "4.3.5",
82
+ "vitest": "^1.6.0",
75
83
  "vue-eslint-parser": "^9.4.2"
76
84
  }
77
85
  }
@@ -18,6 +18,7 @@
18
18
  'unnnic-checkbox__label__right',
19
19
  `unnnic-checkbox__label__${size}`,
20
20
  ]"
21
+ data-testid="checkbox-text-right"
21
22
  >
22
23
  {{ textRight }}
23
24
  </div>
@@ -0,0 +1,66 @@
1
+ import { afterEach, describe, expect, it } from 'vitest';
2
+ import { mount } from '@vue/test-utils';
3
+
4
+ import Checkbox from '../Checkbox.vue';
5
+
6
+ const createWrapper = (props) => {
7
+ return mount(Checkbox, {
8
+ props,
9
+ });
10
+ };
11
+
12
+ describe('Checkbox', () => {
13
+ let wrapper;
14
+
15
+ afterEach(() => {
16
+ wrapper.unmount();
17
+ });
18
+
19
+ it('should render right label', () => {
20
+ wrapper = createWrapper({ textRight: 'Label Test' });
21
+ const label = wrapper.find('[data-testid="checkbox-text-right"]');
22
+ expect(label.text()).eq('Label Test');
23
+ });
24
+
25
+ it('should checkbox emit change events', async () => {
26
+ wrapper = createWrapper();
27
+ const checkbox = wrapper.findComponent({ name: 'Icon' });
28
+
29
+ // click false to true
30
+ await checkbox.trigger('click');
31
+ expect(wrapper.emitted('change')[0][0]).eq(true);
32
+
33
+ // click true to false
34
+ await wrapper.setProps({ modelValue: true });
35
+ await checkbox.trigger('click');
36
+ expect(wrapper.emitted('change')[1][0]).eq(false);
37
+
38
+ // click less to false
39
+ await wrapper.setProps({ modelValue: 'less' });
40
+ expect(wrapper.vm.icon).eq('checkbox-less');
41
+ await checkbox.trigger('click');
42
+ expect(wrapper.emitted('change')[2][0]).eq(false);
43
+ });
44
+
45
+ it('should checkbox disabled', async () => {
46
+ wrapper = createWrapper({ disabled: true });
47
+ const checkbox = wrapper.findComponent({ name: 'Icon' });
48
+ await checkbox.trigger('click');
49
+ expect(wrapper.emitted('change')).eq(undefined);
50
+ });
51
+
52
+ it('should define sizes', async () => {
53
+ wrapper = createWrapper({ size: 'sm', textRight: 'Label' });
54
+ const checkbox = wrapper.findComponent({ name: 'Icon' });
55
+ const label = wrapper.find('.unnnic-checkbox__label');
56
+
57
+ // sm
58
+ expect(checkbox.classes()).include('unnnic-icon__size--sm');
59
+ expect(label.classes()).include('unnnic-checkbox__label__sm');
60
+
61
+ // md
62
+ await wrapper.setProps({ size: 'md' });
63
+ expect(checkbox.classes()).include('unnnic-icon__size--md');
64
+ expect(label.classes()).include('unnnic-checkbox__label__md');
65
+ });
66
+ });
@@ -0,0 +1,30 @@
1
+ import { mount } from '@vue/test-utils';
2
+
3
+ import Label from '../Label.vue';
4
+ import { beforeEach, describe, expect, it } from 'vitest';
5
+
6
+ const createWrapper = () => {
7
+ return mount(Label, {
8
+ props: {
9
+ label: 'Label Test',
10
+ },
11
+ });
12
+ };
13
+
14
+ describe('Label', () => {
15
+ let wrapper;
16
+
17
+ beforeEach(() => {
18
+ wrapper = createWrapper();
19
+ });
20
+
21
+ it('should render label', () => {
22
+ const label = wrapper.findComponent({ name: 'UnnnicLabel' });
23
+ expect(label.text()).eq('Label Test');
24
+ });
25
+
26
+ it('applies the correct classes and styles', () => {
27
+ const label = wrapper.findComponent('.unnnic-label__label');
28
+ expect(label.html()).toMatchSnapshot();
29
+ });
30
+ });
@@ -0,0 +1,3 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Label > applies the correct classes and styles 1`] = `"<p class="unnnic-label__label">Label Test</p>"`;
@@ -1,34 +1,30 @@
1
- import unnnicCheckbox from '../components/Checkbox/Checkbox.vue';
1
+ import UnnnicCheckbox from '../components/Checkbox/Checkbox.vue';
2
2
 
3
3
  export default {
4
4
  title: 'Form/Checkbox',
5
- component: unnnicCheckbox,
5
+ component: UnnnicCheckbox,
6
6
  argTypes: {
7
- value: { control: 'inline-radio', options: [true, false, 'less'] },
7
+ modelValue: { control: 'inline-radio', options: [true, false, 'less'] },
8
8
  disabled: { control: 'boolean' },
9
9
  size: { control: 'select', options: ['md', 'sm'] },
10
+ textRight: { control: 'text' },
10
11
  },
11
12
  render: (args) => ({
12
13
  components: {
13
- unnnicCheckbox,
14
+ UnnnicCheckbox,
14
15
  },
15
16
  setup() {
16
17
  return { args };
17
18
  },
18
- data() {
19
- return {
20
- value: true,
21
- };
22
- },
23
19
  template: `
24
- <unnnicCheckbox v-model="value" />
20
+ <UnnnicCheckbox v-bind="args" @change="args.modelValue = $event" />
25
21
  `,
26
22
  }),
27
23
  };
28
24
 
29
25
  export const Default = {
30
26
  args: {
31
- value: true,
27
+ modelValue: true,
32
28
  disabled: false,
33
29
  size: 'md',
34
30
  },