@@ -2,12 +2,19 @@ import React from "react";
22import { render , fireEvent , cleanup } from "@testing-library/react" ;
33import "@testing-library/jest-dom/extend-expect" ;
44import SearchForm , { TEST_IDS } from "./SearchForm" ;
5- import { LANGUAGES } from "./LanguageInput " ;
5+ import { SearchProvider } from "App " ;
66
77afterEach ( cleanup ) ;
88
9+ const renderWithProvider = ( ) =>
10+ render (
11+ < SearchProvider >
12+ < SearchForm />
13+ </ SearchProvider >
14+ ) ;
15+
916test ( "`LabelInput` adds a label to `labelArray`" , ( ) => {
10- const { getByLabelText, getByTestId } = render ( < SearchForm /> ) ;
17+ const { getByLabelText, getByTestId } = renderWithProvider ( ) ;
1118
1219 const labelInput = getByLabelText ( / l a b e l / i) ;
1320 const activeLabels = getByTestId ( TEST_IDS . activeLabels ) ;
@@ -24,16 +31,16 @@ test("`LabelInput` adds a label to `labelArray`", () => {
2431} ) ;
2532
2633test ( "`LanguageInput` selection works" , ( ) => {
27- const { getByLabelText } = render ( < SearchForm /> ) ;
34+ const { getByLabelText } = renderWithProvider ( ) ;
2835
2936 const languageInput = getByLabelText ( / l a n g u a g e / i) ;
3037
31- fireEvent . change ( languageInput , { target : { value : LANGUAGES [ 1 ] } } ) ;
32- expect ( languageInput ) . toHaveValue ( LANGUAGES [ 1 ] ) ;
38+ fireEvent . change ( languageInput , { target : { value : "Haskell" } } ) ;
39+ expect ( languageInput ) . toHaveValue ( "Haskell" ) ;
3340} ) ;
3441
3542test ( "`KeywordsInput` selection works" , ( ) => {
36- const { getByLabelText } = render ( < SearchForm /> ) ;
43+ const { getByLabelText } = renderWithProvider ( ) ;
3744
3845 const keywordsInput = getByLabelText ( / k e y w o r d s / i) ;
3946
@@ -42,7 +49,7 @@ test("`KeywordsInput` selection works", () => {
4249} ) ;
4350
4451test ( "`SearchForm` form submit works" , ( ) => {
45- const { getByLabelText } = render ( < SearchForm /> ) ;
52+ const { getByLabelText } = renderWithProvider ( ) ;
4653
4754 const keywordsInput = getByLabelText ( / k e y w o r d s / i) ;
4855 const languageInput = getByLabelText ( / l a n g u a g e / i) ;
@@ -51,7 +58,7 @@ test("`SearchForm` form submit works", () => {
5158 fireEvent . change ( keywordsInput , { target : { value : "Hello" } } ) ;
5259 fireEvent . change ( labelInput , { target : { value : "Foo" } } ) ;
5360 fireEvent . keyDown ( labelInput , { keyCode : 13 } ) ;
54- fireEvent . change ( languageInput , { target : { value : LANGUAGES [ 1 ] } } ) ;
61+ fireEvent . change ( languageInput , { target : { value : "Any" } } ) ;
5562
5663 // @TODO : Implement the `handleSubmit` test
5764} ) ;
0 commit comments