/
local-state_spec.js
105 lines (90 loc) · 3.42 KB
/
local-state_spec.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
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
import { getSelector } from '../support/utils/css-modules';
// Warning: The following tests are not atomic (which is why we're using before
// instead of beforeEach). Each test builds on the previous and in some cases
// tests rely on state generated by previous tests. This is not ideal, but until
// we expand the Cypress suite further it is good enough. Think of these tests
// as smoke tests.
describe('Local state example', () => {
context('homepage', () => {
before(() => {
cy.visit('/');
});
it('should have correct title', () => {
cy.title().should('include', 'React Cosmos');
});
it('should list components', () => {
const componentSel = getSelector('index__componentName');
cy.get(`${componentSel}:eq(0)`).should('contain', 'Counter');
cy.get(`${componentSel}:eq(1)`).should('contain', 'CounterList');
});
it('should list fixtures', () => {
const fixtureSel = getSelector('index__fixture');
cy.get(`${fixtureSel}:eq(0)`).should('contain', 'default');
cy.get(`${fixtureSel}:eq(1)`).should('contain', 'fiveClicks');
cy.get(`${fixtureSel}:eq(2)`).should('contain', 'default');
cy.get(`${fixtureSel}:eq(3)`).should('contain', 'oneTwoThree');
});
it('should show welcome message', () => {
cy.get(getSelector('index__content')).should('contain', "You're all set");
});
});
context('filter', () => {
before(() => {
const inputSel = getSelector('index__searchInput');
cy.get(inputSel).type('oneThree');
});
it('should match only one fixture', () => {
const fixtureSel = getSelector('index__fixture');
cy
.get(fixtureSel)
.should('have.length', 1)
.eq(0)
.should('contain', 'oneTwoThree');
});
});
context('select fixture', () => {
// There's only one fixture at this point
const fixtureButtonSel = `${getSelector('index__fixture')}:eq(0)`;
before(() => {
cy.get(fixtureButtonSel).click();
});
it('should add active class to fixture button', () => {
cy
.get(fixtureButtonSel)
.then($fixtureButton => {
return $fixtureButton.attr('class');
})
.should('contain', 'index__fixtureSelected');
});
it('should render Loader iframe', () => {
cy
.get('iframe')
.should('have.exist')
.should('have.attr', 'src', './loader/index.html');
});
});
context('fixture editor', () => {
// The first menu button is the fixture editor toggle
const editorButtonSel = `${getSelector('index__button')}:eq(1)`;
before(() => {
cy.get(editorButtonSel).click();
});
it('should add active class to editor button', () => {
cy
.get(editorButtonSel)
.then($fixtureButton => {
return $fixtureButton.attr('class');
})
.should('contain', 'index__selectedButton');
});
it('should display fixture inside editor', () => {
cy.get('.CodeMirror-line:eq(0)').should('contain', '{');
cy.get('.CodeMirror-line:eq(1)').should('contain', '"state": {');
cy.get('.CodeMirror-line:eq(2)').should('contain', '"children": {');
cy.get('.CodeMirror-line:eq(3)').should('contain', '"c1": {');
cy.get('.CodeMirror-line:eq(4)').should('contain', '"value": 1');
cy.get('.CodeMirror-line:eq(7)').should('contain', '"value": 2');
cy.get('.CodeMirror-line:eq(10)').should('contain', '"value": 3');
});
});
});