-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactiveUrl.ts
34 lines (30 loc) · 1.21 KB
/
activeUrl.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
34
import { getValue, isInputElement, isSelectElement } from '../common/dom';
export default {
async passed(elements: HTMLElement[]): Promise<boolean> {
const promisedElementFetches = elements.map((element: HTMLElement) => {
return new Promise((resolve: (value: boolean) => void): void => {
if (!isInputElement(element) && !isSelectElement(element)) {
resolve(true);
}
const values = getValue(element);
if (values.length) {
Promise.all(values.map((value: string) => {
return fetch(value).then((response: Response) => {
return response.status === 200;
});
})).then((activeResponses: boolean[]) => {
resolve( !activeResponses.filter((active: boolean) => !active).length)
})
} else {
resolve(true);
}
})
})
return !(await Promise.all(promisedElementFetches))
.filter((active: boolean) => !active)
.length;
},
message(): string {
return 'activeUrl';
}
}