This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
/
InlineBadges.test.js
60 lines (54 loc) · 2.53 KB
/
InlineBadges.test.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
55
56
57
58
59
60
const { describeMacro, itMacro } = require('./utils.js');
/**
* @typedef {object} TestCase
* @property {string} title
* @property {string[]} args
* @property {string} expected
*/
/** @type {TestCase[]} */
const TEST_CASES = [
{
title: 'Obsolete overrides deprecated',
args: ['deprecated', 'obsolete'],
expected:
' <span title="This is an obsolete API and is no longer guaranteed to work." class="icon-only-inline"><i class="icon-trash"> </i></span>'
},
{
title: 'Non-standard comes first',
args: ['deprecated', 'experimental', 'non-standard'],
expected:
' <span title="This API has not been standardized." class="icon-only-inline"><i class="icon-warning-sign"> </i></span>' +
' <span title="This is an experimental API that should not be used in production code." class="icon-only-inline"><i class="icon-beaker"> </i></span>' +
' <span title="This deprecated API should no longer be used, but will probably still work." class="icon-only-inline"><i class="icon-thumbs-down-alt"> </i></span>'
},
{
title: 'Badges follow icons',
args: ['readonly', 'experimental', 'non-standard'],
expected:
' <span title="This API has not been standardized." class="icon-only-inline"><i class="icon-warning-sign"> </i></span>' +
' <span title="This is an experimental API that should not be used in production code." class="icon-only-inline"><i class="icon-beaker"> </i></span>' +
'<span title="This value may not be changed." class="inlineIndicator readOnly readOnlyInline">Read only </span>'
}
];
describeMacro('InlineBadges', () => {
itMacro('Early return when no arguments are provided', async macro => {
await expect(macro.call()).resolves.toBeFalsy();
});
for (const t of TEST_CASES) {
itMacro(t.title, async macro => {
let result = await macro.call(...t.args);
expect(result).toEqual(t.expected);
});
}
itMacro('Duplicate badge throws error', async macro => {
await expect(macro.call('experimental', 'experimental')).rejects.toThrow(TypeError);
});
itMacro('Unknown badge throws error (reports used case)', async macro => {
// eslint-disable-next-line jest/valid-expect
let rejects = expect(macro.call('__INVALID__')).rejects;
await Promise.all([
rejects.toThrow(TypeError),
rejects.toThrow('Unknown badge: __INVALID__'),
]);
});
});