forked from uber/baseweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
54 lines (44 loc) · 1.43 KB
/
tests.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Copyright (c) 2018 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
/* eslint-disable no-console */
/* eslint-disable react/prop-types */
/* eslint-disable flowtype/require-valid-file-annotation */
/* eslint-env browser */
import React from 'react';
import scenarios from '../src/**/*.scenario.js';
const nameCounts = scenarios.reduce((map, s) => {
if (!map[s.name]) {
map[s.name] = 1;
} else {
map[s.name]++;
}
return map;
}, {});
const collisions = Object.entries(nameCounts).filter(([_, count]) => count > 1);
if (collisions.length >= 1) {
console.error(`Found colliding scenario name(s): ${collisions
.map(([name]) => name)
.join(', ')}. Double check your scenario file name export.
`);
}
const A11yFail = props => <div role={props.message} />;
export default function showTestcase() {
// needs polyfill for IE
const urlParams = new URLSearchParams(window.location.search);
const name = urlParams.get('name');
if (!name) {
const message = 'No scenario name provided.';
console.error(message);
return <A11yFail message={message} />;
}
const scenario = scenarios.find(s => s.name === name);
if (!scenario) {
const message = `No scenario found with the name: '${name}.'`;
console.error(message);
return <A11yFail message={message} />;
}
return <div>{scenario.component()}</div>;
}