Skip to content

Commit

Permalink
feat(remove-android): Remove isResultHighlightUnavailableUnified (#6750)
Browse files Browse the repository at this point in the history
#### Details

Deprecating Android support will touch hundreds of files, so we're
breaking it up into more manageable units. This PR removes
the `isResultHighlightUnavailableUnified` method, which was only
referenced by its unit tests and by the unified client's initializer
(which was removed in a previous PR). The web extension's initializer
users `isResultHighlightUnavailableUnified`, which always returns
`false`.

Once `isResultHighlightUnavailableUnified` is removed, we can also
delete `src\electron\platform\android\android-scan-results.ts`

##### Motivation

Android deprecation feature

##### Context

<!-- Are there any parts that you've intentionally left out-of-scope for
a later PR to handle? -->

<!-- Were there any alternative approaches you considered? What
tradeoffs did you consider? -->

#### Pull request checklist
<!-- If a checklist item is not applicable to this change, write "n/a"
in the checkbox -->
- [n/a] Addresses an existing issue (part of Android deprecation
feature)
- [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: `<rootDir>/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
  • Loading branch information
DaveTryon committed Jun 22, 2023
1 parent a9f7ede commit 8e47f95
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 270 deletions.
34 changes: 0 additions & 34 deletions src/common/is-result-highlight-unavailable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,10 @@

import { FilterableResult } from 'common/get-card-selection-view-data';
import { PlatformData } from 'common/types/store-data/unified-data-interface';
import { BoundingRectangle } from 'electron/platform/android/android-scan-results';

export type IsResultHighlightUnavailable = (
result: FilterableResult,
platformInfo: PlatformData | null,
) => boolean;

export const isResultHighlightUnavailableUnified: IsResultHighlightUnavailable = (
result,
platformInfo,
) => {
if (
platformInfo?.viewPortInfo?.width == null ||
platformInfo?.viewPortInfo?.height == null ||
result.descriptors.boundingRectangle == null ||
!hasValidBoundingRectangle(
result.descriptors.boundingRectangle,
platformInfo.viewPortInfo.width,
platformInfo.viewPortInfo.height,
)
) {
return true;
}

return false;
};

function hasValidBoundingRectangle(
boundingRectangle: BoundingRectangle,
viewPortWidth: number,
viewPortHeight: number,
): boolean {
return !(
boundingRectangle.right <= 0 ||
boundingRectangle.bottom <= 0 ||
boundingRectangle.left > viewPortWidth ||
boundingRectangle.top > viewPortHeight
);
}

export const isResultHighlightUnavailableWeb: IsResultHighlightUnavailable = () => false;
2 changes: 0 additions & 2 deletions src/common/types/store-data/unified-data-interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { BoundingRectangle } from 'electron/platform/android/android-scan-results';
import { Target } from 'scanner/iruleresults';
import { DictionaryStringTo } from 'types/common-types';
import { GuidanceLink } from './guidance-links';
Expand Down Expand Up @@ -92,7 +91,6 @@ export type UnifiedIdentifiers = {

export type UnifiedDescriptors = {
snippet?: string;
boundingRectangle?: BoundingRectangle;
relatedCssSelectors?: string[];
} & InstancePropertyBag;

Expand Down
9 changes: 0 additions & 9 deletions src/electron/platform/android/android-scan-results.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ export const exampleAssessmentResult: AssessmentData = {
testStepStatus: {},
};

export const exampleUnifiedResultWithBoundingRectangle = {
...exampleUnifiedResult,
descriptors: {
...exampleUnifiedResult.descriptors,
boundingRectangle: {
left: 1,
top: 2,
right: 3,
bottom: 4,
},
},
};

export const exampleUnifiedRuleResult: CardRuleResult = {
id: 'some-rule',
nodes: [exampleUnifiedResult as UnifiedResult],
Expand Down
213 changes: 1 addition & 212 deletions src/tests/unit/tests/common/is-result-highlight-unavailable.test.ts
Original file line number Diff line number Diff line change
@@ -1,217 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import {
isResultHighlightUnavailableUnified,
isResultHighlightUnavailableWeb,
} from 'common/is-result-highlight-unavailable';
import { PlatformData, UnifiedResult } from 'common/types/store-data/unified-data-interface';

describe('isResultHighlightUnavailableUnified', () => {
test('unavailable: boundingRectangle is null', () => {
const unifiedResult: UnifiedResult = {
descriptors: {},
} as UnifiedResult;

expect(isResultHighlightUnavailableUnified(unifiedResult, {} as PlatformData)).toEqual(
true,
);
});

test('unavailable: platformData is null', () => {
const unifiedResult: UnifiedResult = {
descriptors: { boundingRectangle: {} },
} as UnifiedResult;

expect(isResultHighlightUnavailableUnified(unifiedResult, null)).toEqual(true);
});

test('unavailable: viewPort data missing height', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
left: 0,
right: 1,
top: 0,
bottom: 1,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 4 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(true);
});

test('unavailable: viewPort data missing width', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
left: 0,
right: 1,
top: 0,
bottom: 1,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { height: 4 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(true);
});

test('unavailable: boundingRectangle left value is greater than platform width', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
left: 5,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 4, height: 10 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(true);
});

test('unavailable: boundingRectangle right value is negative', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
right: -5,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 1, height: 1 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(true);
});

test('unavailable: boundingRectangle bottom value is negative', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
bottom: -5,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 1, height: 1 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(true);
});

test('unavailable: boundingRectangle top value is greater than platform height', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
bottom: 0,
top: 50,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 4, height: 10 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(true);
});

test('available: highlight is completely within the viewport', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
right: 2,
left: 0,
top: 2,
bottom: 5,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 4, height: 10 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(false);
});

test('available: highlight is partially out of the viewport from the left', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
right: 2,
left: -5,
top: 2,
bottom: 5,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 4, height: 10 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(false);
});

test('available: highlight is partially out of the viewport from the top', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
right: 2,
left: 0,
top: -2,
bottom: 5,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 4, height: 10 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(false);
});

test('available: highlight is partially out of the viewport from the right', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
right: 5,
left: 1,
top: 2,
bottom: 5,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 4, height: 10 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(false);
});

test('available: highlight is partially out of the viewport from the bottom', () => {
const unifiedResult: UnifiedResult = {
descriptors: {
boundingRectangle: {
right: 2,
left: 1,
top: 2,
bottom: 15,
},
},
} as UnifiedResult;
const platformData: PlatformData = {
viewPortInfo: { width: 4, height: 10 },
} as PlatformData;

expect(isResultHighlightUnavailableUnified(unifiedResult, platformData)).toEqual(false);
});
});
import { isResultHighlightUnavailableWeb } from 'common/is-result-highlight-unavailable';

describe('isResultHighlightUnavailableWeb', () => {
test('should always be available', () => {
Expand Down

0 comments on commit 8e47f95

Please sign in to comment.