This repository has been archived by the owner on Nov 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Badge.e2e.ts
64 lines (50 loc) · 2.14 KB
/
Badge.e2e.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
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
import * as eyes from 'eyes.it';
import {$, browser, Key} from 'protractor';
import {getStoryUrl, scrollToElement, waitForVisibilityOf} from 'wix-ui-test-utils/protractor';
import {badgeTestkitFactory} from '../../testkit/protractor';
import * as autoExampleDriver from 'wix-storybook-utils/AutoExampleDriver';
const byDataHook = dataHook => $(`[data-hook="${dataHook}"]`);
// TODO: move method to protractor-helpers, or to the AutoExampleDriver?
const focusElementInAutoExample = async element => {
const parentElement = await element.getWebElement().getDriver();
await parentElement
.actions()
.click()
.perform();
await browser
.actions()
.sendKeys(Key.TAB)
.perform();
};
describe('Badge', () => {
const storyUrl = getStoryUrl('Components', 'Badge');
beforeEach(() => browser.get(storyUrl));
describe('AutoExample', () => {
beforeEach(async () => {
await autoExampleDriver.reset();
});
eyes.it('should display correct content', async () => {
const driver = badgeTestkitFactory({dataHook: 'storybook-badge'});
await waitForVisibilityOf(driver.element(), 'Cannot find Badge');
expect(await driver.text()).toBe('I\'M A BADGE!');
});
eyes.it('should not have a focus state when onClick prop is not used', async () => {
await autoExampleDriver.setProps({onClick: undefined});
const driver = badgeTestkitFactory({dataHook: 'storybook-badge'});
await waitForVisibilityOf(driver.element(), 'Cannot find Badge');
await focusElementInAutoExample(driver.element());
});
eyes.it('should have a focus state when onClick prop is used', async () => {
await autoExampleDriver.setProps({onClick: () => true});
const driver = badgeTestkitFactory({dataHook: 'storybook-badge'});
await waitForVisibilityOf(driver.element(), 'Cannot find Badge');
await focusElementInAutoExample(driver.element());
});
});
eyes.it('should not break design', async () => {
const dataHook = 'badge-variations';
const element = byDataHook(dataHook);
await waitForVisibilityOf(element, `Cannot find ${dataHook}`);
await scrollToElement(element);
});
});