11import { describe , it , expect } from 'vitest' ;
22import { fireEvent , render } from '@testing-library/svelte' ;
33
4- import AttributesTypesForm from '../../src/lib/components/v2/projects/datasets/AttributesTypesForm .svelte' ;
4+ import ImageAttributesTypesForm from '../../src/lib/components/v2/projects/datasets/ImageAttributesTypesForm .svelte' ;
55import { tick } from 'svelte' ;
66
77describe ( 'AttributesTypesForm' , ( ) => {
8- it ( 'init with existing filters ' , async ( ) => {
9- const result = render ( AttributesTypesForm ) ;
8+ it ( 'init with existing values ' , async ( ) => {
9+ const result = render ( ImageAttributesTypesForm ) ;
1010 result . component . init (
1111 {
1212 key1 : 'value1' ,
@@ -28,46 +28,46 @@ describe('AttributesTypesForm', () => {
2828 expect ( values [ 1 ] ) . eq ( '42' ) ;
2929 } ) ;
3030
31- it ( 'add and remove attribute filter ' , async ( ) => {
32- const result = render ( AttributesTypesForm ) ;
31+ it ( 'add and remove attribute' , async ( ) => {
32+ const result = render ( ImageAttributesTypesForm ) ;
3333 expect ( result . queryAllByPlaceholderText ( 'Key' ) . length ) . eq ( 0 ) ;
34- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
34+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
3535 expect ( result . queryAllByPlaceholderText ( 'Key' ) . length ) . eq ( 1 ) ;
36- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Remove attribute filter ' } ) ) ;
36+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Remove attribute' } ) ) ;
3737 expect ( result . queryAllByPlaceholderText ( 'Key' ) . length ) . eq ( 0 ) ;
3838 } ) ;
3939
40- it ( 'add and remove type filter ' , async ( ) => {
41- const result = render ( AttributesTypesForm ) ;
40+ it ( 'add and remove type' , async ( ) => {
41+ const result = render ( ImageAttributesTypesForm ) ;
4242 expect ( result . queryAllByPlaceholderText ( 'Key' ) . length ) . eq ( 0 ) ;
43- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type filter ' } ) ) ;
43+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type' } ) ) ;
4444 expect ( result . queryAllByPlaceholderText ( 'Key' ) . length ) . eq ( 1 ) ;
45- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Remove type filter ' } ) ) ;
45+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Remove type' } ) ) ;
4646 expect ( result . queryAllByPlaceholderText ( 'Key' ) . length ) . eq ( 0 ) ;
4747 } ) ;
4848
49- it ( 'validate missing attribute filter key' , async ( ) => {
50- const result = render ( AttributesTypesForm ) ;
49+ it ( 'validate missing attribute key' , async ( ) => {
50+ const result = render ( ImageAttributesTypesForm ) ;
5151 result . component . init ( { } , { } ) ;
52- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
52+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
5353 expect ( result . component . validateFields ( ) ) . false ;
5454 await tick ( ) ;
5555 expect ( result . getByText ( 'Key is required' ) ) . toBeDefined ( ) ;
5656 } ) ;
5757
58- it ( 'validate missing attribute filter value' , async ( ) => {
59- const result = render ( AttributesTypesForm ) ;
58+ it ( 'validate missing attribute value' , async ( ) => {
59+ const result = render ( ImageAttributesTypesForm ) ;
6060 result . component . init ( { } , { } ) ;
61- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
61+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
6262 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
6363 expect ( result . component . validateFields ( ) ) . false ;
6464 await tick ( ) ;
6565 expect ( result . getByText ( 'Value is required' ) ) . toBeDefined ( ) ;
6666 } ) ;
6767
6868 it ( 'validate invalid number' , async ( ) => {
69- const result = render ( AttributesTypesForm ) ;
70- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
69+ const result = render ( ImageAttributesTypesForm ) ;
70+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
7171 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
7272 await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'number' } } ) ;
7373 await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : 'foo' } } ) ;
@@ -77,8 +77,8 @@ describe('AttributesTypesForm', () => {
7777 } ) ;
7878
7979 it ( 'switch to number attribute from string containing a numeric value (number is preserved)' , async ( ) => {
80- const result = render ( AttributesTypesForm ) ;
81- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
80+ const result = render ( ImageAttributesTypesForm ) ;
81+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
8282 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
8383 await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : '42' } } ) ;
8484 await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'number' } } ) ;
@@ -87,8 +87,8 @@ describe('AttributesTypesForm', () => {
8787 } ) ;
8888
8989 it ( 'switch to number attribute from string containing text (number is reset)' , async ( ) => {
90- const result = render ( AttributesTypesForm ) ;
91- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
90+ const result = render ( ImageAttributesTypesForm ) ;
91+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
9292 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
9393 await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : 'foo' } } ) ;
9494 await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'number' } } ) ;
@@ -97,17 +97,17 @@ describe('AttributesTypesForm', () => {
9797 } ) ;
9898
9999 it ( 'switch to boolean attribute, default to false' , async ( ) => {
100- const result = render ( AttributesTypesForm ) ;
101- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
100+ const result = render ( ImageAttributesTypesForm ) ;
101+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
102102 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
103103 await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'boolean' } } ) ;
104104 expect ( result . getByLabelText ( 'Value' ) . value ) . eq ( 'false' ) ;
105105 expect ( result . component . validateFields ( ) ) . true ;
106106 } ) ;
107107
108108 it ( 'switch to boolean attribute from string equals to "true", true is set' , async ( ) => {
109- const result = render ( AttributesTypesForm ) ;
110- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
109+ const result = render ( ImageAttributesTypesForm ) ;
110+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
111111 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
112112 await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : 'true' } } ) ;
113113 await fireEvent . change ( result . getByLabelText ( 'Type' ) , { target : { value : 'boolean' } } ) ;
@@ -116,11 +116,11 @@ describe('AttributesTypesForm', () => {
116116 } ) ;
117117
118118 it ( 'validate duplicated attribute key' , async ( ) => {
119- const result = render ( AttributesTypesForm ) ;
120- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
119+ const result = render ( ImageAttributesTypesForm ) ;
120+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
121121 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
122122 await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : 'foo' } } ) ;
123- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
123+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
124124 await fireEvent . input ( result . queryAllByPlaceholderText ( 'Key' ) [ 1 ] , {
125125 target : { value : 'my-key' }
126126 } ) ;
@@ -133,32 +133,32 @@ describe('AttributesTypesForm', () => {
133133 } ) ;
134134
135135 it ( 'allow same key for attribute and type' , async ( ) => {
136- const result = render ( AttributesTypesForm ) ;
137- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute filter ' } ) ) ;
136+ const result = render ( ImageAttributesTypesForm ) ;
137+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add attribute' } ) ) ;
138138 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
139139 await fireEvent . input ( result . getByPlaceholderText ( 'Value' ) , { target : { value : 'foo' } } ) ;
140- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type filter ' } ) ) ;
140+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type' } ) ) ;
141141 await fireEvent . input ( result . queryAllByPlaceholderText ( 'Key' ) [ 1 ] , {
142142 target : { value : 'my-key' }
143143 } ) ;
144144 expect ( result . component . validateFields ( ) ) . true ;
145145 } ) ;
146146
147- it ( 'validate missing type filter key' , async ( ) => {
148- const result = render ( AttributesTypesForm ) ;
147+ it ( 'validate missing type key' , async ( ) => {
148+ const result = render ( ImageAttributesTypesForm ) ;
149149 result . component . init ( { } , { } ) ;
150- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type filter ' } ) ) ;
150+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type' } ) ) ;
151151 expect ( result . component . validateFields ( ) ) . false ;
152152 await tick ( ) ;
153153 expect ( result . getByText ( 'Key is required' ) ) . toBeDefined ( ) ;
154154 } ) ;
155155
156- it ( 'validate duplicated type filter key' , async ( ) => {
157- const result = render ( AttributesTypesForm ) ;
156+ it ( 'validate duplicated type key' , async ( ) => {
157+ const result = render ( ImageAttributesTypesForm ) ;
158158 result . component . init ( { } , { } ) ;
159- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type filter ' } ) ) ;
159+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type' } ) ) ;
160160 await fireEvent . input ( result . getByPlaceholderText ( 'Key' ) , { target : { value : 'my-key' } } ) ;
161- await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type filter ' } ) ) ;
161+ await fireEvent . click ( result . getByRole ( 'button' , { name : 'Add type' } ) ) ;
162162 await fireEvent . input ( result . queryAllByPlaceholderText ( 'Key' ) [ 1 ] , {
163163 target : { value : 'my-key' }
164164 } ) ;
0 commit comments