@weni/unnnic-system 3.36.0 → 3.36.1-alpha.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.
Files changed (36) hide show
  1. package/dist/components/MultiSelect/MultiSelectOption.css +1 -1
  2. package/dist/components/MultiSelect/MultiSelectOption.vue.mjs +2 -2
  3. package/dist/components/MultiSelect/MultiSelectOption.vue2.mjs +41 -15
  4. package/dist/components/MultiSelect/MultiSelectTreeOptions.css +1 -0
  5. package/dist/components/MultiSelect/MultiSelectTreeOptions.vue.mjs +7 -0
  6. package/dist/components/MultiSelect/MultiSelectTreeOptions.vue2.mjs +50 -0
  7. package/dist/components/MultiSelect/index.css +1 -1
  8. package/dist/components/MultiSelect/index.vue.mjs +2 -2
  9. package/dist/components/MultiSelect/index.vue2.mjs +126 -114
  10. package/dist/composables/useMultiSelectRows.mjs +74 -0
  11. package/dist/composables/useMultiSelectSelection.mjs +44 -0
  12. package/dist/composables/useSelectBase.mjs +44 -39
  13. package/dist/composables/useSelectKeyboard.mjs +70 -35
  14. package/dist/composables/useTreeExpansion.mjs +24 -0
  15. package/dist/lib/tree-selection.mjs +66 -0
  16. package/dist/locales/en.json.mjs +9 -5
  17. package/dist/style.css +4 -2
  18. package/dist/unnnic.umd.js +19 -19
  19. package/package.json +2 -2
  20. package/src/components/MultiSelect/MultiSelectOption.vue +66 -3
  21. package/src/components/MultiSelect/MultiSelectTreeOptions.vue +73 -0
  22. package/src/components/MultiSelect/__tests__/MultiSelect.spec.js +556 -0
  23. package/src/components/MultiSelect/__tests__/MultiSelectOption.spec.js +55 -1
  24. package/src/components/MultiSelect/__tests__/__snapshots__/MultiSelectOption.spec.js.snap +5 -0
  25. package/src/components/MultiSelect/index.vue +57 -50
  26. package/src/components/Select/_select-shared.scss +8 -0
  27. package/src/components/Select/types.ts +1 -0
  28. package/src/composables/useMultiSelectRows.ts +121 -0
  29. package/src/composables/useMultiSelectSelection.ts +97 -0
  30. package/src/composables/useSelectBase.ts +40 -16
  31. package/src/composables/useSelectKeyboard.ts +92 -18
  32. package/src/composables/useTreeExpansion.ts +44 -0
  33. package/src/lib/__tests__/tree-selection.spec.ts +141 -0
  34. package/src/lib/tree-selection.ts +156 -0
  35. package/src/locales/en.json +3 -1
  36. package/src/stories/MultiSelect.stories.js +62 -1
@@ -587,6 +587,562 @@ describe('UnnnicMultiSelect.vue', () => {
587
587
  });
588
588
  });
589
589
 
