Skip to content

Commit e601525

Browse files
authored
feat(google-rules-mvp): unified e2e tests v2 results (#4432)
Details Adding E2E tests for when the ATFA results feature flag is on, because the results_v2 are different. Motivation Adding/updating E2E tests to use the feature flag Context #4431 added the results_v2.json that is used for the added tests
1 parent 7304dd2 commit e601525

File tree

3 files changed

+133
-12
lines changed

3 files changed

+133
-12
lines changed

src/tests/electron/tests/automated-checks-view.test.ts

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33
import * as path from 'path';
4+
import { UnifiedFeatureFlags } from 'electron/common/unified-feature-flags';
45
import { createApplication } from 'tests/electron/common/create-application';
56
import { scanForAccessibilityIssuesInAllModes } from 'tests/electron/common/scan-for-accessibility-issues';
67
import { AppController } from 'tests/electron/common/view-controllers/app-controller';
@@ -18,9 +19,6 @@ describe('AutomatedChecksView', () => {
1819
'beforeEach',
1920
);
2021
app = await createApplication({ suppressFirstTimeDialog: true });
21-
const resultsView = await app.openResultsView();
22-
await resultsView.waitForScreenshotViewVisible();
23-
cardsView = resultsView.createCardsViewController();
2422
});
2523

