srcdev-nuxt-forms 2.1.28 → 2.1.29

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.
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <fieldset class="multiple-checkboxes-fieldset" :class="[{ error: fieldHasError }]">
2
+ <fieldset class="multiple-checkboxes-fieldset" :class="[elementClasses, { error: fieldHasError }]" :data-testid>
3
3
  <legend :class="[{ 'has-description': hasDescription }]">{{ legend }}</legend>
4
4
 
5
5
  <div v-if="hasDescriptionSlot" :id="`${id}-description`">
@@ -59,10 +59,14 @@
59
59
  </template>
60
60
 
61
61
  <script setup lang="ts">
62
- import propValidators from '../../c12/prop-validators';
62
+ import propValidators from '../c12/prop-validators';
63
63
  import type { IOptionsConfig, IFormMultipleOptions } from '@/types/types.forms';
64
64
 
65
- const { id, name, legend, label, required, fieldHasError, placeholder, isButton, errorMessage, size, optionsLayout, equalCols, styleClassPassthrough, theme, direction } = defineProps({
65
+ const { dataTestid, id, name, legend, label, required, fieldHasError, placeholder, isButton, errorMessage, size, optionsLayout, equalCols, styleClassPassthrough, theme, direction } = defineProps({
66
+ dataTestid: {
67
+ type: String,
68
+ default: 'multiple-checkboxes',
69
+ },
66
70
  id: {
67
71
  type: String,
68
72
  required: true,
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <fieldset class="single-checkbox-fieldset" :class="[{ error: fieldHasError }]">
2
+ <fieldset class="single-checkbox-fieldset" :class="[elementClasses, { error: fieldHasError }]" :data-testid>
3
3
  <legend :class="[{ 'has-description': hasDescription }]">{{ legend }}</legend>
4
4
 
5
5
  <div v-if="hasDescriptionSlot" :id="`${name}-description`">
@@ -21,10 +21,14 @@
21
21
  </template>
22
22
 
23
23
  <script setup lang="ts">
24
- import propValidators from '../../c12/prop-validators';
24
+ import propValidators from '../c12/prop-validators';
25
25
  import type { IFormMultipleOptions } from '@/types/types.forms';
26
26
 
27
- const { id, name, legend, label, required, fieldHasError, errorMessage, size, optionsLayout, equalCols, trueValue, falseValue, styleClassPassthrough, theme } = defineProps({
27
+ const { dataTestid, id, name, legend, label, required, fieldHasError, errorMessage, size, optionsLayout, equalCols, trueValue, falseValue, styleClassPassthrough, theme } = defineProps({
28
+ dataTestid: {
29
+ type: String,
30
+ default: 'multiple-radio-buttons',
31
+ },
28
32
  id: {
29
33
  type: String,
30
34
  required: true,
@@ -0,0 +1,98 @@
1
+ // https://nuxt.com/docs/getting-started/testing#unit-testing
2
+ import { describe, it, expect } from 'vitest';
3
+ import { VueWrapper } from '@vue/test-utils';
4
+ import { mountSuspended } from '@nuxt/test-utils/runtime';
5
+ import ComponentUnderTest from '../MultipleCheckboxes.vue';
6
+ import tagsData from './data/tags.json';
7
+
8
+ let initialPropsData = {
9
+ dataTestid: 'multiple-checkboxes',
10
+ id: 'tags',
11
+ name: 'tags',
12
+ legend: 'Choose tags (as checkboxes)',
13
+ required: true,
14
+ label: 'Check between 3 and 8 tags',
15
+ placeholder: 'eg. Type something here',
16
+ isButton: true,
17
+ errorMessage: 'Please select between 3 and 8 tags',
18
+ fieldHasError: false,
19
+ fieldData: tagsData,
20
+ size: 'small',
21
+ optionsLayout: 'inline',
22
+ styleClassPassthrough: ['testClass'],
23
+ theme: 'primary',
24
+ };
25
+
26
+ const initialSlots = {
27
+ checkedIcon: () => ``,
28
+ itemIcon: () => `<Icon name="material-symbols:add-2" class="icon" />`,
29
+ };
30
+
31
+ let wrapper: VueWrapper<InstanceType<typeof ComponentUnderTest>>;
32
+ const wrapperFactory = (propsData = {}, slotsData = {}) => {
33
+ const mockPropsData = { ...initialPropsData, ...propsData };
34
+ const mockSlotsData = { ...initialSlots, ...slotsData };
35
+
36
+ return mountSuspended(ComponentUnderTest, {
37
+ attachTo: document.body,
38
+ props: mockPropsData,
39
+ slots: mockSlotsData,
40
+ });
41
+ };
42
+
43
+ describe('MultipleCheckboxes Component', () => {
44
+ it('Mounts', async () => {
45
+ wrapper = await wrapperFactory();
46
+ expect(wrapper).toBeTruthy();
47
+ });
48
+
49
+ it('renders properly', async () => {
50
+ wrapper = await wrapperFactory();
51
+ const dataTestIdElem = wrapper.attributes('data-testid');
52
+ expect(dataTestIdElem).toBe(initialPropsData.dataTestid);
53
+ expect(wrapper.find('[data-testid]').classes()).toContain('testClass');
54
+ });
55
+
56
+ it('updates checkbox modelValue when items clicked', async () => {
57
+ const modelValue = ref<string[]>([]);
58
+ const propsData = {
59
+ modelValue,
60
+ };
61
+ wrapper = await wrapperFactory(propsData);
62
+ const checkboxElements = wrapper.findAll('input[type="checkbox"]');
63
+
64
+ /*
65
+ * Test the first checkbox checked
66
+ **/
67
+ const firstCheckbox = checkboxElements[0];
68
+ expect(firstCheckbox.attributes('aria-checked')).toBe('false');
69
+ const firstCheckboxTrueValue = firstCheckbox.attributes('true-value');
70
+
71
+ await firstCheckbox.trigger('click');
72
+
73
+ expect(wrapper.emitted()).toHaveProperty('update:modelValue');
74
+ const firstEmittedEvents = wrapper.emitted('update:modelValue');
75
+ if (firstEmittedEvents && firstEmittedEvents[0]) {
76
+ expect(firstEmittedEvents[0]).includes(firstCheckboxTrueValue);
77
+ }
78
+
79
+ expect(firstCheckbox.attributes('aria-checked')).toBe('true');
80
+
81
+ /*
82
+ * Test the second checkbox chekced
83
+ **/
84
+ const secondCheckbox = checkboxElements[1];
85
+ expect(secondCheckbox.attributes('aria-checked')).toBe('false');
86
+ const secondCheckboxTrueValue = secondCheckbox.attributes('true-value');
87
+
88
+ await secondCheckbox.trigger('click');
89
+
90
+ expect(wrapper.emitted()).toHaveProperty('update:modelValue');
91
+ const secondEmittedEvents = wrapper.emitted('update:modelValue');
92
+ if (secondEmittedEvents && secondEmittedEvents[0]) {
93
+ expect(secondEmittedEvents[1]).includes(secondCheckboxTrueValue);
94
+ }
95
+
96
+ expect(secondCheckbox.attributes('aria-checked')).toBe('true');
97
+ });
98
+ });
@@ -0,0 +1,67 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "pizza",
5
+ "name": "tags",
6
+ "value": "pizza",
7
+ "label": "Pizza"
8
+ },
9
+ {
10
+ "id": "italian",
11
+ "name": "tags",
12
+ "value": "italian",
13
+ "label": "Italian"
14
+ },
15
+ {
16
+ "id": "vegetarian",
17
+ "name": "tags",
18
+ "value": "vegetarian",
19
+ "label": "Vegetarian"
20
+ },
21
+ {
22
+ "id": "stir-fry",
23
+ "name": "tags",
24
+ "value": "stir-fry",
25
+ "label": "Stir-fry"
26
+ },
27
+ {
28
+ "id": "asian",
29
+ "name": "tags",
30
+ "value": "asian",
31
+ "label": "Asian"
32
+ },
33
+ {
34
+ "id": "cookies",
35
+ "name": "tags",
36
+ "value": "cookies",
37
+ "label": "Cookies"
38
+ },
39
+ {
40
+ "id": "dessert",
41
+ "name": "tags",
42
+ "value": "dessert",
43
+ "label": "Dessert"
44
+ },
45
+ {
46
+ "id": "baking",
47
+ "name": "tags",
48
+ "value": "baking",
49
+ "label": "Baking"
50
+ },
51
+ {
52
+ "id": "pasta",
53
+ "name": "tags",
54
+ "value": "pasta",
55
+ "label": "Pasta"
56
+ },
57
+ {
58
+ "id": "chicken",
59
+ "name": "tags",
60
+ "value": "chicken",
61
+ "label": "Chicken"
62
+ }
63
+ ],
64
+ "total": 5,
65
+ "skip": 0,
66
+ "limit": 10
67
+ }
@@ -6,8 +6,8 @@
6
6
 
7
7
  <input
8
8
  :type
9
- :true-value="trueValue"
10
- :false-value="falseValue"
9
+ :true-value
10
+ :false-value
11
11
  :id
12
12
  :name
13
13
  :required="required && !multipleOptions"
@@ -103,7 +103,7 @@ const isArray = Array.isArray(modelValue.value);
103
103
 
104
104
  const isChecked = computed(() => {
105
105
  if (isArray) {
106
- return modelValue.value.indexOf(trueValue) > -1;
106
+ return modelValue.value.includes(trueValue);
107
107
  } else {
108
108
  return modelValue.value === trueValue;
109
109
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <fieldset :aria-required="required" :aria-invalid="fieldHasError" role="radiogroup" class="multiple-radiobuttons-fieldset" :class="[{ error: fieldHasError }]">
2
+ <fieldset :aria-required="required" :aria-invalid="fieldHasError" role="radiogroup" class="multiple-radiobuttons-fieldset" :class="[elementClasses, { error: fieldHasError }]" :data-testid>
3
3
  <legend :class="[{ 'has-description': hasDescriptionSlot }]">{{ legend }}</legend>
4
4
 
5
5
  <div v-if="hasDescriptionSlot" :id="`${name}-description`">
@@ -62,7 +62,11 @@
62
62
  import propValidators from '../c12/prop-validators';
63
63
  import type { IFormMultipleOptions } from '@/types/types.forms';
64
64
 
65
- const { id, name, legend, label, required, fieldHasError, placeholder, isButton, errorMessage, size, optionsLayout, equalCols, styleClassPassthrough, theme, direction } = defineProps({
65
+ const { dataTestid, id, name, legend, label, required, fieldHasError, placeholder, isButton, errorMessage, size, optionsLayout, equalCols, styleClassPassthrough, theme, direction } = defineProps({
66
+ dataTestid: {
67
+ type: String,
68
+ default: 'multiple-radio-buttons',
69
+ },
66
70
  id: {
67
71
  type: String,
68
72
  required: true,
@@ -0,0 +1,89 @@
1
+ // https://nuxt.com/docs/getting-started/testing#unit-testing
2
+ import { describe, it, expect } from 'vitest';
3
+ import { VueWrapper } from '@vue/test-utils';
4
+ import { mountSuspended } from '@nuxt/test-utils/runtime';
5
+ import ComponentUnderTest from '../MultipleRadioButtons.vue';
6
+ import tagsData from './data/tags.json';
7
+
8
+ let initialPropsData = {
9
+ dataTestid: 'multiple-radio-buttons',
10
+ id: 'tags',
11
+ name: 'tags',
12
+ legend: 'Choose tags (as checkboxes)',
13
+ required: true,
14
+ label: 'Check between 3 and 8 tags',
15
+ placeholder: 'eg. Type something here',
16
+ isButton: true,
17
+ errorMessage: 'Please select between 3 and 8 tags',
18
+ fieldHasError: false,
19
+ fieldData: tagsData,
20
+ size: 'small',
21
+ optionsLayout: 'inline',
22
+ styleClassPassthrough: ['testClass'],
23
+ theme: 'primary',
24
+ };
25
+
26
+ const initialSlots = {
27
+ checkedIcon: () => ``,
28
+ itemIcon: () => `<Icon name="material-symbols:add-2" class="icon" />`,
29
+ };
30
+
31
+ let wrapper: VueWrapper<InstanceType<typeof ComponentUnderTest>>;
32
+ const wrapperFactory = (propsData = {}, slotsData = {}) => {
33
+ const mockPropsData = { ...initialPropsData, ...propsData };
34
+ const mockSlotsData = { ...initialSlots, ...slotsData };
35
+
36
+ return mountSuspended(ComponentUnderTest, {
37
+ attachTo: document.body,
38
+ props: mockPropsData,
39
+ slots: mockSlotsData,
40
+ });
41
+ };
42
+
43
+ describe('MultipleRadioButtons Component', () => {
44
+ it('Mounts', async () => {
45
+ wrapper = await wrapperFactory();
46
+ expect(wrapper).toBeTruthy();
47
+ });
48
+
49
+ it('renders properly', async () => {
50
+ wrapper = await wrapperFactory();
51
+ const dataTestIdElem = wrapper.attributes('data-testid');
52
+ expect(dataTestIdElem).toBe(initialPropsData.dataTestid);
53
+ expect(wrapper.find('[data-testid]').classes()).toContain('testClass');
54
+ });
55
+
56
+ it('updates radio modelValue when items clicked', async () => {
57
+ const modelValue = ref<string>('');
58
+ const propsData = {
59
+ modelValue,
60
+ };
61
+ wrapper = await wrapperFactory(propsData);
62
+
63
+ /*
64
+ * Test the first radio button
65
+ **/
66
+ const radiobuttonElements = wrapper.findAll('input[type="radio"]');
67
+ const firstRadioButton = radiobuttonElements[0];
68
+ expect(firstRadioButton.attributes('aria-checked')).toBe('false');
69
+ const firstRadioButtonTrueValue = firstRadioButton.attributes('true-value');
70
+
71
+ await firstRadioButton.trigger('click');
72
+ wrapper.vm.modelValue.value = firstRadioButtonTrueValue;
73
+ expect(firstRadioButton.attributes('aria-checked')).toBe('true');
74
+ expect(wrapper.vm.modelValue.value).toEqual(firstRadioButtonTrueValue);
75
+
76
+ /*
77
+ * Test the second radio button
78
+ **/
79
+ const secondRadioButton = radiobuttonElements[1];
80
+ expect(secondRadioButton.attributes('aria-checked')).toBe('false');
81
+ const secondRadioButtonTrueValue = secondRadioButton.attributes('true-value');
82
+
83
+ await secondRadioButton.trigger('click');
84
+ wrapper.vm.modelValue.value = secondRadioButtonTrueValue;
85
+ expect(firstRadioButton.attributes('aria-checked')).toBe('false');
86
+ expect(secondRadioButton.attributes('aria-checked')).toBe('true');
87
+ expect(wrapper.vm.modelValue.value).toEqual(secondRadioButtonTrueValue);
88
+ });
89
+ });
@@ -0,0 +1,67 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "pizza",
5
+ "name": "tags",
6
+ "value": "pizza",
7
+ "label": "Pizza"
8
+ },
9
+ {
10
+ "id": "italian",
11
+ "name": "tags",
12
+ "value": "italian",
13
+ "label": "Italian"
14
+ },
15
+ {
16
+ "id": "vegetarian",
17
+ "name": "tags",
18
+ "value": "vegetarian",
19
+ "label": "Vegetarian"
20
+ },
21
+ {
22
+ "id": "stir-fry",
23
+ "name": "tags",
24
+ "value": "stir-fry",
25
+ "label": "Stir-fry"
26
+ },
27
+ {
28
+ "id": "asian",
29
+ "name": "tags",
30
+ "value": "asian",
31
+ "label": "Asian"
32
+ },
33
+ {
34
+ "id": "cookies",
35
+ "name": "tags",
36
+ "value": "cookies",
37
+ "label": "Cookies"
38
+ },
39
+ {
40
+ "id": "dessert",
41
+ "name": "tags",
42
+ "value": "dessert",
43
+ "label": "Dessert"
44
+ },
45
+ {
46
+ "id": "baking",
47
+ "name": "tags",
48
+ "value": "baking",
49
+ "label": "Baking"
50
+ },
51
+ {
52
+ "id": "pasta",
53
+ "name": "tags",
54
+ "value": "pasta",
55
+ "label": "Pasta"
56
+ },
57
+ {
58
+ "id": "chicken",
59
+ "name": "tags",
60
+ "value": "chicken",
61
+ "label": "Chicken"
62
+ }
63
+ ],
64
+ "total": 5,
65
+ "skip": 0,
66
+ "limit": 10
67
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "srcdev-nuxt-forms",
3
3
  "type": "module",
4
- "version": "2.1.28",
4
+ "version": "2.1.29",
5
5
  "main": "nuxt.config.ts",
6
6
  "scripts": {
7
7
  "clean": "rm -rf .nuxt && rm -rf .output && rm -rf .playground/.nuxt && rm -rf .playground/.output",
8
+ "cleanall": "rm -rf node_modules && rm -rf .nuxt && rm -rf .output && rm -rf .playground/.nuxt && rm -rf .playground/.output && rm -rf .playground/node_modules && rm package-lock.json",
8
9
  "reinstall": "rm -rf node_modules && npm install",
9
10
  "dev": "nuxi dev .playground",
10
11
  "build": "nuxt build .playground",
@@ -23,12 +24,11 @@
23
24
  "types/"
24
25
  ],
25
26
  "devDependencies": {
26
- "@iconify-json/material-symbols": "1.2.10",
27
- "@nuxt/eslint-config": "0.7.2",
28
- "@nuxt/icon": "1.10.1",
27
+ "@nuxt/eslint-config": "0.7.3",
28
+ "@nuxt/icon": "1.10.2",
29
29
  "@nuxt/test-utils": "3.15.1",
30
30
  "@vue/test-utils": "2.4.6",
31
- "eslint": "9.16.0",
31
+ "eslint": "9.17.0",
32
32
  "happy-dom": "15.11.7",
33
33
  "nuxt": "3.14.1592",
34
34
  "release-it": "17.10.0",
@@ -37,15 +37,18 @@
37
37
  "vue": "3.5.13"
38
38
  },
39
39
  "dependencies": {
40
- "@iconify-json/carbon": "1.2.4",
41
- "@iconify-json/gridicons": "1.2.1",
42
- "@iconify-json/radix-icons": "1.2.1",
43
- "@iconify-json/ri": "1.2.3",
40
+ "@iconify-json/carbon": "1.2.5",
41
+ "@iconify-json/gridicons": "1.2.2",
42
+ "@iconify-json/material-symbols": "1.2.12",
43
+ "@iconify-json/material-symbols-light": "1.2.12",
44
+ "@iconify-json/ph": "1.2.2",
45
+ "@iconify-json/radix-icons": "1.2.2",
46
+ "@iconify-json/ri": "1.2.5",
44
47
  "@nuxtjs/storybook": "8.3.2",
45
- "@storybook/addon-essentials": "8.4.6",
46
- "@storybook/addon-interactions": "8.4.6",
47
- "@storybook/addon-links": "8.4.6",
48
- "@storybook/vue3": "8.4.6",
48
+ "@storybook/addon-essentials": "8.4.7",
49
+ "@storybook/addon-interactions": "8.4.7",
50
+ "@storybook/addon-links": "8.4.7",
51
+ "@storybook/vue3": "8.4.7",
49
52
  "http-proxy-middleware": "3.0.3",
50
53
  "modern-normalize": "3.0.1",
51
54
  "zod": "3.24.1"