Skip to content

Commit fbd52bb

Browse files
committed
update to latest src
1 parent a68aaff commit fbd52bb

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

Diff for: visual-js/visual/src/selective-region.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
DiffingOption,
3+
DiffingOptionsIn,
4+
RegionIn,
5+
} from './graphql/__generated__/graphql';
6+
7+
export type SelectiveRegionOptions =
8+
| { enableOnly: Array<keyof DiffingOptionsIn>; disableOnly?: never }
9+
| { enableOnly?: never; disableOnly: Array<keyof DiffingOptionsIn> };
10+
11+
export type SelectiveRegion = Omit<RegionIn, 'diffingOptions'> &
12+
SelectiveRegionOptions;
13+
14+
export function selectiveRegionOptionsToDiffingOptions(
15+
opt: SelectiveRegionOptions,
16+
): DiffingOptionsIn {
17+
if ('enableOnly' in opt && opt.enableOnly) {
18+
const diffingOptions: DiffingOptionsIn = {
19+
content: false,
20+
dimensions: false,
21+
position: false,
22+
structure: false,
23+
style: false,
24+
visual: false,
25+
};
26+
for (const key of opt.enableOnly) diffingOptions[key] = true;
27+
return diffingOptions;
28+
} else {
29+
const diffingOptions: DiffingOptionsIn = {
30+
content: true,
31+
dimensions: true,
32+
position: true,
33+
structure: true,
34+
style: true,
35+
visual: true,
36+
};
37+
for (const key of opt.disableOnly) diffingOptions[key] = false;
38+
return diffingOptions;
39+
}
40+
}
41+
42+
export function selectiveRegionToRegionIn(
43+
input: SelectiveRegion[],
44+
): Array<RegionIn> {
45+
return input.map((opt) => {
46+
const { x, y, width, height } = opt;
47+
return {
48+
x,
49+
y,
50+
width,
51+
height,
52+
diffingOptions: selectiveRegionOptionsToDiffingOptions(opt),
53+
};
54+
});
55+
}

Diff for: visual-js/visual/src/types.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export type FullPageScreenshotOptions =
2+
| boolean
3+
| {
4+
/**
5+
* Adjust address bar padding on iOS and Android for viewport cutout.
6+
*/
7+
addressBarShadowPadding?: number;
8+
/**
9+
* Delay in ms after scrolling and before taking screenshots.
10+
* A slight delay can be helpful if the page is using lazy loading when scrolling
11+
*/
12+
delayAfterScrollMs?: number;
13+
/**
14+
* Disable CSS animations and the input caret in the app.
15+
*/
16+
disableCSSAnimation?: boolean;
17+
/**
18+
* Hide elements on the page after first scroll by css selectors.
19+
*/
20+
hideAfterFirstScroll?: string[];
21+
/**
22+
* Hide all scrollbars in the app.
23+
*/
24+
hideScrollBars?: boolean;
25+
/**
26+
* Adjust toolbar padding on iOS and Android for viewport cutout.
27+
*/
28+
toolBarShadowPadding?: number;
29+
/**
30+
* Limit the number of screenshots taken for scrolling and stitching.
31+
*/
32+
scrollLimit?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
33+
};

Diff for: visual-js/visual/src/utils.spec.ts

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { describe, expect, test } from '@jest/globals';
2+
import { getFullPageConfig } from './utils';
3+
import { FullPageConfigIn } from './graphql/__generated__/graphql';
4+
5+
const configDelay: FullPageConfigIn = {
6+
delayAfterScrollMs: 1500,
7+
};
8+
9+
const configDelayBig: FullPageConfigIn = {
10+
delayAfterScrollMs: 5000,
11+
};
12+
13+
describe('utils', () => {
14+
describe('getFullPageConfig', () => {
15+
describe('returns undefined', () => {
16+
test('when main is true and local is false', () => {
17+
expect(getFullPageConfig(true, false)).toBeUndefined();
18+
});
19+
test('when main is false and local is false', () => {
20+
expect(getFullPageConfig(false, false)).toBeUndefined();
21+
});
22+
test('when main is false and local is false', () => {
23+
expect(getFullPageConfig(false, false)).toBeUndefined();
24+
});
25+
test('when main is object and local is false', () => {
26+
expect(getFullPageConfig(configDelay, false)).toBeUndefined();
27+
});
28+
test('when main is undefined and local is false', () => {
29+
expect(getFullPageConfig(undefined, false)).toBeUndefined();
30+
});
31+
test('when main is undefined and local is undefined', () => {
32+
expect(getFullPageConfig(undefined, undefined)).toBeUndefined();
33+
});
34+
test('when main is false and local is undefined', () => {
35+
expect(getFullPageConfig(false, undefined)).toBeUndefined();
36+
});
37+
});
38+
describe('returns empty config', () => {
39+
test('when main is true and local is true', () => {
40+
expect(getFullPageConfig(true, undefined)).toEqual({});
41+
});
42+
test('when main is false and local is true', () => {
43+
expect(getFullPageConfig(true, undefined)).toEqual({});
44+
});
45+
test('when main is undefined and local is true', () => {
46+
expect(getFullPageConfig(true, undefined)).toEqual({});
47+
});
48+
test('when main is true and local is undefined', () => {
49+
expect(getFullPageConfig(true, undefined)).toEqual({});
50+
});
51+
});
52+
describe('returns config', () => {
53+
test('when main is config and local is true', () => {
54+
expect(getFullPageConfig(configDelay, true)).toEqual(configDelay);
55+
});
56+
test('when main is true and local is config', () => {
57+
expect(getFullPageConfig(true, configDelay)).toEqual(configDelay);
58+
});
59+
test('when main is false and local is config', () => {
60+
expect(getFullPageConfig(true, configDelay)).toEqual(configDelay);
61+
});
62+
test('when main is config and local is config', () => {
63+
expect(getFullPageConfig(configDelay, configDelay)).toEqual(
64+
configDelay,
65+
);
66+
});
67+
test('and local overwrites main config', () => {
68+
expect(getFullPageConfig(configDelay, configDelayBig)).toEqual(
69+
configDelayBig,
70+
);
71+
});
72+
test('with merged local and main config', () => {
73+
const main = { delayAfterScrollMs: 500 };
74+
const local = { disableCSSAnimation: false };
75+
expect(getFullPageConfig(main, local)).toEqual({ ...main, ...local });
76+
});
77+
});
78+
});
79+
});

0 commit comments

Comments
 (0)