From dbc38114c339830eb4e971487a568d137f527ff0 Mon Sep 17 00:00:00 2001 From: lisli1 <48259897+lisli1@users.noreply.github.com> Date: Fri, 2 Dec 2022 11:00:50 -0800 Subject: [PATCH] feat(medium-pass-1): register MediumPass callbacks in ActionCreator (#6227) #### Details This PR ensures that the MediumPass/QuickAssess equivalents of Assessment callbacks are registered in ActionCreator ##### Motivation Part of feature work ##### Context #### Pull request checklist - [n/a] Addresses an existing issue: #0000 - [x] Ran `yarn null:autoadd` - [x] Ran `yarn fastpass` - [x] Added/updated relevant unit test(s) (and ran `yarn test`) - [x] Verified code coverage for the changes made. Check coverage report at: `/test-results/unit/coverage` - [x] PR title *AND* final merge commit title both start with a semantic tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See `CONTRIBUTING.md`. - [n/a] (UI changes only) Added screenshots/GIFs to description above - [n/a] (UI changes only) Verified usability with NVDA/JAWS --- src/background/actions/action-creator.ts | 102 ++++- .../background/actions/action-creator.test.ts | 368 ++++++++++-------- 2 files changed, 304 insertions(+), 166 deletions(-) diff --git a/src/background/actions/action-creator.ts b/src/background/actions/action-creator.ts index 7c8ec0e2d51..440ba2d6e42 100644 --- a/src/background/actions/action-creator.ts +++ b/src/background/actions/action-creator.ts @@ -135,7 +135,7 @@ export class ActionCreator { ); this.interpreter.registerTypeToPayloadCallback( Messages.Assessment.AssessmentScanCompleted, - this.onAssessmentScanCompleted, + this.onAssessmentScanCompletedForAssessment, ); this.interpreter.registerTypeToPayloadCallback( Messages.Assessment.StartOverTest, @@ -147,11 +147,11 @@ export class ActionCreator { ); this.interpreter.registerTypeToPayloadCallback( Messages.Assessment.StartOverAllAssessments, - this.onStartOverAllAssessments, + this.onStartOverAllAssessmentsForAssessment, ); this.interpreter.registerTypeToPayloadCallback( Messages.Assessment.CancelStartOverAllAssessments, - this.onCancelStartOverAllAssessments, + this.onCancelStartOverAllAssessmentsForAssessment, ); this.interpreter.registerTypeToPayloadCallback( Messages.Assessment.EnableVisualHelper, @@ -170,6 +170,43 @@ export class ActionCreator { this.onEnableVisualHelperWithoutScan, ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.AssessmentScanCompleted, + this.onAssessmentScanCompletedForQuickAssess, + ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.StartOverTest, + this.onStartOver, + ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.CancelStartOver, + this.onCancelStartOver, + ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.StartOverAllAssessments, + this.onStartOverAllAssessmentsForQuickAssess, + ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.CancelStartOverAllAssessments, + this.onCancelStartOverAllAssessmentsForQuickAssess, + ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.EnableVisualHelper, + this.onEnableVisualHelper, + ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.DisableVisualHelperForTest, + this.onDisableVisualHelpersForTest, + ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.DisableVisualHelper, + this.onDisableVisualHelper, + ); + this.interpreter.registerTypeToPayloadCallback( + Messages.MediumPass.EnableVisualHelperWithoutScan, + this.onEnableVisualHelperWithoutScan, + ); + this.interpreter.registerTypeToPayloadCallback( Messages.Inspect.SetHoveredOverSelector, this.onSetHoveredOverSelector, @@ -219,8 +256,10 @@ export class ActionCreator { this.telemetryEventHandler.publishTelemetry(eventName, payload); }; - private onStartOverAllAssessments = async (payload: ToggleActionPayload): Promise => { - const eventName = TelemetryEvents.START_OVER_ASSESSMENT; + private onStartOverAllAssessments = async ( + payload: ToggleActionPayload, + eventName: string, + ): Promise => { this.telemetryEventHandler.publishTelemetry(eventName, payload); await this.visualizationActions.disableAssessmentVisualizations.invoke( null, @@ -228,11 +267,36 @@ export class ActionCreator { ); }; - private onCancelStartOverAllAssessments = (payload: BaseActionPayload): void => { - const eventName = TelemetryEvents.CANCEL_START_OVER_ASSESSMENT; + private onStartOverAllAssessmentsForAssessment = async ( + payload: ToggleActionPayload, + ): Promise => { + await this.onStartOverAllAssessments(payload, TelemetryEvents.START_OVER_ASSESSMENT); + }; + + private onStartOverAllAssessmentsForQuickAssess = async ( + payload: ToggleActionPayload, + ): Promise => { + await this.onStartOverAllAssessments(payload, TelemetryEvents.START_OVER_MEDIUM_PASS); + }; + + private onCancelStartOverAllAssessments = ( + payload: BaseActionPayload, + eventName: string, + ): void => { this.telemetryEventHandler.publishTelemetry(eventName, payload); }; + private onCancelStartOverAllAssessmentsForAssessment = (payload: BaseActionPayload): void => { + this.onCancelStartOverAllAssessments(payload, TelemetryEvents.CANCEL_START_OVER_ASSESSMENT); + }; + + private onCancelStartOverAllAssessmentsForQuickAssess = (payload: BaseActionPayload): void => { + this.onCancelStartOverAllAssessments( + payload, + TelemetryEvents.CANCEL_START_OVER_MEDIUM_PASS, + ); + }; + private onDetailsViewClosed = async (): Promise => { await this.visualizationActions.disableAssessmentVisualizations.invoke( null, @@ -243,8 +307,8 @@ export class ActionCreator { private onAssessmentScanCompleted = async ( payload: ScanCompletedPayload, tabId: number, + eventName: string, ): Promise => { - const eventName = TelemetryEvents.ASSESSMENT_SCAN_COMPLETED; this.telemetryEventHandler.publishTelemetry(eventName, payload); await this.visualizationActions.scanCompleted.invoke(null, this.executingScope); this.notificationCreator.createNotificationByVisualizationKey( @@ -256,6 +320,28 @@ export class ActionCreator { await this.targetTabController.showTargetTab(tabId, payload.testType, payload.key); }; + private onAssessmentScanCompletedForAssessment = async ( + payload: ScanCompletedPayload, + tabId: number, + ): Promise => { + await this.onAssessmentScanCompleted( + payload, + tabId, + TelemetryEvents.ASSESSMENT_SCAN_COMPLETED, + ); + }; + + private onAssessmentScanCompletedForQuickAssess = async ( + payload: ScanCompletedPayload, + tabId: number, + ): Promise => { + await this.onAssessmentScanCompleted( + payload, + tabId, + TelemetryEvents.MEDIUM_PASS_SCAN_COMPLETED, + ); + }; + private onTabbedElementAdded = async (payload: AddTabbedElementPayload): Promise => { await this.visualizationScanResultActions.addTabbedElement.invoke( payload, diff --git a/src/tests/unit/tests/background/actions/action-creator.test.ts b/src/tests/unit/tests/background/actions/action-creator.test.ts index ad206dc1545..b55e2493160 100644 --- a/src/tests/unit/tests/background/actions/action-creator.test.ts +++ b/src/tests/unit/tests/background/actions/action-creator.test.ts @@ -611,135 +611,167 @@ describe('ActionCreatorTest', () => { validator.verifyAll(); }); - test('registerCallback for onAssessmentScanCompleted', async () => { - const tabId = -1; - const telemetryData: BaseTelemetryData = { - triggeredBy: 'stub triggered by' as TriggeredBy, - source: testSource, - }; + describe('onAssessmentScanCompleted', () => { + const testCases = [ + [ + Messages.Assessment.AssessmentScanCompleted, + TelemetryEvents.ASSESSMENT_SCAN_COMPLETED, + ], + [ + Messages.MediumPass.AssessmentScanCompleted, + TelemetryEvents.MEDIUM_PASS_SCAN_COMPLETED, + ], + ]; - const payload: ScanCompletedPayload = { - telemetry: telemetryData, - selectorMap: {}, - scanResult: null, - testType: VisualizationType.HeadingsAssessment, - key: 'key', - scanIncompleteWarnings: [], - }; + test.each(testCases)('registerCallback with %s', async (eventName, telemetryEvent) => { + const tabId = -1; + const telemetryData: BaseTelemetryData = { + triggeredBy: 'stub triggered by' as TriggeredBy, + source: testSource, + }; - const validator = new ActionCreatorValidator() - .setupTelemetrySend(TelemetryEvents.ASSESSMENT_SCAN_COMPLETED, payload, tabId) - .setupCreateNotificationByVisualizationKey( - payload.selectorMap, - payload.key, - payload.testType, - payload.scanIncompleteWarnings, - ) - .setupShowTargetTab(tabId, payload.testType, payload.key); + const payload: ScanCompletedPayload = { + telemetry: telemetryData, + selectorMap: {}, + scanResult: null, + testType: VisualizationType.HeadingsAssessment, + key: 'key', + scanIncompleteWarnings: [], + }; - const actionCreator = validator.buildActionCreator(); + const validator = new ActionCreatorValidator() + .setupTelemetrySend(telemetryEvent, payload, tabId) + .setupCreateNotificationByVisualizationKey( + payload.selectorMap, + payload.key, + payload.testType, + payload.scanIncompleteWarnings, + ) + .setupShowTargetTab(tabId, payload.testType, payload.key); - actionCreator.registerCallbacks(); + const actionCreator = validator.buildActionCreator(); - await validator.simulateMessage( - Messages.Assessment.AssessmentScanCompleted, - payload, - tabId, - ); + actionCreator.registerCallbacks(); - validator.verifyAll(); + await validator.simulateMessage(eventName, payload, tabId); + + validator.verifyAll(); + }); }); - test('registerCallback for onStartOverAssessment', async () => { - const tabId = 1; - const payload: ChangeInstanceStatusPayload = { - test: VisualizationType.HeadingsAssessment, - status: null, - requirement: null, - selector: null, - }; - const disableActionName = 'disableVisualization'; + describe('onStartOverAssessment', () => { + const testCases = [Messages.Assessment.StartOverTest, Messages.MediumPass.StartOverTest]; - const validator = new ActionCreatorValidator() - .setupActionOnVisualizationActions(disableActionName) - .setupVisualizationActionWithInvokeParameter(disableActionName, payload.test) - .setupTelemetrySend(TelemetryEvents.START_OVER_TEST, payload, 1); - const actionCreator = validator.buildActionCreator(); + test.each(testCases)('registerCallback with %s', async eventName => { + const tabId = 1; + const payload: ChangeInstanceStatusPayload = { + test: VisualizationType.HeadingsAssessment, + status: null, + requirement: null, + selector: null, + }; + const disableActionName = 'disableVisualization'; - actionCreator.registerCallbacks(); + const validator = new ActionCreatorValidator() + .setupActionOnVisualizationActions(disableActionName) + .setupVisualizationActionWithInvokeParameter(disableActionName, payload.test) + .setupTelemetrySend(TelemetryEvents.START_OVER_TEST, payload, 1); + const actionCreator = validator.buildActionCreator(); - await validator.simulateMessage(Messages.Assessment.StartOverTest, payload, tabId); + actionCreator.registerCallbacks(); - validator.verifyAll(); + await validator.simulateMessage(eventName, payload, tabId); + + validator.verifyAll(); + }); }); - test('registerCallback for onCancelStartOverAssessment', async () => { - const tabId = 1; - const payload: BaseActionPayload = {}; + describe('onCancelStartOverAssessment', () => { + const testCases = [ + Messages.Assessment.CancelStartOver, + Messages.MediumPass.CancelStartOver, + ]; - const validator = new ActionCreatorValidator().setupTelemetrySend( - TelemetryEvents.CANCEL_START_OVER_TEST, - payload, - tabId, - ); + test.each(testCases)('registerCallback with %s', async eventName => { + const tabId = 1; + const payload: BaseActionPayload = {}; - const actionCreator = validator.buildActionCreator(); + const validator = new ActionCreatorValidator().setupTelemetrySend( + TelemetryEvents.CANCEL_START_OVER_TEST, + payload, + tabId, + ); - actionCreator.registerCallbacks(); + const actionCreator = validator.buildActionCreator(); - await validator.simulateMessage(Messages.Assessment.CancelStartOver, payload, tabId); + actionCreator.registerCallbacks(); - validator.verifyAll(); + await validator.simulateMessage(eventName, payload, tabId); + + validator.verifyAll(); + }); }); - test('registerCallback for onStartOverAllAssessments', async () => { - const tabId = 1; - const payload: ChangeInstanceStatusPayload = { - test: VisualizationType.HeadingsAssessment, - status: null, - requirement: null, - selector: null, - }; - const disableActionName = 'disableAssessmentVisualizations'; + describe('onStartOverAllAssessments', () => { + const testCases = [ + [Messages.Assessment.StartOverAllAssessments, TelemetryEvents.START_OVER_ASSESSMENT], + [Messages.MediumPass.StartOverAllAssessments, TelemetryEvents.START_OVER_MEDIUM_PASS], + ]; + + test.each(testCases)('registerCallback with %s', async (eventName, telemetryEvent) => { + const tabId = 1; + const payload: ChangeInstanceStatusPayload = { + test: VisualizationType.HeadingsAssessment, + status: null, + requirement: null, + selector: null, + }; + const disableActionName = 'disableAssessmentVisualizations'; - const validator = new ActionCreatorValidator() - .setupActionOnVisualizationActions(disableActionName) - .setupVisualizationActionWithInvokeParameter(disableActionName, null) - .setupTelemetrySend(TelemetryEvents.START_OVER_ASSESSMENT, payload, 1); - const actionCreator = validator.buildActionCreator(); + const validator = new ActionCreatorValidator() + .setupActionOnVisualizationActions(disableActionName) + .setupVisualizationActionWithInvokeParameter(disableActionName, null) + .setupTelemetrySend(telemetryEvent, payload, 1); + const actionCreator = validator.buildActionCreator(); - actionCreator.registerCallbacks(); + actionCreator.registerCallbacks(); - await validator.simulateMessage( - Messages.Assessment.StartOverAllAssessments, - payload, - tabId, - ); + await validator.simulateMessage(eventName, payload, tabId); - validator.verifyAll(); + validator.verifyAll(); + }); }); - test('registerCallback for onCancelStartOverAllAssessments', async () => { - const tabId = 1; - const payload: BaseActionPayload = {}; + describe('onCancelStartOverAllAssessments', () => { + const testCases = [ + [ + Messages.Assessment.CancelStartOverAllAssessments, + TelemetryEvents.CANCEL_START_OVER_ASSESSMENT, + ], + [ + Messages.MediumPass.CancelStartOverAllAssessments, + TelemetryEvents.CANCEL_START_OVER_MEDIUM_PASS, + ], + ]; - const validator = new ActionCreatorValidator().setupTelemetrySend( - TelemetryEvents.CANCEL_START_OVER_ASSESSMENT, - payload, - tabId, - ); + test.each(testCases)('registerCallback with %s', async (eventName, telemetryEvent) => { + const tabId = 1; + const payload: BaseActionPayload = {}; - const actionCreator = validator.buildActionCreator(); + const validator = new ActionCreatorValidator().setupTelemetrySend( + telemetryEvent, + payload, + tabId, + ); - actionCreator.registerCallbacks(); + const actionCreator = validator.buildActionCreator(); - await validator.simulateMessage( - Messages.Assessment.CancelStartOverAllAssessments, - payload, - tabId, - ); + actionCreator.registerCallbacks(); - validator.verifyAll(); + await validator.simulateMessage(eventName, payload, tabId); + + validator.verifyAll(); + }); }); test('registerCallback for onRescanVisualization', async () => { @@ -772,90 +804,110 @@ describe('ActionCreatorTest', () => { validator.verifyAll(); }); - test('registerCallback for onEnableVisualHelper', async () => { - const tabId = 1; - const payload: ToggleActionPayload = { - test: VisualizationType.HeadingsAssessment, - }; - const actionName = 'enableVisualization'; + describe('onEnableVisualHelper', () => { + const testCases = [ + Messages.Assessment.EnableVisualHelper, + Messages.MediumPass.EnableVisualHelper, + ]; - const validator = new ActionCreatorValidator() - .setupActionOnVisualizationActions(actionName) - .setupVisualizationActionWithInvokeParameter(actionName, payload); - const actionCreator = validator.buildActionCreator(); + test.each(testCases)('registerCallback with %s', async eventName => { + const tabId = 1; + const payload: ToggleActionPayload = { + test: VisualizationType.HeadingsAssessment, + }; + const actionName = 'enableVisualization'; - actionCreator.registerCallbacks(); + const validator = new ActionCreatorValidator() + .setupActionOnVisualizationActions(actionName) + .setupVisualizationActionWithInvokeParameter(actionName, payload); + const actionCreator = validator.buildActionCreator(); + + actionCreator.registerCallbacks(); - await validator.simulateMessage(Messages.Assessment.EnableVisualHelper, payload, tabId); + await validator.simulateMessage(eventName, payload, tabId); - validator.verifyAll(); + validator.verifyAll(); + }); }); - test('registerCallback for onEnableVisualHelperWithoutScan', async () => { - const tabId = 1; - const payload: ToggleActionPayload = { - test: VisualizationType.HeadingsAssessment, - }; - const actionName = 'enableVisualizationWithoutScan'; + describe('onEnableVisualHelperWithoutScan', () => { + const testCases = [ + Messages.Assessment.EnableVisualHelperWithoutScan, + Messages.MediumPass.EnableVisualHelperWithoutScan, + ]; - const validator = new ActionCreatorValidator() - .setupActionOnVisualizationActions(actionName) - .setupVisualizationActionWithInvokeParameter(actionName, payload); - const actionCreator = validator.buildActionCreator(); + test.each(testCases)('registerCallback with %s', async eventName => { + const tabId = 1; + const payload: ToggleActionPayload = { + test: VisualizationType.HeadingsAssessment, + }; + const actionName = 'enableVisualizationWithoutScan'; - actionCreator.registerCallbacks(); + const validator = new ActionCreatorValidator() + .setupActionOnVisualizationActions(actionName) + .setupVisualizationActionWithInvokeParameter(actionName, payload); + const actionCreator = validator.buildActionCreator(); - await validator.simulateMessage( - Messages.Assessment.EnableVisualHelperWithoutScan, - payload, - tabId, - ); + actionCreator.registerCallbacks(); - validator.verifyAll(); + await validator.simulateMessage(eventName, payload, tabId); + + validator.verifyAll(); + }); }); - test('registerCallback for onDisableVisualHelper', async () => { - const tabId = 1; - const payload: ToggleActionPayload = { - test: VisualizationType.HeadingsAssessment, - }; - const actionName = 'disableVisualization'; + describe('onDisableVisualHelper', () => { + const testCases = [ + Messages.Assessment.DisableVisualHelper, + Messages.MediumPass.DisableVisualHelper, + ]; - const validator = new ActionCreatorValidator() - .setupActionOnVisualizationActions(actionName) - .setupVisualizationActionWithInvokeParameter(actionName, payload.test) - .setupTelemetrySend(TelemetryEvents.DISABLE_VISUAL_HELPER, payload, 1); + test.each(testCases)('registerCallback with %s', async eventName => { + const tabId = 1; + const payload: ToggleActionPayload = { + test: VisualizationType.HeadingsAssessment, + }; + const actionName = 'disableVisualization'; - const actionCreator = validator.buildActionCreator(); + const validator = new ActionCreatorValidator() + .setupActionOnVisualizationActions(actionName) + .setupVisualizationActionWithInvokeParameter(actionName, payload.test) + .setupTelemetrySend(TelemetryEvents.DISABLE_VISUAL_HELPER, payload, 1); - actionCreator.registerCallbacks(); + const actionCreator = validator.buildActionCreator(); - await validator.simulateMessage(Messages.Assessment.DisableVisualHelper, payload, tabId); + actionCreator.registerCallbacks(); - validator.verifyAll(); + await validator.simulateMessage(eventName, payload, tabId); + + validator.verifyAll(); + }); }); - test('registerCallback for onDisableVisualHelpersForTest', async () => { - const tabId = 1; - const payload: ToggleActionPayload = { - test: VisualizationType.HeadingsAssessment, - }; - const actionName = 'disableVisualization'; + describe('onDisableVisualHelpersForTest', () => { + const testCases = [ + Messages.Assessment.DisableVisualHelperForTest, + Messages.MediumPass.DisableVisualHelperForTest, + ]; - const validator = new ActionCreatorValidator() - .setupActionOnVisualizationActions(actionName) - .setupVisualizationActionWithInvokeParameter(actionName, payload.test); - const actionCreator = validator.buildActionCreator(); + test.each(testCases)('registerCallback with %s', async eventName => { + const tabId = 1; + const payload: ToggleActionPayload = { + test: VisualizationType.HeadingsAssessment, + }; + const actionName = 'disableVisualization'; - actionCreator.registerCallbacks(); + const validator = new ActionCreatorValidator() + .setupActionOnVisualizationActions(actionName) + .setupVisualizationActionWithInvokeParameter(actionName, payload.test); + const actionCreator = validator.buildActionCreator(); - await validator.simulateMessage( - Messages.Assessment.DisableVisualHelperForTest, - payload, - tabId, - ); + actionCreator.registerCallbacks(); - validator.verifyAll(); + await validator.simulateMessage(eventName, payload, tabId); + + validator.verifyAll(); + }); }); test('registerCallback for switch focus back to target', async () => {