1
1
import { fireEvent , render , screen } from "@testing-library/react" ;
2
- import { test , fc } from "@fast-check/jest" ;
3
2
import "@testing-library/jest-dom" ;
4
3
import { DownloadImmutableFormInput } from "#/Artifacts/CardanoDbV2SnapshotsList/DownloadButton" ;
5
4
6
- const maxImmutable = 100000 ;
5
+ const maxImmutable = 100_000 ;
7
6
8
7
function setup ( max ) {
9
8
const utils = render ( < DownloadImmutableFormInput max = { max } /> ) ;
10
9
return {
11
- // Note: in `fast-check` tests `screen.getByRole("spinbutton")` find two elements for a reason I don't understand, so
12
- // I'm using getAllByRole and selecting the first one to avoid the error.
13
- input : screen . getAllByRole ( "spinbutton" ) [ 0 ] ,
10
+ input : screen . getByRole ( "spinbutton" ) ,
14
11
...utils ,
15
12
} ;
16
13
}
@@ -29,35 +26,32 @@ describe("DownloadImmutableFormInput", () => {
29
26
expect ( input . value ) . toBe ( "" ) ;
30
27
} ) ;
31
28
32
- test . prop ( {
33
- immutable_file_number : fc . nat ( {
34
- max : maxImmutable ,
35
- } ) ,
36
- } ) ( "Immutable below or equal to max allowed" , ( { immutable_file_number } ) => {
37
- const { input } = setup ( maxImmutable ) ;
38
- fireEvent . change ( input , {
39
- // target: { value: `${immutable_file_number}` },
40
- target : { value : immutable_file_number } ,
41
- } ) ;
29
+ it . each ( [ 0 , 123 , 67_782 , maxImmutable ] ) (
30
+ "Immutable below or equal to max allowed: %d" ,
31
+ ( immutable_file_number ) => {
32
+ const { input } = setup ( maxImmutable ) ;
33
+ fireEvent . change ( input , {
34
+ target : { value : immutable_file_number } ,
35
+ } ) ;
42
36
43
- expect ( input . checkValidity ( ) ) . toBeTruthy ( ) ;
44
- expect ( input . value ) . toBe ( `${ immutable_file_number } ` ) ;
45
- } ) ;
37
+ expect ( input . checkValidity ( ) ) . toBeTruthy ( ) ;
38
+ expect ( input . value ) . toBe ( `${ immutable_file_number } ` ) ;
39
+ } ,
40
+ ) ;
46
41
47
- test . prop ( {
48
- immutable_file_number : fc . oneof ( fc . integer ( { max : - 1 } ) , fc . integer ( { min : maxImmutable + 1 } ) ) ,
49
- } ) ( "Immutable above max or below 0 is invalid" , ( { immutable_file_number } ) => {
50
- const { input } = setup ( maxImmutable ) ;
51
- fireEvent . change ( input , {
52
- target : { value : immutable_file_number } ,
53
- } ) ;
42
+ it . each ( [ - 4328 , - 1 , maxImmutable + 1 , 528_432 ] ) (
43
+ "Immutable above max or below 0 is invalid: %d" ,
44
+ ( immutable_file_number ) => {
45
+ const { input } = setup ( maxImmutable ) ;
46
+ fireEvent . change ( input , {
47
+ target : { value : immutable_file_number } ,
48
+ } ) ;
54
49
55
- expect ( input . checkValidity ( ) ) . toBeFalsy ( ) ;
56
- } ) ;
50
+ expect ( input . checkValidity ( ) ) . toBeFalsy ( ) ;
51
+ } ,
52
+ ) ;
57
53
58
- test . prop ( {
59
- immutable_file_number : fc . string ( { minLength : 1 } ) . filter ( ( s ) => isNaN ( parseInt ( s ) ) ) ,
60
- } ) ( "Non-number is invalid" , ( { immutable_file_number } ) => {
54
+ it . each ( [ "@124" , "⚠️" , "text" ] ) ( "Non-number is invalid: %s" , ( immutable_file_number ) => {
61
55
const { input } = setup ( { maxImmutable } ) ;
62
56
fireEvent . change ( input , {
63
57
target : { value : immutable_file_number } ,
@@ -66,9 +60,7 @@ describe("DownloadImmutableFormInput", () => {
66
60
expect ( input . checkValidity ( ) ) . toBeFalsy ( ) ;
67
61
} ) ;
68
62
69
- test . prop ( {
70
- immutable_file_number : fc . float ( { noInteger : true } ) ,
71
- } ) ( "Float is invalid" , ( { immutable_file_number } ) => {
63
+ it . each ( [ 0.1 , 1.432 , 67_782.32 ] ) ( "Float is invalid: %f" , ( { immutable_file_number } ) => {
72
64
const { input } = setup ( { maxImmutable } ) ;
73
65
fireEvent . change ( input , {
74
66
target : { value : immutable_file_number } ,
0 commit comments