1
1
import { render , fireEvent } from '@testing-library/vue'
2
2
import 'jest-dom/extend-expect'
3
- import Signup from './components/Signup'
4
-
5
- test ( 'signup form submits' , async ( ) => {
6
- const fakeUser = {
7
- username : 'jackiechan' ,
8
- about : 'Lorem ipsum dolor sit amet' ,
9
- selected : 'None of the above' ,
10
- rememberMe : true
3
+ import Form from './components/Form'
4
+
5
+ test ( 'Review form submits' , async ( ) => {
6
+ const fakeReview = {
7
+ title : 'An Awesome Movie' ,
8
+ review : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' ,
9
+ rating : '3' ,
10
+ genre : 'Action' ,
11
+ recommend : true
11
12
}
12
13
13
14
const {
@@ -17,31 +18,34 @@ test('signup form submits', async () => {
17
18
getByDisplayValue,
18
19
getByPlaceholderText,
19
20
emitted
20
- } = render ( Signup )
21
+ } = render ( Form )
21
22
22
23
const submitButton = getByText ( 'Submit' )
23
24
24
- // Initially the form should be disabled
25
+ // Initially the submit button should be disabled
25
26
expect ( submitButton ) . toBeDisabled ( )
26
27
27
- // We are gonna showcase several ways of targetting DOM elements.
28
+ // In this test we showcase several ways of targetting DOM elements.
28
29
// However, `getByLabelText` should be your top preference when handling
29
30
// form elements.
30
- //
31
31
// Read 'What queries should I use?' for additional context:
32
32
// https://testing-library.com/docs/guide-which-query
33
- const userNameInput = getByLabelText ( / u s e r n a m e / i)
34
- await fireEvent . update ( userNameInput , fakeUser . username )
35
33
36
- const aboutMeTextarea = getByPlaceholderText ( 'I was born in...' )
37
- await fireEvent . update ( aboutMeTextarea , fakeUser . about )
34
+ const titleInput = getByLabelText ( / t i t l e o f t h e m o v i e / i )
35
+ await fireEvent . update ( titleInput , fakeReview . title )
38
36
39
- const rememberMeInput = getByTestId ( 'remember-input' )
40
- await fireEvent . update ( rememberMeInput , fakeUser . rememberMe )
37
+ const reviewTextarea = getByPlaceholderText ( 'Write an awesome review' )
38
+ await fireEvent . update ( reviewTextarea , fakeReview . review )
39
+
40
+ const ratingSelect = getByLabelText ( 'Wonderful' )
41
+ await fireEvent . update ( ratingSelect , fakeReview . rating )
41
42
42
43
// Get the Select element by using the initially displayed value.
43
- const preferenceSelect = getByDisplayValue ( 'Dogs' )
44
- await fireEvent . update ( preferenceSelect , fakeUser . selected )
44
+ const genreSelect = getByDisplayValue ( 'Comedy' )
45
+ await fireEvent . update ( genreSelect , fakeReview . genre )
46
+
47
+ const recommendInput = getByTestId ( 'recommend-checkbox' )
48
+ await fireEvent . update ( recommendInput , fakeReview . recommend )
45
49
46
50
// NOTE: in jsdom, it's not possible to trigger a form submission
47
51
// by clicking on the submit button. This is really unfortunate.
@@ -54,5 +58,5 @@ test('signup form submits', async () => {
54
58
55
59
// Assert event has been emitted.
56
60
expect ( emitted ( ) . submit ) . toHaveLength ( 1 )
57
- expect ( emitted ( ) . submit [ 0 ] ) . toEqual ( [ fakeUser ] )
61
+ expect ( emitted ( ) . submit [ 0 ] ) . toEqual ( [ fakeReview ] )
58
62
} )
0 commit comments