-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathApp.test.js
72 lines (56 loc) · 1.95 KB
/
App.test.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
import React from 'react'
import AppFunctional from './AppFunctional'
import { render, fireEvent, screen } from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
// Write your tests here
test('sanity', () => {
expect(true).toBe(true)
})
test('header renders', () => {
render(<AppFunctional />)
const coordinates = screen.queryByText(/coordinates/i)
const upButton = screen.queryByText('UP')
const leftButton = screen.queryByText('LEFT')
const rightButton = screen.queryByText('RIGHT')
const downButton = screen.queryByText('DOWN')
const resetButton = screen.queryByText('reset')
expect(coordinates).toBeInTheDocument()
expect(leftButton).toBeInTheDocument()
expect(rightButton).toBeInTheDocument()
expect(upButton).toBeInTheDocument()
expect(downButton).toBeInTheDocument()
expect(resetButton).toBeInTheDocument()
})
test('typing in input results in text entered', () => {
render(<AppFunctional />)
const inputBox = screen.getByRole('textbox', {id:'email'})
expect(inputBox)
.toBeInTheDocument()
fireEvent.change(inputBox, { target: {value: 'pizzatime'}})
expect(inputBox)
.toHaveValue('pizzatime')
})
test('clicking reset clears input box', () => {
render(<AppFunctional />)
const inputBox = screen.getByRole('textbox', {id:'email'})
const resetButton = screen.getByTestId('reset')
fireEvent.change(inputBox, { target: {value: 'pizzatime'}})
expect(inputBox)
.toHaveValue('pizzatime')
fireEvent.click(resetButton)
expect(inputBox)
.toHaveValue('')
})
test('cannot go up past bounds', () => {
render(<AppFunctional />)
const upButton = screen.getByTestId('up')
fireEvent.click(upButton)
fireEvent.click(upButton)
expect(screen.getByText("You can't go up")).toBeInTheDocument()
})
test('displays moves', () => {
render(<AppFunctional />)
const upButton = screen.getByTestId('up')
fireEvent.click(upButton)
expect(screen.getByText("You moved 1 time")).toBeInTheDocument()
})