-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.ts
33 lines (26 loc) · 1.7 KB
/
tools.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { ClientFunction } from "testcafe";
const allowedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
export function mkValidPath(path: string): string {
return path.split("").map(char => allowedChars.includes(char) ? char : "_").join("");
}
export function getRandomIntInRange(min: number, max: number) {
return min + Math.floor(Math.random() * (max - min));
}
export const getWindowDevicePixelRatio = ClientFunction(() => window.devicePixelRatio);
const targetWidth = 640;
const targetHeight = 480;
export const landscapeDimensions = {width: targetWidth, height: targetHeight};
export const portraitDimensions = {width: targetHeight, height: targetWidth};
export type Dimensions = {width: number, height: number};
export const getWindowInnerDimensions = ClientFunction<Dimensions, []>(() => ({width: window.innerWidth, height: window.innerHeight}));
export type Orientation = "PORTRAIT" | "LANDSCAPE";
export const getWindowOrientation = ClientFunction<Orientation, []>(() => (window.innerWidth > window.innerHeight) ? "LANDSCAPE" : "PORTRAIT");
/** set size to something else so resize is necessary */
export const resizeToSomethingElse = async (t: TestController) => t.resizeWindow(targetWidth + 13, targetHeight + 13);
export const resizeTo = async (t: TestController, dimensions: Dimensions) => t.resizeWindow(dimensions.width, dimensions.height);
export const resizeToLandscape = async (t: TestController) => resizeTo(t, landscapeDimensions);
export const resizeToPortrait = async (t: TestController) => resizeTo(t, portraitDimensions);
export function getOrientation(dimensions: Dimensions): Orientation {
if(dimensions.width > dimensions.height) return "LANDSCAPE";
return "PORTRAIT";
}