1
+ const selector = require ( '../fixtures/selectors.json' ) ;
2
+
3
+ const viewport = [ 'macbook-15' , 'iphone-6' ] ;
4
+
5
+ describe ( 'Multi Select ' , ( ) => {
6
+
7
+ before ( function ( ) {
8
+ cy . visit ( 'http://localhost:8000/cypress-tests' ) ;
9
+ cy . title ( ) . should ( 'equal' , 'React-Select' ) ;
10
+ cy . get ( 'h1' ) . should ( 'contain' , 'Test Page for Cypress' ) ;
11
+ } ) ;
12
+
13
+ viewport . forEach ( view => {
14
+ before ( function ( ) {
15
+ cy . viewport ( view ) ;
16
+ } ) ;
17
+ beforeEach ( function ( ) {
18
+ cy . reload ( ) ;
19
+ } ) ;
20
+
21
+ it (
22
+ 'Should display several default values that can be removed ' + view ,
23
+ ( ) => {
24
+ cy
25
+ . get ( selector . multiSelectDefaultValues )
26
+ . then ( function ( $defaultValue ) {
27
+ expect ( $defaultValue ) . to . have . length ( 2 ) ;
28
+ expect ( $defaultValue . eq ( 0 ) ) . to . contain ( 'Purple' ) ;
29
+ expect ( $defaultValue . eq ( 1 ) ) . to . contain ( 'Red' ) ;
30
+ } ) ;
31
+
32
+ cy
33
+ . get ( selector . firstMultiValueRemove )
34
+ . click ( )
35
+ . get ( selector . multiSelectDefaultValues )
36
+ . then ( function ( $defaultValue ) {
37
+ expect ( $defaultValue ) . to . have . length ( 1 ) ;
38
+ expect ( $defaultValue . eq ( 0 ) ) . to . contain ( 'Red' ) ;
39
+ } )
40
+ . get ( selector . menuMulti )
41
+ . should ( 'not.be.visible' ) ;
42
+ }
43
+ ) ;
44
+
45
+ it (
46
+ 'Should be able to remove values on keyboard actions ' + view ,
47
+ ( ) => {
48
+ cy
49
+ . get ( selector . multiSelectInput )
50
+ . click ( )
51
+ . type ( '{backspace}' , { force : true } )
52
+ . get ( selector . multiSelectDefaultValues )
53
+ . then ( function ( $defaultValue ) {
54
+ expect ( $defaultValue ) . to . have . length ( 1 ) ;
55
+ expect ( $defaultValue . eq ( 0 ) ) . to . contain ( 'Purple' ) ;
56
+ } )
57
+ . get ( selector . multiSelectInput )
58
+ . type ( '{backspace}' , { force : true } )
59
+ . get ( selector . placeHolderMulti )
60
+ . should ( 'contain' , 'Select...' ) ;
61
+ }
62
+ ) ;
63
+
64
+ it (
65
+ 'Should select different options using - click and enter ' + view ,
66
+ ( ) => {
67
+ cy
68
+ . get ( selector . menuMulti )
69
+ . should ( 'not.exist' )
70
+ . get ( selector . toggleMenuMulti )
71
+ . click ( )
72
+ . get ( selector . menuMulti )
73
+ . should ( 'exist' )
74
+ . get ( selector . menuMulti )
75
+ . should ( 'be.visible' )
76
+ . get ( selector . menuOption )
77
+ . contains ( 'Orange' )
78
+ . click ( )
79
+ . get ( selector . toggleMenuMulti )
80
+ . click ( )
81
+ . get ( selector . menuOption )
82
+ . contains ( 'Yellow' )
83
+ . click ( )
84
+ . get ( selector . multiSelectInput )
85
+ . click ( { force : true } )
86
+ . type ( 'Slate' , { force : true } )
87
+ . type ( '{enter}' , { force : true } )
88
+ . get ( selector . multiSelectDefaultValues )
89
+ . then ( function ( $defaultValue ) {
90
+ expect ( $defaultValue ) . to . have . length ( 5 ) ;
91
+ expect ( $defaultValue . eq ( 0 ) ) . to . contain ( 'Purple' ) ;
92
+ expect ( $defaultValue . eq ( 1 ) ) . to . contain ( 'Red' ) ;
93
+ expect ( $defaultValue . eq ( 2 ) ) . to . contain ( 'Orange' ) ;
94
+ expect ( $defaultValue . eq ( 3 ) ) . to . contain ( 'Yellow' ) ;
95
+ expect ( $defaultValue . eq ( 4 ) ) . to . contain ( 'Slate' ) ;
96
+ } ) ;
97
+ } ) ;
98
+ } ) ;
99
+ } ) ;
0 commit comments