@@ -7,46 +7,32 @@ let urlTestIndex = urlParams.get("testIndex");
77let urlVizzuUrl = urlParams . get ( "vizzuUrl" ) ;
88let urlVizzuRefUrl = urlParams . get ( "vizzuRefUrl" ) ;
99
10- let vizzuUrl = document . getElementById ( " vizzuUrl") ;
11- let vizzuRef = document . getElementById ( " vizzuRef") ;
12- let testCase = document . getElementById ( " testCase") ;
13- let frame = document . getElementById ( " frame") ;
14- let frameRef = document . getElementById ( " frame-ref") ;
15- let difCanvas = document . getElementById ( " canvas-dif") ;
16- let replay = document . getElementById ( " replay") ;
17- let play = document . getElementById ( " play") ;
10+ let vizzuUrl = document . querySelector ( "# vizzuUrl") ;
11+ let vizzuRef = document . querySelector ( "# vizzuRef") ;
12+ let testCase = document . querySelector ( "# testCase") ;
13+ let frame = document . querySelector ( "# frame") ;
14+ let frameRef = document . querySelector ( "# frame-ref") ;
15+ let difCanvas = document . querySelector ( "# canvas-dif") ;
16+ let replay = document . querySelector ( "# replay") ;
17+ let play = document . querySelector ( "# play") ;
1818
1919function getDiff ( ) {
2020 let doc = frame . contentWindow . document ;
2121 let docRef = frameRef . contentWindow . document ;
22- if (
23- doc . vizzuImgData !== undefined &&
24- docRef . vizzuImgData !== undefined &&
25- doc . vizzuImgIndex == docRef . vizzuImgIndex
26- ) {
27- let w = doc . vizzuImgData . width ;
28- let h = doc . vizzuImgData . height ;
29- let res = ImgDiff . compare (
30- "move" ,
31- doc . vizzuImgData . data ,
32- docRef . vizzuImgData . data ,
33- w ,
34- h
35- ) ;
22+ if ( doc . vizzuImgData && docRef . vizzuImgData && doc . vizzuImgIndex === docRef . vizzuImgIndex ) {
23+ let { width : w , height : h , data } = doc . vizzuImgData ;
24+ let res = ImgDiff . compare ( "move" , data , docRef . vizzuImgData . data , w , h ) ;
3625
3726 let dif = new ImageData ( res . diffData , w , h ) ;
3827 difCanvas . width = 800 ;
3928 difCanvas . height = 500 ;
4029 const ctx = difCanvas . getContext ( "2d" ) ;
4130 ctx . clearRect ( 0 , 0 , w , h ) ;
4231 ctx . putImageData ( dif , 0 , 0 ) ;
43- doc . vizzuImgData = undefined ;
44- docRef . vizzuImgData = undefined ;
45- difCanvas . style = `border:1px solid ${ res . match ? "green" : "red" } ` ;
46- setTimeout ( getDiff , 100 ) ;
47- } else {
48- setTimeout ( getDiff , 100 ) ;
32+ doc . vizzuImgData = docRef . vizzuImgData = undefined ;
33+ difCanvas . style . border = `1px solid ${ res . match ? "green" : "red" } ` ;
4934 }
35+ setTimeout ( getDiff , 100 ) ;
5036}
5137
5238function update ( ) {
@@ -69,6 +55,10 @@ function update() {
6955 run ( charts ) ;
7056 } , 0 ) ;
7157 } ) ;
58+
59+ testCase . querySelectorAll ( "option" ) . forEach ( ( option ) => {
60+ option . style . backgroundColor = option . selected ? "rgba(206,206,206,255)" : option . getAttribute ( "background-color" ) ;
61+ } ) ;
7262}
7363
7464function connectSliders ( ) {
@@ -122,37 +112,20 @@ function setupSelects() {
122112 vizzuRef . addEventListener ( "change" , update ) ;
123113 testCase . addEventListener ( "change" , update ) ;
124114 replay . addEventListener ( "click" , update ) ;
125- play . addEventListener ( "click" , ( ) => {
126- run ( [ undefined , undefined ] ) ;
127- } ) ;
115+ play . addEventListener ( "click" , ( ) => run ( [ undefined , undefined ] ) ) ;
128116}
129117
130118function populateLibs ( ) {
131119 fetch ( "/getLibList" )
132120 . then ( ( response ) => response . json ( ) )
133121 . then ( ( data ) => {
134- for ( let name in data ) {
135- let url = data [ name ] ;
122+ Object . entries ( data ) . forEach ( ( [ name , url ] ) => {
136123 vizzuUrl . appendChild ( getVizzuOption ( url , name ) ) ;
137124 vizzuRef . appendChild ( getVizzuOption ( url , name ) ) ;
138- }
139- let lastSelected = localStorage . getItem ( "vizzuUrl" ) ;
140- if ( urlVizzuUrl ) {
141- lastSelected = data [ urlVizzuUrl ] ;
142- }
143- if ( ! lastSelected ) lastSelected = data [ "localhost" ] ;
125+ } ) ;
126+ let lastSelected = data [ urlVizzuUrl ] || localStorage . getItem ( "vizzuUrl" ) || data [ "localhost" ] ;
144127 vizzuUrl . value = lastSelected ;
145- let lastSelectedRef = localStorage . getItem ( "vizzuRef" ) ;
146- if ( urlVizzuRefUrl ) {
147- lastSelectedRef = data [ urlVizzuRefUrl ] ;
148- }
149- if ( ! lastSelectedRef ) {
150- if ( data [ "HEAD" ] ) {
151- lastSelectedRef = data [ "HEAD" ] ;
152- } else {
153- lastSelectedRef = data [ "localhost" ] ;
154- }
155- }
128+ let lastSelectedRef = data [ urlVizzuRefUrl ] || localStorage . getItem ( "vizzuRef" ) || data [ "HEAD" ] || data [ "localhost" ] ;
156129 vizzuRef . value = lastSelectedRef ;
157130 populateCases ( ) ;
158131 } ) ;
@@ -163,19 +136,19 @@ function getVizzuOption(url, name) {
163136 option . value = url ;
164137 const text = document . createTextNode ( name ) ;
165138 option . appendChild ( text ) ;
166- return option
139+ return option ;
167140}
168141
169142function populateCases ( ) {
170143 fetch ( "/getTestList" )
171144 . then ( ( response ) => response . json ( ) )
172145 . then ( ( data ) => {
173- let lastSelected = "" ;
146+ let lastSelected = localStorage . getItem ( "testCase" ) ;
174147 for ( let i = 0 ; i < data . length ; i ++ ) {
175148 let actcase = JSON . stringify ( data [ i ] ) ;
176149 if (
177150 data [ i ] . testFile === urlTestFile &&
178- data [ i ] . testIndex === urlTestIndex
151+ data [ i ] . testIndex == urlTestIndex
179152 ) {
180153 lastSelected = actcase ;
181154 }
@@ -184,7 +157,7 @@ function populateCases() {
184157 let selected = i == 0 ? 'selected="selected"' : "" ;
185158 testCase . appendChild ( getTestCaseOption ( actcase , actcaseName , actcaseResult , selected ) ) ;
186159 }
187- if ( lastSelected === "" ) lastSelected = JSON . stringify ( data [ 0 ] ) ;
160+ if ( ! lastSelected ) lastSelected = JSON . stringify ( data [ 0 ] ) ;
188161 testCase . value = lastSelected ;
189162
190163 setupSelects ( ) ;
@@ -193,26 +166,23 @@ function populateCases() {
193166}
194167
195168function getTestCaseOption ( testCase , testCaseName , testCaseResult , selected ) {
196- const option = document . createElement ( 'option' ) ;
197- option . setAttribute ( 'style' , getTestCaseStyle ( testCaseResult ) ) ;
169+ const option = document . createElement ( "option" ) ;
198170 option . value = testCase ;
199171 option . selected = selected ;
200- let textValue = testCaseName ;
201- if ( testCaseResult ) textValue = `${ testCaseName } | ${ testCaseResult } ` ;
202- const text = document . createTextNode ( textValue ) ;
203- option . appendChild ( text ) ;
172+ option . textContent = testCaseResult ? `${ testCaseName } | ${ testCaseResult } ` : testCaseName ;
173+ option . setAttribute ( "background-color" , getTestCaseBackgroundColorByResult ( testCaseResult ) ) ;
204174 return option ;
205175}
206176
207- function getTestCaseStyle ( testCaseResult ) {
177+ function getTestCaseBackgroundColorByResult ( testCaseResult ) {
208178 if ( testCaseResult === "PASS" ) {
209- return "background-color: rgba(152, 251, 152, 0.8) !important; " ;
179+ return "rgba(152,251,152,0.8)" ;
210180 } else if ( testCaseResult === "FAIL" ) {
211- return "background-color: rgba(255, 153, 153, 0.8) !important; " ;
181+ return "rgba(255,153,153,0.8)" ;
212182 } else if ( testCaseResult === "WARN" ) {
213- return "background-color: rgba(255, 255, 153, 0.8) !important; " ;
183+ return "rgba(255,255,153,0.8)" ;
214184 }
215- return ";"
185+ return "" ;
216186}
217187
218188populateLibs ( ) ;
0 commit comments