33import * as fs from 'fs' ;
44import * as path from 'path' ;
55import { getNarrowModeThresholdsForUnified } from 'electron/common/narrow-mode-thresholds' ;
6+ import { UnifiedFeatureFlags } from 'electron/common/unified-feature-flags' ;
67import { androidTestConfigs } from 'electron/platform/android/test-configs/android-test-configs' ;
78import { createApplication } from 'tests/electron/common/create-application' ;
89import { ResultsViewSelectors } from 'tests/electron/common/element-identifiers/results-view-selectors' ;
@@ -26,8 +27,6 @@ describe('ResultsView', () => {
2627 'beforeEach' ,
2728 ) ;
2829 app = await createApplication ( { suppressFirstTimeDialog : true } ) ;
29- resultsView = await app . openResultsView ( ) ;
30- await resultsView . waitForScreenshotViewVisible ( ) ;
3130 } ) ;
3231
3332 afterEach ( async ( ) => {
@@ -37,6 +36,8 @@ describe('ResultsView', () => {
3736 } ) ;
3837
3938 it ( 'should pass accessibility validation when left nav is showing' , async ( ) => {
39+ await openResultsView ( ) ;
40+
4041 await app . client . browserWindow . setSize (
4142 narrowModeThresholds . collapseCommandBarThreshold + 1 ,
4243 height ,
@@ -51,6 +52,8 @@ describe('ResultsView', () => {
5152 config => config . featureFlag === undefined ,
5253 ) [ testIndex ] . contentPageInfo . title ;
5354
55+ await openResultsView ( ) ;
56+
5457 await app . client . browserWindow . setSize (
5558 narrowModeThresholds . collapseCommandBarThreshold + 1 ,
5659 height ,
@@ -62,10 +65,14 @@ describe('ResultsView', () => {
6265 } ) ;
6366
6467 it ( 'should pass accessibility validation in all contrast modes' , async ( ) => {
68+ await openResultsView ( ) ;
6569 await scanForAccessibilityIssuesInAllModes ( app ) ;
6670 } ) ;
6771
68- it ( 'ScreenshotView renders screenshot image from specified source' , async ( ) => {
72+ it ( 'ScreenshotView renders screenshot image from specified source for v1 results' , async ( ) => {
73+ app . setFeatureFlag ( UnifiedFeatureFlags . atfaResults , false ) ;
74+ await openResultsView ( ) ;
75+
6976 const resultExamplePath = path . join (
7077 testResourceServerConfig . absolutePath ,
7178 'AccessibilityInsights/result.json' ,
@@ -85,7 +92,33 @@ describe('ResultsView', () => {
8592 expect ( actualScreenshotImage ) . toEqual ( expectedScreenshotImage ) ;
8693 } ) ;
8794
88- it ( 'ScreenshotView renders expected number/size of highlight boxes in expected positions' , async ( ) => {
95+ it ( 'ScreenshotView renders screenshot image from specified source for results_v2' , async ( ) => {
96+ app . setFeatureFlag ( UnifiedFeatureFlags . atfaResults , true ) ;
97+ await openResultsView ( ) ;
98+
99+ const resultExamplePath = path . join (
100+ testResourceServerConfig . absolutePath ,
101+ 'AccessibilityInsights/result_v2.json' ,
102+ ) ;
103+ const axeRuleResultExample = JSON . parse (
104+ fs . readFileSync ( resultExamplePath , { encoding : 'utf-8' } ) ,
105+ ) ;
106+ const expectedScreenshotImage =
107+ 'data:image/png;base64,' + axeRuleResultExample . AxeResults . axeContext . screenshot ;
108+
109+ await resultsView . waitForSelector ( ScreenshotViewSelectors . screenshotImage ) ;
110+ const actualScreenshotImage = await resultsView . client . getAttribute (
111+ ScreenshotViewSelectors . screenshotImage ,
112+ 'src' ,
113+ ) ;
114+
115+ expect ( actualScreenshotImage ) . toEqual ( expectedScreenshotImage ) ;
116+ } ) ;
117+
118+ it ( 'ScreenshotView renders expected number/size of highlight boxes in expected positions for v1 results' , async ( ) => {
119+ app . setFeatureFlag ( UnifiedFeatureFlags . atfaResults , false ) ;
120+ await openResultsView ( ) ;
121+
89122 await resultsView . waitForSelector ( ScreenshotViewSelectors . highlightBox ) ;
90123
91124 const boxes = await resultsView . client . $$ ( ScreenshotViewSelectors . highlightBox ) ;
@@ -99,6 +132,22 @@ describe('ResultsView', () => {
99132 ] ) ;
100133 } ) ;
101134
135+ it ( 'ScreenshotView renders expected number/size of highlight boxes in expected positions for results_v2' , async ( ) => {
136+ app . setFeatureFlag ( UnifiedFeatureFlags . atfaResults , true ) ;
137+ await openResultsView ( ) ;
138+
139+ await resultsView . waitForSelector ( ScreenshotViewSelectors . highlightBox ) ;
140+
141+ const boxes = await resultsView . client . $$ ( ScreenshotViewSelectors . highlightBox ) ;
142+ const styles = await Promise . all ( boxes . map ( async b => await b . getAttribute ( 'style' ) ) ) ;
143+ const actualHighlightBoxStyles = styles . map ( extractPositionStyles ) ;
144+ verifyHighlightBoxStyles ( actualHighlightBoxStyles , [
145+ { width : 73.6111 , height : 3.42593 , top : 38.7037 , left : 13.1481 } ,
146+ { width : 73.6111 , height : 3.42593 , top : 38.7037 , left : 13.1481 } ,
147+ { width : 100 , height : 35.4167 , top : 42.1296 , left : 0 } ,
148+ ] ) ;
149+ } ) ;
150+
102151 type PositionStyles = {
103152 width : number ;
104153 height : number ;
@@ -144,6 +193,7 @@ describe('ResultsView', () => {
144193 } ;
145194
146195 it ( 'command bar reflows when narrow mode threshold is crossed' , async ( ) => {
196+ await openResultsView ( ) ;
147197 await setupWindowForCommandBarReflowTest ( 'narrow' ) ;
148198 await resultsView . waitForSelector ( ResultsViewSelectors . leftNavHamburgerButton ) ;
149199
@@ -156,6 +206,7 @@ describe('ResultsView', () => {
156206 } ;
157207
158208 it ( 'hamburger button click opens and closes left nav' , async ( ) => {
209+ await openResultsView ( ) ;
159210 await setupWindowForCommandBarReflowTest ( 'narrow' ) ;
160211 await waitForFluentLeftNavToDisappear ( ) ;
161212 await resultsView . client . click ( ResultsViewSelectors . leftNavHamburgerButton ) ;
@@ -168,6 +219,7 @@ describe('ResultsView', () => {
168219 } ) ;
169220
170221 it ( 'left nav closes when item is selected' , async ( ) => {
222+ await openResultsView ( ) ;
171223 await setupWindowForCommandBarReflowTest ( 'narrow' ) ;
172224 await resultsView . client . click ( ResultsViewSelectors . leftNavHamburgerButton ) ;
173225 await resultsView . waitForSelector ( ResultsViewSelectors . fluentLeftNav ) ;
@@ -178,7 +230,13 @@ describe('ResultsView', () => {
178230 } ) ;
179231
180232 it ( 'export report button exists' , async ( ) => {
233+ await openResultsView ( ) ;
181234 await setupWindowForCommandBarReflowTest ( 'wide' ) ;
182235 await resultsView . waitForSelector ( ResultsViewSelectors . exportReportButton ) ;
183236 } ) ;
237+
238+ async function openResultsView ( ) : Promise < void > {
239+ resultsView = await app . openResultsView ( ) ;
240+ await resultsView . waitForScreenshotViewVisible ( ) ;
241+ }
184242} ) ;
0 commit comments