forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost.spec.js
More file actions
97 lines (83 loc) · 2.79 KB
/
Post.spec.js
File metadata and controls
97 lines (83 loc) · 2.79 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/// <reference types="cypress" />
import React from 'react'
import { mount } from '@cypress/react'
import * as calc from './calc'
import SideBySide from './SideBySide'
import Post from './Post'
import { SkeletonTheme } from 'react-loading-skeleton'
describe('Post skeletons', () => {
it('mocks the es6 import', () => {
cy.stub(calc, 'getRandomNumber')
.as('lucky')
.returns(777)
mount(<Post />)
cy.contains('.random', '777')
})
it('default', () => {
mount(
<SideBySide>
<Post />
<Post title="A title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum
nec justo feugiat, auctor nunc ac, volutpat arcu. Suspendisse faucibus
aliquam ante, sit amet iaculis dolor posuere et. In ut placerat leo.
</Post>
</SideBySide>,
)
})
it('large size', () => {
mount(
<SideBySide>
<Post size="large" />
<Post size="large" title="A title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum
nec justo feugiat, auctor nunc ac, volutpat arcu. Suspendisse faucibus
aliquam ante, sit amet iaculis dolor posuere et. In ut placerat leo.
</Post>
</SideBySide>,
)
})
it('different colors', () => {
const Test = () => {
return (
<div>
<SkeletonTheme color="#1D5CA6" highlightColor="#164999">
<Post />
</SkeletonTheme>
<SkeletonTheme color="#333" highlightColor="#4a4a4a">
<Post />
</SkeletonTheme>
</div>
)
}
mount(<Test />)
})
// extra test - set Post title after a timeout
it('loads title after timeout', () => {
const Demo = () => {
// at first there is not title, no children
const [title, setTitle] = React.useState('')
const [text, setText] = React.useState('')
setTimeout(() => {
setTitle('Post title 👍')
}, 1000)
setTimeout(() => {
setText(`The text has arrived ...
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec
justo feugiat, auctor nunc ac, volutpat arcu. Suspendisse faucibus
aliquam ante, sit amet iaculis dolor posuere et. In ut placerat leo.
`)
}, 2000)
return <Post title={title} children={text} />
}
mount(<Demo />)
// at first, the title and the text are 💀
cy.get('h1 .react-loading-skeleton').should('have.length', 1)
cy.get('p .react-loading-skeleton').should('have.length', 5)
// then the title arrives, but the text is still skeletons
cy.contains('h1', 'Post title 👍').should('be.visible')
cy.get('p .react-loading-skeleton').should('have.length', 5)
// and then no skeletons remain
cy.get('.react-loading-skeleton').should('not.exist')
})
})