590
+ describe('tree mode', () => {
591
+ const treeOptions = [
592
+ {
593
+ label: 'Status do pedido',
594
+ value: 'status',
595
+ children: [
596
+ { label: 'Atraso na entrega', value: 'atraso' },
597
+ { label: 'Rastreamento', value: 'rastreamento' },
598
+ { label: 'Nota fiscal', value: 'nota' },
599
+ ],
600
+ },
601
+ {
602
+ label: 'Pagamento',
603
+ value: 'pagamento',
604
+ children: [{ label: 'Pix', value: 'pix' }],
605
+ },
606
+ { label: 'Unclassified', value: 'unclassified' },
607
+ ];
608
+
609
+ async function mountTree(props = {}) {
610
+ wrapper.unmount();
611
+ wrapper = mountWrapper({
612
+ options: treeOptions,
613
+ modelValue: [],
614
+ ...props,
615
+ });
616
+ wrapper.vm.setOpenPopover(true);
617
+ await wrapper.vm.$nextTick();
618
+ return wrapper;
619
+ }
620
+
621
+ async function expandFirstParent() {
622
+ const options = wrapper.findAllComponents({
623
+ name: 'UnnnicMultiSelectOption',
624
+ });
625
+ await options[0].vm.$emit('update:expanded', true);
626
+ await wrapper.vm.$nextTick();
627
+ }
628
+
629
+ function pressKey(key) {
630
+ document.dispatchEvent(
631
+ new KeyboardEvent('keydown', { key, bubbles: true }),
632
+ );
633
+ }
634
+
635
+ function getFocusedIndex() {
636
+ return wrapper
637
+ .findAllComponents({ name: 'UnnnicMultiSelectOption' })
638
+ .findIndex((option) => option.props('focused'));
639
+ }
640
+
641
+ test('renders only root rows while parents are collapsed', async () => {
642
+ await mountTree();
643
+ const options = wrapper.findAllComponents({
644
+ name: 'UnnnicMultiSelectOption',
645
+ });
646
+ expect(options.length).toBe(3);
647
+ expect(options[0].props('expandable')).toBe(true);
648
+ expect(options[0].props('expanded')).toBe(false);
649
+ expect(options[2].props('expandable')).toBe(false);
650
+ expect(options[2].props('level')).toBe(1);
651
+ });
652
+
653
+ test('expands a parent and shows its children', async () => {
654
+ await mountTree();
655
+ await expandFirstParent();
656
+
657
+ const options = wrapper.findAllComponents({
658
+ name: 'UnnnicMultiSelectOption',
659
+ });
660
+ expect(options.length).toBe(6);
661
+ expect(options[1].props('label')).toBe('Atraso na entrega');
662
+ expect(options[1].props('level')).toBe(2);
663
+ });
664
+
665
+ test('checking a parent selects it and every child', async () => {
666
+ await mountTree();
667
+ const options = wrapper.findAllComponents({
668
+ name: 'UnnnicMultiSelectOption',
669
+ });
670
+
671
+ await options[0].vm.$emit('update:model-value', true);
672
+
673
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
674
+ 'atraso',
675
+ 'rastreamento',
676
+ 'nota',
677
+ 'status',
678
+ ]);
679
+ });
680
+
681
+ test('unchecking a parent clears it and its children', async () => {
682
+ await mountTree({
683
+ modelValue: ['status', 'atraso', 'rastreamento', 'nota'],
684
+ });
685
+ const options = wrapper.findAllComponents({
686
+ name: 'UnnnicMultiSelectOption',
687
+ });
688
+
689
+ await options[0].vm.$emit('update:model-value', false);
690
+
691
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([]);
692
+ });
693
+
694
+ test('shows the parent as indeterminate when only some children are selected', async () => {
695
+ await mountTree({ modelValue: ['atraso'] });
696
+ const options = wrapper.findAllComponents({
697
+ name: 'UnnnicMultiSelectOption',
698
+ });
699
+
700
+ expect(options[0].props('active')).toBe('less');
701
+ });
702
+
703
+ test('clicking an indeterminate parent selects every child', async () => {
704
+ await mountTree({ modelValue: ['atraso'] });
705
+ const options = wrapper.findAllComponents({
706
+ name: 'UnnnicMultiSelectOption',
707
+ });
708
+
709
+ await options[0].vm.$emit('update:model-value', true);
710
+
711
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
712
+ 'atraso',
713
+ 'rastreamento',
714
+ 'nota',
715
+ 'status',
716
+ ]);
717
+ });
718
+
719
+ test('ticking the last child adds the parent value', async () => {
720
+ await mountTree({ modelValue: ['atraso', 'rastreamento'] });
721
+ await expandFirstParent();
722
+
723
+ const options = wrapper.findAllComponents({
724
+ name: 'UnnnicMultiSelectOption',
725
+ });
726
+ await options[3].vm.$emit('update:model-value', true);
727
+
728
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
729
+ 'atraso',
730
+ 'rastreamento',
731
+ 'nota',
732
+ 'status',
733
+ ]);
734
+ });
735
+
736
+ test('skips disabled children and counts only enabled ones for the parent', async () => {
737
+ const optionsWithDisabled = [
738
+ {
739
+ label: 'Parent',
740
+ value: 'parent',
741
+ children: [
742
+ { label: 'Off', value: 'off', disabled: true },
743
+ { label: 'On', value: 'on' },
744
+ ],
745
+ },
746
+ ];
747
+ await mountTree({ options: optionsWithDisabled });
748
+ const options = wrapper.findAllComponents({
749
+ name: 'UnnnicMultiSelectOption',
750
+ });
751
+
752
+ await options[0].vm.$emit('update:model-value', true);
753
+
754
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
755
+ 'on',
756
+ 'parent',
757
+ ]);
758
+ });
759
+
760
+ test('an incoming parent value implies its children', async () => {
761
+ await mountTree({ modelValue: ['status'] });
762
+ await expandFirstParent();
763
+
764
+ const options = wrapper.findAllComponents({
765
+ name: 'UnnnicMultiSelectOption',
766
+ });
767
+ expect(options[0].props('active')).toBe(true);
768
+ expect(options[1].props('active')).toBe(true);
769
+
770
+ await options[1].vm.$emit('update:model-value', false);
771
+
772
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
773
+ 'rastreamento',
774
+ 'nota',
775
+ ]);
776
+ });
777
+
778
+ test('keeps values that are not in the options', async () => {
779
+ await mountTree({ modelValue: ['unknown'] });
780
+ const options = wrapper.findAllComponents({
781
+ name: 'UnnnicMultiSelectOption',
782
+ });
783
+
784
+ await options[2].vm.$emit('update:model-value', true);
785
+
786
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
787
+ 'unknown',
788
+ 'unclassified',
789
+ ]);
790
+ });
791
+
792
+ test('emits option objects with returnObject', async () => {
793
+ await mountTree({ returnObject: true });
794
+ const options = wrapper.findAllComponents({
795
+ name: 'UnnnicMultiSelectOption',
796
+ });
797
+
798
+ await options[1].vm.$emit('update:model-value', true);
799
+
800
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
801
+ treeOptions[1].children[0],
802
+ treeOptions[1],
803
+ ]);
804
+ });
805
+
806
+ test('treats empty children as a flat list', async () => {
807
+ await mountTree({
808
+ options: [{ label: 'Leaf', value: 'leaf', children: [] }],
809
+ });
810
+
811
+ expect(document.querySelector('[role="tree"]')).toBeNull();
812
+ });
813
+
814
+ test('renders 550 options expanded and searched', async () => {
815
+ const manyOptions = Array.from({ length: 50 }, (_, parentIndex) => ({
816
+ label: `Topic ${parentIndex}`,
817
+ value: `topic-${parentIndex}`,
818
+ children: Array.from({ length: 10 }, (_, childIndex) => ({
819
+ label: `Subtopic ${parentIndex}-${childIndex}`,
820
+ value: `subtopic-${parentIndex}-${childIndex}`,
821
+ })),
822
+ }));
823
+ await mountTree({ options: manyOptions, enableSearch: true });
824
+
825
+ await wrapper.setProps({ search: 'Subtopic' });
826
+ expect(
827
+ wrapper.findAllComponents({ name: 'UnnnicMultiSelectOption' }).length,
828
+ ).toBe(550);
829
+
830
+ await wrapper.setProps({ search: 'Subtopic 7-' });
831
+ expect(
832
+ wrapper.findAllComponents({ name: 'UnnnicMultiSelectOption' }).length,
833
+ ).toBe(11);
834
+ });
835
+
836
+ test('restores the manual expansion when the search is cleared', async () => {
837
+ await mountTree({ enableSearch: true });
838
+ await expandFirstParent();
839
+
840
+ await wrapper.setProps({ search: 'Pix' });
841
+ await wrapper.setProps({ search: '' });
842
+
843
+ const options = wrapper.findAllComponents({
844
+ name: 'UnnnicMultiSelectOption',
845
+ });
846
+ expect(options.length).toBe(6);
847
+ expect(options[0].props('expanded')).toBe(true);
848
+ expect(options[4].props('expanded')).toBe(false);
849
+ });
850
+
851
+ test('closed field lists display items in tree order', async () => {
852
+ await mountTree({
853
+ modelValue: ['unclassified', 'pix', 'pagamento', 'nota'],
854
+ });
855
+
856
+ expect(wrapper.vm.inputValue).toBe(
857
+ 'Nota fiscal, Pagamento, Unclassified',
858
+ );
859
+ });
860
+
861
+ test('ArrowRight moves into the first child of an expanded parent', async () => {
862
+ await mountTree();
863
+ await expandFirstParent();
864
+ await flushPromises();
865
+ await flushPromises();
866
+
867
+ pressKey('ArrowDown');
868
+ await flushPromises();
869
+ pressKey('ArrowRight');
870
+ await flushPromises();
871
+
872
+ expect(getFocusedIndex()).toBe(1);
873
+ });
874
+
875
+ test('ArrowLeft moves from a child to its parent', async () => {
876
+ await mountTree();
877
+ await expandFirstParent();
878
+ await flushPromises();
879
+ await flushPromises();
880
+
881
+ pressKey('ArrowDown');
882
+ pressKey('ArrowDown');
883
+ pressKey('ArrowDown');
884
+ await flushPromises();
885
+ pressKey('ArrowLeft');
886
+ await flushPromises();
887
+
888
+ expect(getFocusedIndex()).toBe(0);
889
+ });
890
+
891
+ test('Enter toggles the focused parent', async () => {
892
+ await mountTree();
893
+ await flushPromises();
894
+ await flushPromises();
895
+
896
+ pressKey('ArrowDown');
897
+ pressKey('ArrowDown');
898
+ await flushPromises();
899
+ pressKey('Enter');
900
+ await flushPromises();
901
+
902
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
903
+ 'pix',
904
+ 'pagamento',
905
+ ]);
906
+ });
907
+
908
+ test('clamps the focus when a collapse shrinks the list', async () => {
909
+ await mountTree();
910
+ await expandFirstParent();
911
+ await flushPromises();
912
+ await flushPromises();
913
+
914
+ for (let step = 0; step < 6; step += 1) pressKey('ArrowDown');
915
+ await flushPromises();
916
+ expect(getFocusedIndex()).toBe(5);
917
+
918
+ const options = wrapper.findAllComponents({
919
+ name: 'UnnnicMultiSelectOption',
920
+ });
921
+ await options[0].vm.$emit('update:expanded', false);
922
+ await flushPromises();
923
+
924
+ expect(getFocusedIndex()).toBe(2);
925
+ });
926
+
927
+ test('flat lists ignore Space', async () => {
928
+ wrapper.vm.setOpenPopover(true);
929
+ await flushPromises();
930
+ await flushPromises();
931
+
932
+ pressKey('ArrowDown');
933
+ await flushPromises();
934
+ pressKey(' ');
935
+ await flushPromises();
936
+
937
+ expect(wrapper.emitted('update:modelValue')).toBeFalsy();
938
+ });
939
+
940
+ const getOptionLabels = () =>
941
+ wrapper
942
+ .findAllComponents({ name: 'UnnnicMultiSelectOption' })
943
+ .map((option) => option.props('label'));
944
+
945
+ test('search matching a parent keeps all of its children', async () => {
946
+ await mountTree({ enableSearch: true, search: 'Status' });
947
+
948
+ expect(wrapper.vm.filteredOptions.map(({ value }) => value)).toEqual([
949
+ 'status',
950
+ ]);
951
+ expect(getOptionLabels()).toEqual([
952
+ 'Status do pedido',
953
+ 'Atraso na entrega',
954
+ 'Rastreamento',
955
+ 'Nota fiscal',
956
+ ]);
957
+ });
958
+
959
+ test('search matching a child keeps its parent with only matching children', async () => {
960
+ await mountTree({ enableSearch: true, search: 'Rastre' });
961
+
962
+ expect(wrapper.vm.filteredOptions.map(({ value }) => value)).toEqual([
963
+ 'status',
964
+ ]);
965
+ expect(getOptionLabels()).toEqual(['Status do pedido', 'Rastreamento']);
966
+ });
967
+
968
+ test('matching branches render expanded while search is not empty', async () => {
969
+ await mountTree({ enableSearch: true, search: 'Status' });
970
+ const options = wrapper.findAllComponents({
971
+ name: 'UnnnicMultiSelectOption',
972
+ });
973
+
974
+ expect(options[0].props('expanded')).toBe(true);
975
+ expect(options.length).toBe(4);
976
+ });
977
+
978
+ test('lets the user collapse and expand branches while searching', async () => {
979
+ await mountTree({ enableSearch: true, search: 'Status' });
980
+ const getOptions = () =>
981
+ wrapper.findAllComponents({ name: 'UnnnicMultiSelectOption' });
982
+
983
+ await getOptions()[0].vm.$emit('update:expanded', false);
984
+ expect(getOptions()).toHaveLength(1);
985
+ expect(getOptions()[0].props('expanded')).toBe(false);
986
+
987
+ await getOptions()[0].vm.$emit('update:expanded', true);
988
+ expect(getOptions()).toHaveLength(4);
989
+ });
990
+
991
+ test('expands branches again when a new search starts', async () => {
992
+ await mountTree({ enableSearch: true, search: 'Status' });
993
+ const getOptions = () =>
994
+ wrapper.findAllComponents({ name: 'UnnnicMultiSelectOption' });
995
+
996
+ await getOptions()[0].vm.$emit('update:expanded', false);
997
+ await wrapper.setProps({ search: '' });
998
+ await wrapper.setProps({ search: 'Status' });
999
+
1000
+ expect(getOptions()[0].props('expanded')).toBe(true);
1001
+ });
1002
+
1003
+ test('shows no results when the tree search has no matches', async () => {
1004
+ await mountTree({ enableSearch: true, search: 'no-match' });
1005
+
1006
+ expect(wrapper.vm.filteredOptions).toEqual([]);
1007
+ expect(
1008
+ document.querySelector('.unnnic-multi-select__content-no-results'),
1009
+ ).not.toBeNull();
1010
+ });
1011
+
1012
+ test('closed field shows only the parent label when every child is selected', async () => {
1013
+ await mountTree({
1014
+ modelValue: ['status', 'atraso', 'rastreamento', 'nota'],
1015
+ });
1016
+
1017
+ expect(wrapper.vm.inputValue).toBe('Status do pedido');
1018
+ });
1019
+
1020
+ test('closed field lists checked children when the parent is partial', async () => {
1021
+ await mountTree({ modelValue: ['atraso'] });
1022
+
1023
+ expect(wrapper.vm.inputValue).toBe('Atraso na entrega');
1024
+ });
1025
+
1026
+ test('clear button emits an empty model', async () => {
1027
+ await mountTree({
1028
+ clearable: true,
1029
+ modelValue: ['status', 'atraso', 'rastreamento', 'nota'],
1030
+ });
1031
+ const input = wrapper.findComponent({ name: 'UnnnicInput' });
1032
+
1033
+ await input.vm.$emit('clear');
1034
+
1035
+ expect(wrapper.emitted('update:modelValue')[0]).toEqual([[]]);
1036
+ });
1037
+
1038
+ test('exposes tree ARIA attributes', async () => {
1039
+ await mountTree({ modelValue: ['atraso'] });
1040
+
1041
+ const tree = document.querySelector('[role="tree"]');
1042
+ const parent = document.querySelector('[role="treeitem"]');
1043
+
1044
+ expect(tree).not.toBeNull();
1045
+ expect(parent?.getAttribute('aria-level')).toBe('1');
1046
+ expect(parent?.getAttribute('aria-checked')).toBe('mixed');
1047
+ expect(parent?.getAttribute('aria-expanded')).toBe('false');
1048
+ });
1049
+
1050
+ test('resets expansion when the popover closes', async () => {
1051
+ await mountTree();
1052
+ await expandFirstParent();
1053
+ expect(
1054
+ wrapper.findAllComponents({ name: 'UnnnicMultiSelectOption' }).length,
1055
+ ).toBe(6);
1056
+
1057
+ wrapper.vm.setOpenPopover(false);
1058
+ await wrapper.vm.$nextTick();
1059
+ wrapper.vm.setOpenPopover(true);
1060
+ await wrapper.vm.$nextTick();
1061
+
1062
+ expect(
1063
+ wrapper.findAllComponents({ name: 'UnnnicMultiSelectOption' }).length,
1064
+ ).toBe(3);
1065
+ });
1066
+
1067
+ test('ArrowRight expands the focused parent', async () => {
1068
+ await mountTree();
1069
+ await flushPromises();
1070
+ await flushPromises();
1071
+
1072
+ document.dispatchEvent(
1073
+ new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }),
1074
+ );
1075
+ await flushPromises();
1076
+ document.dispatchEvent(
1077
+ new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true }),
1078
+ );
1079
+ await flushPromises();
1080
+
1081
+ expect(
1082
+ wrapper.findAllComponents({ name: 'UnnnicMultiSelectOption' }).length,
1083
+ ).toBe(6);
1084
+ });
1085
+
1086
+ test('ArrowLeft collapses the focused parent', async () => {
1087
+ await mountTree();
1088
+ await expandFirstParent();
1089
+ await flushPromises();
1090
+ await flushPromises();
1091
+
1092
+ document.dispatchEvent(
1093
+ new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }),
1094
+ );
1095
+ await flushPromises();
1096
+ document.dispatchEvent(
1097
+ new KeyboardEvent('keydown', { key: 'ArrowLeft', bubbles: true }),
1098
+ );
1099
+ await flushPromises();
1100
+
1101
+ expect(
1102
+ wrapper.findAllComponents({ name: 'UnnnicMultiSelectOption' }).length,
1103
+ ).toBe(3);
1104
+ });
1105
+
1106
+ test('Space toggles the focused option', async () => {
1107
+ await mountTree();
1108
+ await flushPromises();
1109
+ await flushPromises();
1110
+
1111
+ document.dispatchEvent(
1112
+ new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }),
1113
+ );
1114
+ await flushPromises();
1115
+ document.dispatchEvent(
1116
+ new KeyboardEvent('keydown', { key: ' ', bubbles: true }),
1117
+ );
1118
+ await flushPromises();
1119
+
1120
+ expect(wrapper.emitted('update:modelValue')).toBeTruthy();
1121
+ expect(wrapper.emitted('update:modelValue')[0][0]).toEqual([
1122
+ 'atraso',
1123
+ 'rastreamento',
1124
+ 'nota',
1125
+ 'status',
1126
+ ]);
1127
+ });
1128
+
1129
+ test('Space is ignored while the search input has focus', async () => {
1130
+ await mountTree({ enableSearch: true });
1131
+ await flushPromises();
1132
+ await flushPromises();
1133
+
1134
+ const searchInput = document.querySelector(
1135
+ '.unnnic-multi-select__input-search input',
1136
+ );
1137
+ searchInput.dispatchEvent(
1138
+ new KeyboardEvent('keydown', { key: ' ', bubbles: true }),
1139
+ );
1140
+ await flushPromises();
1141
+
1142
+ expect(wrapper.emitted('update:modelValue')).toBeFalsy();
1143
+ });
1144
+ });
1145
+
590
1146
  describe('keyboard navigation', () => {
591
1147
  test('closes popover through keyboard close callback', async () => {
592
1148
  wrapper.vm.setOpenPopover(true);
@@ -1,9 +1,15 @@
1
1
  import { mount } from '@vue/test-utils';
2
2
  import { beforeEach, describe, expect, test, afterEach } from 'vitest';
3
3
  import MultiSelectOption from '../MultiSelectOption.vue';
4
+ import i18n from '@/utils/plugins/i18n';
4
5
 
5
6
  const createWrapper = (props = {}) => {
6
- return mount(MultiSelectOption, { props });
7
+ return mount(MultiSelectOption, {
8
+ props,
9
+ global: {
10
+ plugins: [i18n],
11
+ },
12
+ });
7
13
  };
8
14
 
9
15
  describe('MultiSelectOption.vue', () => {
@@ -72,6 +78,54 @@ describe('MultiSelectOption.vue', () => {
72
78
  });
73
79
  });
74
80
 
81
+ describe('indeterminate state', () => {
82
+ test('passes less to the checkbox modelValue', async () => {
83
+ await wrapper.setProps({ active: 'less' });
84
+ const checkbox = wrapper.findComponent({ name: 'UnnnicCheckbox' });
85
+ expect(checkbox.props('modelValue')).toBe('less');
86
+ });
87
+
88
+ test('emits true when the checkbox is clicked while less', async () => {
89
+ await wrapper.setProps({ active: 'less' });
90
+ const checkbox = wrapper.findComponent({ name: 'UnnnicCheckbox' });
91
+
92
+ await checkbox.vm.$emit('update:model-value', false);
93
+
94
+ expect(wrapper.emitted('update:modelValue')[0][0]).toBe(true);
95
+ });
96
+ });
97
+
98
+ describe('tree props', () => {
99
+ test('renders the expand button and emits update:expanded', async () => {
100
+ await wrapper.setProps({ expandable: true, expanded: false });
101
+
102
+ const button = wrapper.find('.unnnic-multi-select-option__expand');
103
+ expect(button.exists()).toBe(true);
104
+ expect(button.attributes('aria-expanded')).toBe('false');
105
+
106
+ await button.trigger('click');
107
+
108
+ expect(wrapper.emitted('update:expanded')[0][0]).toBe(true);
109
+ });
110
+
111
+ test('applies the level 2 modifier class', async () => {
112
+ await wrapper.setProps({ level: 2 });
113
+ expect(wrapper.classes()).toContain(
114
+ 'unnnic-multi-select-option--level-2',
115
+ );
116
+ });
117
+
118
+ test('renders a spacer on a root leaf', async () => {
119
+ await wrapper.setProps({ level: 1, expandable: false });
120
+ expect(
121
+ wrapper.find('.unnnic-multi-select-option__expand-spacer').exists(),
122
+ ).toBe(true);
123
+ expect(wrapper.find('.unnnic-multi-select-option__expand').exists()).toBe(
124
+ false,
125
+ );
126
+ });
127
+ });
128
+
75
129
  describe('active state', () => {
76
130
  test('passes active prop to checkbox modelValue when active is true', async () => {
77
131
  await wrapper.setProps({ active: true });
@@ -2,6 +2,7 @@
2
2
 
3
3
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with active state 1`] = `
4
4
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
5
+ <!--v-if-->
5
6
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox" checked="">
6
7
  <p data-v-18939422="" class="unnnic-checkbox__label" data-testid="checkbox-text-right">Test Option</p>
7
8
  </label>
@@ -12,6 +13,7 @@ exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with active
12
13
 
13
14
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with both active and disabled states 1`] = `
14
15
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
16
+ <!--v-if-->
15
17
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper unnnic-checkbox__input-wrapper--disabled"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox" disabled="" checked="">
16
18
  <p data-v-18939422="" class="unnnic-checkbox__label unnnic-checkbox__label--disabled" data-testid="checkbox-text-right">Test Option</p>
17
19
  </label>
@@ -22,6 +24,7 @@ exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with both a
22
24
 
23
25
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with default props 1`] = `
24
26
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
27
+ <!--v-if-->
25
28
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox">
26
29
  <p data-v-18939422="" class="unnnic-checkbox__label" data-testid="checkbox-text-right">Test Option</p>
27
30
  </label>
@@ -32,6 +35,7 @@ exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with defaul
32
35
 
33
36
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with disabled state 1`] = `
34
37
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
38
+ <!--v-if-->
35
39
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper unnnic-checkbox__input-wrapper--disabled"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox" disabled="">
36
40
  <p data-v-18939422="" class="unnnic-checkbox__label unnnic-checkbox__label--disabled" data-testid="checkbox-text-right">Test Option</p>
37
41
  </label>
@@ -42,6 +46,7 @@ exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with disabl
42
46
 
43
47
  exports[`MultiSelectOption.vue > snapshot testing > matches snapshot with focused state 1`] = `
44
48
  "<div data-v-7d79eb5d="" class="unnnic-multi-select-option">
49
+ <!--v-if-->
45
50
  <section data-v-18939422="" data-v-7d79eb5d="" class="unnnic-checkbox"><label data-v-18939422="" class="unnnic-checkbox__input-wrapper"><input data-v-18939422="" class="unnnic-checkbox__input" type="checkbox">
46
51
  <p data-v-18939422="" class="unnnic-checkbox__label" data-testid="checkbox-text-right">Test Option</p>
47
52
  </label>