This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getCy.ts
132 lines (118 loc) · 3.51 KB
/
getCy.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import {
selector,
cypressTag,
useCypressTag,
getCypressTag,
combineParts,
} from '../..';
describe('cypress-helper-getcy', () => {
before(() => {
cy.visit('./fixtures/index.html');
});
describe('cy.get', () => {
context('single name', () => {
it('can get single item', () => {
cy.getCy('items').should('exist');
});
it('can get a collection of items', () => {
cy.getCy('item').should('have.length', 3);
});
it('can append additional selector', () => {
cy.getCy('items', '>:nth-child(2)').should('have.text', 'Bob');
});
it('works as expected with `within`', () => {
cy.getCy('items').within(() => {
cy.getCy('item').should('have.length', 2);
});
});
});
context('array of names', () => {
it('can select several items', () => {
cy.getCy(['items', 'item']).should('have.length', 4);
});
});
describe('options', () => {
it('can disable logging via log = false', () => {
cy.getCy('items', undefined, { log: false });
});
it('can enable logging for internal `get` via log = true', () => {
cy.getCy('items', undefined, { log: true });
});
it('can pass a timeout to internal `get`', () => {
cy.getCy('items', undefined, { timeout: 500 });
});
});
});
describe('selector', () => {
it('works', () => {
expect(selector('foo')).equal(`[data-cy='foo']`);
});
it('works with `append` parameter', () => {
expect(selector('foo', ':first-child')).equal(
`[data-cy='foo']:first-child`
);
});
});
describe('combineParts', () => {
it('works no parts', () => {
expect(combineParts()).equal('');
});
it('works with one part', () => {
expect(combineParts('foo')).equal('foo');
});
it('works with multiple parts', () => {
expect(combineParts('foo', 'bar', 'baz')).equal('foo/bar/baz');
});
});
describe('cypressTag', () => {
it('works without name', () => {
expect(cypressTag('foo')()).equal('foo');
});
it('works with name', () => {
expect(cypressTag('foo')('bar')).equal('foo/bar');
});
it('works with multiple namespace parts', () => {
expect(cypressTag('foo', 'bar')('baz')).equal('foo/bar/baz');
});
});
describe('useCypressTag', () => {
it('works without name', () => {
expect(useCypressTag('foo')()).eql({ 'data-cy': 'foo' });
});
it('works with name', () => {
expect(useCypressTag('foo')('bar')).eql({ 'data-cy': 'foo/bar' });
});
it('works with multiple namespaces', () => {
expect(useCypressTag('foo', 'bar')('baz')).eql({
'data-cy': 'foo/bar/baz',
});
});
});
describe('getCypressTag', () => {
it('works without name', () => {
const tag = getCypressTag('foo');
tag()
.should('exist')
.and('have.text', 'Foo');
});
it('works with name', () => {
const tag = getCypressTag('foo');
tag('bar')
.should('exist')
.and('have.text', 'Foo Bar');
});
it('works with several names', () => {
const tag = getCypressTag('foo');
tag(['bar', 'baz']).should($items => {
expect($items.eq(0)).to.have.text('Foo Bar');
expect($items.eq(1)).to.have.text('Foo Baz');
});
});
it('works with several namespaces', () => {
const tag = getCypressTag('foo', 'bar');
tag('baz')
.should('exist')
.and('have.text', 'Foo Bar Baz');
});
});
});