2624
afterEach(async () => {
@@ -30,17 +28,22 @@ describe('AutomatedChecksView', () => {
3028
});
3129

3230
it('should use the expected window title', async () => {
31+
await openResultsAndCardsViews();
3332
await app.waitForTitle('Accessibility Insights for Android - Automated checks');
3433
});
3534

3635
it('displays automated checks results collapsed by default', async () => {
36+
await openResultsAndCardsViews();
3737
await cardsView.waitForRuleGroupCount(3);
3838

3939
const collapsibleContentElements = await cardsView.queryRuleGroupContents();
4040
expect(collapsibleContentElements).toHaveLength(0);
4141
});
4242

43-
it('supports expanding and collapsing rule groups', async () => {
43+
it('supports expanding and collapsing rule groups with results (v1)', async () => {
44+
app.setFeatureFlag(UnifiedFeatureFlags.atfaResults, false);
45+
await openResultsAndCardsViews();
46+
4447
await cardsView.waitForHighlightBoxCount(4);
4548
expect(await cardsView.queryRuleGroupContents()).toHaveLength(0);
4649

@@ -67,7 +70,44 @@ describe('AutomatedChecksView', () => {
6770
await cardsView.assertExpandedRuleGroup(3, 'TouchSizeWcag', 1);
6871
});
6972

70-
it('should pass accessibility rvalidation in all contrast modes', async () => {
73+
it('supports expanding and collapsing rule groups with results_v2', async () => {
74+
app.setFeatureFlag(UnifiedFeatureFlags.atfaResults, true);
75+
await openResultsAndCardsViews();
76+
77+
await cardsView.waitForHighlightBoxCount(3);
78+
expect(await cardsView.queryRuleGroupContents()).toHaveLength(0);
79+
80+
await cardsView.toggleRuleGroupAtPosition(1);
81+
await cardsView.assertExpandedRuleGroup(1, 'EditTextValue', 1);
82+
83+
await cardsView.toggleRuleGroupAtPosition(2);
84+
await cardsView.assertExpandedRuleGroup(2, 'TouchSizeWcag', 1);
85+
86+
await cardsView.toggleRuleGroupAtPosition(3);
87+
await cardsView.assertExpandedRuleGroup(3, 'ImageViewName', 1);
88+
89+
await cardsView.waitForHighlightBoxCount(3);
90+
expect(await cardsView.queryRuleGroupContents()).toHaveLength(3);
91+
92+
await cardsView.toggleRuleGroupAtPosition(1);
93+
await cardsView.assertCollapsedRuleGroup(1, 'EditTextValue');
94+
95+
await cardsView.toggleRuleGroupAtPosition(2);
96+
await cardsView.assertCollapsedRuleGroup(2, 'TouchSizeWcag');
97+
98+
await cardsView.waitForHighlightBoxCount(1);
99+
expect(await cardsView.queryRuleGroupContents()).toHaveLength(1);
100+
await cardsView.assertExpandedRuleGroup(3, 'ImageViewName', 1);
101+
});
102+
103+
it('should pass accessibility validation in all contrast modes', async () => {
104+
await openResultsAndCardsViews();
71105
await scanForAccessibilityIssuesInAllModes(app);
72106
});
107+
108+
async function openResultsAndCardsViews(): Promise<void> {
109+
const resultsView = await app.openResultsView();
110+
await resultsView.waitForScreenshotViewVisible();
111+
cardsView = resultsView.createCardsViewController();
112+
}
73113
});

src/tests/electron/tests/needs-review-view.test.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33
import * as path from 'path';
44
import { getNarrowModeThresholdsForUnified } from 'electron/common/narrow-mode-thresholds';
5+
import { UnifiedFeatureFlags } from 'electron/common/unified-feature-flags';
56
import { createApplication } from 'tests/electron/common/create-application';
67
import { ResultsViewSelectors } from 'tests/electron/common/element-identifiers/results-view-selectors';
78
import { scanForAccessibilityIssuesInAllModes } from 'tests/electron/common/scan-for-accessibility-issues';
@@ -24,8 +25,6 @@ describe('NeedsReviewView', () => {
2425

2526
app = await createApplication({ suppressFirstTimeDialog: true });
2627
app.client.browserWindow.setSize(windowWidth, windowHeight);
27-
resultsViewController = await app.openResultsView();
28-
await resultsViewController.clickLeftNavItem('needs-review');
2928
});
3029

3130
afterEach(async () => {
@@ -35,10 +34,13 @@ describe('NeedsReviewView', () => {
3534
});
3635

3736
it('should use the expected window title', async () => {
37+
await openNeedsReview();
3838
await app.waitForTitle('Accessibility Insights for Android - Needs review');
3939
});
4040

41-
it('displays needs review results with one failing result', async () => {
41+
it('displays needs review results with one failing result (results v1)', async () => {
42+
app.setFeatureFlag(UnifiedFeatureFlags.atfaResults, false);
43+
await openNeedsReview();
4244
const cardsView = resultsViewController.createCardsViewController();
4345
await cardsView.waitForRuleGroupCount(1);
4446
expect(await cardsView.queryRuleGroupContents()).toHaveLength(0);
@@ -50,13 +52,34 @@ describe('NeedsReviewView', () => {
5052
expect(await cardsView.queryRuleGroupContents()).toHaveLength(1);
5153
});
5254

55+
it('displays needs review results with 5 failing results (results_v2)', async () => {
56+
app.setFeatureFlag(UnifiedFeatureFlags.atfaResults, true);
57+
await openNeedsReview();
58+
const cardsView = resultsViewController.createCardsViewController();
59+
await cardsView.waitForRuleGroupCount(1);
60+
expect(await cardsView.queryRuleGroupContents()).toHaveLength(0);
61+
await cardsView.waitForHighlightBoxCount(5);
62+
63+
await cardsView.toggleRuleGroupAtPosition(1);
64+
await cardsView.assertExpandedRuleGroup(1, 'TextContrastCheck', 5);
65+
66+
expect(await cardsView.queryRuleGroupContents()).toHaveLength(1);
67+
});
68+
5369
it('should pass accessibility validation in all contrast modes', async () => {
70+
await openNeedsReview();
5471
await scanForAccessibilityIssuesInAllModes(app);
5572
});
5673

5774
it('export report button does not exist', async () => {
75+
await openNeedsReview();
5876
await resultsViewController.waitForSelectorToDisappear(
5977
ResultsViewSelectors.exportReportButton,
6078
);
6179
});
80+
81+
async function openNeedsReview(): Promise<void> {
82+
resultsViewController = await app.openResultsView();
83+
await resultsViewController.clickLeftNavItem('needs-review');
84+
}
6285
});

src/tests/electron/tests/results-view.test.ts

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as fs from 'fs';
44
import * as path from 'path';
55
import { getNarrowModeThresholdsForUnified } from 'electron/common/narrow-mode-thresholds';
6+
import { UnifiedFeatureFlags } from 'electron/common/unified-feature-flags';
67
import { androidTestConfigs } from 'electron/platform/android/test-configs/android-test-configs';
78
import { createApplication } from 'tests/electron/common/create-application';
89
import { 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

Comments
 (0)