forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.spec.ts
More file actions
83 lines (62 loc) · 2.39 KB
/
link.spec.ts
File metadata and controls
83 lines (62 loc) · 2.39 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { expect, test } from '../../test/playwright/index.js';
import type { Link } from './link.js';
import { LinkAppearance } from './link.options.js';
const attributes = {
download: 'download',
href: 'href',
ping: 'ping',
hreflang: 'en-GB',
referrerpolicy: 'no-referrer',
rel: 'external',
target: '_blank',
type: 'foo',
};
test.describe('Link', () => {
test.use({ tagName: 'fluent-link' });
test('should create with document.createElement()', async ({ page, fastPage }) => {
await fastPage.setTemplate();
let hasError = false;
page.on('pageerror', () => {
hasError = true;
});
await page.evaluate(() => {
document.createElement('fluent-link');
});
expect(hasError).toBe(false);
});
test(`should set each property to match its corresponding attribute`, async ({ fastPage }) => {
const { element } = fastPage;
const anchor = element.locator('a');
for (const [attribute, value] of Object.entries(attributes)) {
await test.step(`should set the \`${attribute}\` property to match the \`${attribute}\` attribute`, async () => {
await fastPage.setTemplate({ attributes: { [attribute]: value } });
await expect(element).toHaveAttribute(attribute, value);
await expect(element).toHaveJSProperty(attribute, value);
});
await test.step(`should set the \`${attribute}\` attribute on the internal anchor element`, async () => {
await expect(anchor).toHaveAttribute(attribute, value);
});
}
});
test('should set the `appearance` property to match the `appearance` attribute', async ({ fastPage }) => {
const { element } = fastPage;
for (const appearance of Object.values(LinkAppearance)) {
await test.step(appearance, async () => {
await fastPage.setTemplate({ attributes: { appearance } });
await expect(element).toHaveJSProperty('appearance', appearance);
await expect(element).toHaveAttribute('appearance', appearance);
});
}
});
test('should add an "inline" attribute when the `inline` property is true', async ({ fastPage }) => {
const { element } = fastPage;
await element.evaluate((node: Link) => {
node.inline = true;
});
await expect(element).toHaveAttribute('inline');
await element.evaluate((node: Link) => {
node.inline = false;
});
await expect(element).not.toHaveAttribute('inline');
});
});