1+ import VueUiWaffle from './vue-ui-waffle.vue'
2+
3+
4+ describe ( '<VueUiWaffle />' , ( ) => {
5+ beforeEach ( function ( ) {
6+ cy . fixture ( 'waffle.json' ) . as ( 'fixture' ) ;
7+ cy . viewport ( 800 , 950 ) ;
8+ } ) ;
9+
10+ function updateConfigInFixture ( modifiedConfig ) {
11+ cy . get ( '@fixture' ) . then ( ( fixture ) => {
12+ const updatedFixture = { ...fixture , config : modifiedConfig } ;
13+ cy . wrap ( updatedFixture ) . as ( 'fixture' ) ;
14+ } ) ;
15+ }
16+
17+ it ( 'renders with different config attributes' , function ( ) {
18+ cy . get ( '@fixture' ) . then ( ( fixture ) => {
19+ cy . mount ( VueUiWaffle , {
20+ props : {
21+ dataset : fixture . dataset ,
22+ config : fixture . config
23+ }
24+ } ) ;
25+
26+ cy . get ( `[data-cy="waffle-svg"]` )
27+ . should ( 'exist' ) ;
28+
29+ const sortedDataset = JSON . parse ( JSON . stringify ( fixture . dataset ) ) . sort ( ( a , b ) => {
30+ const sumx = a . values . reduce ( ( x , y ) => x + y , 0 ) ;
31+ const sumy = b . values . reduce ( ( x , y ) => x + y , 0 ) ;
32+ return sumy - sumx
33+ } ) ;
34+
35+ const grandTotal = fixture . dataset . map ( ( d ) => d . values . reduce ( ( a , b ) => a + b , 0 ) ) . reduce ( ( a , b ) => a + b , 0 ) ;
36+
37+ cy . get ( `[data-cy="waffle-title"]` )
38+ . should ( 'exist' )
39+ . contains ( fixture . config . style . chart . title . text ) ;
40+
41+ cy . get ( `[data-cy="waffle-subtitle"]` )
42+ . should ( 'exist' )
43+ . contains ( fixture . config . style . chart . title . subtitle . text ) ;
44+
45+ for ( let i = 0 ; i < fixture . dataset . length ; i += 1 ) {
46+ const expectedValue = sortedDataset [ i ] . values . reduce ( ( a , b ) => a + b , 0 ) ;
47+ const expectedPercentage = ( expectedValue / grandTotal * 100 ) . toFixed ( fixture . config . style . chart . legend . roundingPercentage ) ;
48+
49+ cy . get ( `[data-cy="waffle-legend-item-${ i } "]` )
50+ . should ( 'exist' )
51+ . contains ( `${ sortedDataset [ i ] . name } : ${ expectedValue } (${ expectedPercentage } %)` )
52+ }
53+
54+ for ( let i = 0 ; i < Math . pow ( fixture . config . style . chart . layout . grid . size , 2 ) ; i += 1 ) {
55+ cy . get ( `[data-cy="waffle-rect-underlayer-${ i } "]` )
56+ . should ( 'exist' ) ;
57+ cy . get ( `[data-cy="waffle-rect-${ i } "]` )
58+ . should ( 'exist' ) ;
59+ }
60+
61+ cy . get ( `[data-cy="waffle-rect-0"]` )
62+ . trigger ( 'mouseover' ) ;
63+
64+ cy . get ( `[data-cy="waffle-tooltip"]` ) . then ( ( $tooltip ) => {
65+
66+ const expectedValue = sortedDataset [ 0 ] . values . reduce ( ( a , b ) => a + b , 0 ) ;
67+ const expectedPercentage = ( expectedValue / grandTotal * 100 ) . toFixed ( fixture . config . style . chart . legend . roundingPercentage ) ;
68+
69+ cy . wrap ( $tooltip )
70+ . should ( 'exist' )
71+
72+ cy . get ( `[data-cy="waffle-tooltip-name"]` )
73+ . should ( 'exist' )
74+ . contains ( sortedDataset [ 0 ] . name )
75+
76+ cy . get ( `[data-cy="waffle-tooltip-marker"]` ) . then ( ( $marker ) => {
77+ cy . wrap ( $marker )
78+ . should ( 'exist' )
79+ . invoke ( 'attr' , 'fill' )
80+ . should ( 'eq' , sortedDataset [ 0 ] . color )
81+ } ) ;
82+
83+ cy . get ( `[data-cy="waffle-tooltip-value"]` )
84+ . should ( 'exist' )
85+ . contains ( expectedValue )
86+
87+ cy . get ( `[data-cy="waffle-tooltip-percentage"]` )
88+ . should ( 'exist' )
89+ . contains ( `(${ expectedPercentage } %)` )
90+ } ) ;
91+
92+ cy . get ( `[data-cy="waffle-rect-0"]` )
93+ . trigger ( 'mouseleave' ) ;
94+
95+ cy . get ( `[data-cy="waffle-summary"]` )
96+ . click ( ) ;
97+
98+ cy . get ( `[data-cy="waffle-checkbox-title"]` ) . then ( ( $checkbox ) => {
99+ cy . wrap ( $checkbox )
100+ . check ( ) ;
101+
102+ cy . get ( `[data-cy="waffle-text-title"]` )
103+ . should ( 'exist' )
104+ . contains ( fixture . config . style . chart . title . text ) ;
105+
106+ cy . get ( `[data-cy="waffle-text-subtitle"]` )
107+ . should ( 'exist' )
108+ . contains ( fixture . config . style . chart . title . subtitle . text ) ;
109+
110+ for ( let i = 0 ; i < fixture . dataset . length ; i += 1 ) {
111+ const expectedValue = sortedDataset [ i ] . values . reduce ( ( a , b ) => a + b , 0 ) ;
112+ const expectedPercentage = ( expectedValue / grandTotal * 100 ) . toFixed ( fixture . config . style . chart . legend . roundingPercentage ) ;
113+
114+ cy . get ( `[data-cy="waffle-foreginObject-legend-item-${ i } "]` )
115+ . should ( 'exist' )
116+ . contains ( `${ sortedDataset [ i ] . name } : ${ expectedValue } (${ expectedPercentage } %)` )
117+ }
118+
119+ cy . wrap ( $checkbox )
120+ . uncheck ( )
121+ } ) ;
122+
123+ cy . get ( `[data-cy="waffle-checkbox-table"]` ) . then ( ( $checkbox ) => {
124+ cy . wrap ( $checkbox )
125+ . check ( ) ;
126+
127+ cy . viewport ( 800 , 1100 ) ;
128+
129+ cy . get ( `[data-cy="waffle-table-title"]` )
130+ . should ( 'exist' )
131+ . contains ( `${ fixture . config . style . chart . title . text } : ${ fixture . config . style . chart . title . subtitle . text } ` ) ;
132+
133+ for ( let i = 0 ; i < fixture . dataset . length ; i += 1 ) {
134+ const expectedValue = sortedDataset [ i ] . values . reduce ( ( a , b ) => a + b , 0 ) ;
135+ const expectedPercentage = `${ ( expectedValue / grandTotal * 100 ) . toFixed ( fixture . config . style . chart . legend . roundingPercentage ) } %` ;
136+
137+ cy . get ( `[data-cy="waffle-table-tr-${ i } "]` ) . then ( ( $tr ) => {
138+ cy . wrap ( $tr )
139+ . should ( 'exist' ) ;
140+
141+ cy . wrap ( $tr )
142+ . find ( 'td' )
143+ . should ( 'have.length' , 3 )
144+ . each ( ( $td , index ) => {
145+ if ( index === 0 ) {
146+ cy . wrap ( $td )
147+ . should ( 'contain.text' , `◼${ sortedDataset [ i ] . name } ` )
148+ }
149+ if ( index === 1 ) {
150+ cy . wrap ( $td )
151+ . should ( 'contain.text' , expectedValue )
152+ }
153+ if ( index === 2 ) {
154+ cy . wrap ( $td )
155+ . should ( 'contain.text' , expectedPercentage )
156+ }
157+ } ) ;
158+ } ) ;
159+ }
160+ } )
161+
162+ cy . get ( `[data-cy="waffle-pdf"]` ) . click ( ) ;
163+ cy . wait ( 5000 ) ;
164+ cy . readFile ( `cypress\\Downloads\\${ fixture . config . style . chart . title . text } .pdf` ) ;
165+ cy . get ( `[data-cy="waffle-xls"]` ) . click ( ) ;
166+ cy . wait ( 3000 ) ;
167+ cy . readFile ( `cypress\\Downloads\\${ fixture . config . style . chart . title . text } .xlsx` ) ;
168+ cy . clearDownloads ( ) ;
169+ } ) ;
170+ } ) ;
171+ } )
0 commit comments