forked from kentcdodds/testing-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts.js
More file actions
49 lines (47 loc) · 1.21 KB
/
Copy pathposts.js
File metadata and controls
49 lines (47 loc) · 1.21 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
import {generate} from '../utils'
describe('posts', () => {
let user
beforeEach(() => {
return cy
.loginAsNewUser()
.then(u => (user = u))
.visit('/')
})
it('should allow existing users to login', () => {
const fakePost = generate.postData()
// shorten the content so we don't have to wait so long
fakePost.content = fakePost.content.slice(0, 50)
cy
.getByText(/^\+$/)
.click()
.getByLabelText('Title')
.type(fakePost.title)
.getByLabelText('Content')
// the delay is because the content takes
// forever to type otherwise
.type(fakePost.content, {delay: 1})
.getByLabelText('Tags')
.type(fakePost.tags.join(', '))
.getByText('Submit')
.click()
.assertRoute('/')
cy
.getByTestId('post-title')
.first()
.should('contain', fakePost.title)
cy
.getByTestId('post-content')
.first()
.should('contain', fakePost.content)
fakePost.tags.forEach((t, i) => {
cy
.getByTestId(`post-tag-${i}`)
.first()
.should('contain', t)
})
cy
.getByTestId('post-author-username')
.first()
.should('contain', user.username)
})
})