Skip to content

Commit

Permalink
feat(tab-stops-details-view): Remove instances on undo and update (#4903
Browse files Browse the repository at this point in the history
)
  • Loading branch information
brocktaylor7 authored Nov 19, 2021
1 parent df4c135 commit 8c99d9c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/background/stores/visualization-scan-result-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export class VisualizationScanResultStore extends BaseStoreImpl<VisualizationSca
): void => {
const { requirementId, status } = payload;
this.state.tabStops.requirements[requirementId].status = status;
if (status === 'pass') {
this.state.tabStops.requirements[requirementId].instances = [];
}
this.emitChanged();
};

Expand All @@ -153,6 +156,7 @@ export class VisualizationScanResultStore extends BaseStoreImpl<VisualizationSca
): void => {
const { requirementId } = payload;
this.state.tabStops.requirements[requirementId].status = TabStopRequirementStatuses.unknown;
this.state.tabStops.requirements[requirementId].instances = [];
this.emitChanged();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AddTabbedElementPayload,
AddTabStopInstancePayload,
RemoveTabStopInstancePayload,
ResetTabStopRequirementStatusPayload,
UpdateTabStopInstancePayload,
UpdateTabStopRequirementStatusPayload,
} from 'background/actions/action-payloads';
Expand Down Expand Up @@ -406,8 +407,12 @@ describe('VisualizationScanResultStoreTest', () => {
);
});

test('onUpdateTabStopRequirementStatus', () => {
test('onUpdateTabStopRequirementStatus updates status and removes instances', () => {
const initialState = new VisualizationScanResultStoreDataBuilder().build();
initialState.tabStops.requirements['keyboard-navigation'].status = 'fail';
initialState.tabStops.requirements['keyboard-navigation'].instances = [
{ description: 'test1', id: 'abc' },
];

const payload: UpdateTabStopRequirementStatusPayload = {
requirementId: 'keyboard-navigation',
Expand All @@ -431,6 +436,34 @@ describe('VisualizationScanResultStoreTest', () => {
.testListenerToBeCalledOnce(initialState, expectedState);
});

test('onResetTabStopRequirementStatus resets status and removes instances', () => {
const initialState = new VisualizationScanResultStoreDataBuilder().build();
initialState.tabStops.requirements['keyboard-navigation'].status = 'fail';
initialState.tabStops.requirements['keyboard-navigation'].instances = [
{ description: 'test1', id: 'abc' },
];

const payload: ResetTabStopRequirementStatusPayload = {
requirementId: 'keyboard-navigation',
};

const requirement: TabStopRequirementState = {
'keyboard-navigation': {
status: 'unknown',
instances: [],
isExpanded: false,
},
};

const expectedState = new VisualizationScanResultStoreDataBuilder()
.withTabStopRequirement(requirement)
.build();

createStoreTesterForTabStopRequirementActions('resetTabStopRequirementStatus')
.withActionParam(payload)
.testListenerToBeCalledOnce(initialState, expectedState);
});

test('onAddTabStopInstance', () => {
const initialState = new VisualizationScanResultStoreDataBuilder().build();

Expand Down

0 comments on commit 8c99d9c

Please sign in to comment.