@@ -7,13 +7,16 @@ import {
77 setFields ,
88 setTechs ,
99 setShowJobDurationSlider ,
10+ setShowHidden ,
1011} from "../../../actions/searchOffersActions" ;
1112import { createTheme } from "@material-ui/core" ;
1213import { renderWithStoreAndTheme , screen , fireEvent , act } from "../../../test-utils" ;
13-
1414import { MemoryRouter } from "react-router-dom" ;
1515
16+ import PropTypes from "prop-types" ;
17+
1618import qs from "qs" ;
19+ import { INITIAL_JOB_TYPE } from "../../../reducers/searchOffersReducer" ;
1720
1821// eslint-disable-next-line react/prop-types
1922const RouteWrappedContent = ( { children, url = "/" } ) => (
@@ -22,6 +25,49 @@ const RouteWrappedContent = ({ children, url = "/" }) => (
2225 </ MemoryRouter >
2326) ;
2427
28+ const SearchAreaWrapper = ( {
29+ searchValue = "" , jobType = INITIAL_JOB_TYPE , jobDuration = [ null , null ] , filterJobDuration = false ,
30+ showJobDurationSlider = false , fields = [ ] , technologies = [ ] , setShowJobDurationSlider = ( ) => { } ,
31+ setTechs = ( ) => { } , setJobDuration = ( ) => { } , setFields = ( ) => { } , setJobType = ( ) => { } ,
32+ setSearchValue = ( ) => { } , onSubmit = ( ) => { } , setShowHidden = ( ) => { } ,
33+ } ) => (
34+ < SearchArea
35+ searchValue = { searchValue }
36+ jobType = { jobType }
37+ jobDuration = { jobDuration }
38+ filterJobDuration = { filterJobDuration }
39+ fields = { fields }
40+ technologies = { technologies }
41+ showJobDurationSlider = { showJobDurationSlider }
42+ setShowJobDurationSlider = { setShowJobDurationSlider }
43+ setTechs = { setTechs }
44+ setJobDuration = { setJobDuration }
45+ setFields = { setFields }
46+ setJobType = { setJobType }
47+ setSearchValue = { setSearchValue }
48+ onSubmit = { onSubmit }
49+ setShowHidden = { setShowHidden }
50+ />
51+ ) ;
52+
53+ SearchAreaWrapper . propTypes = {
54+ onSubmit : PropTypes . func ,
55+ searchValue : PropTypes . string . isRequired ,
56+ jobType : PropTypes . string ,
57+ setSearchValue : PropTypes . func . isRequired ,
58+ setJobDuration : PropTypes . func . isRequired ,
59+ setJobType : PropTypes . func . isRequired ,
60+ fields : PropTypes . array . isRequired ,
61+ technologies : PropTypes . array . isRequired ,
62+ showJobDurationSlider : PropTypes . bool . isRequired ,
63+ setFields : PropTypes . func . isRequired ,
64+ setTechs : PropTypes . func . isRequired ,
65+ setShowJobDurationSlider : PropTypes . func . isRequired ,
66+ jobDuration : PropTypes . number ,
67+ filterJobDuration : PropTypes . bool ,
68+ setShowHidden : PropTypes . bool ,
69+ } ;
70+
2571describe ( "SearchArea" , ( ) => {
2672 let onSubmit ;
2773 const theme = createTheme ( ) ;
@@ -34,7 +80,7 @@ describe("SearchArea", () => {
3480 it ( "should render a Paper, a Form, a Search Bar, a Search Button and Advanced Options Button" , ( ) => {
3581 renderWithStoreAndTheme (
3682 < RouteWrappedContent >
37- < SearchArea
83+ < SearchAreaWrapper
3884 onSubmit = { onSubmit }
3985 fields = { [ ] }
4086 technologies = { [ ] }
@@ -44,6 +90,7 @@ describe("SearchArea", () => {
4490 setFields = { ( ) => { } }
4591 setJobType = { ( ) => { } }
4692 setSearchValue = { ( ) => { } }
93+ setShowHidden = { ( ) => { } }
4794 />
4895 </ RouteWrappedContent > ,
4996 { initialState, theme }
@@ -55,6 +102,88 @@ describe("SearchArea", () => {
55102 expect ( screen . getByRole ( "button" , { name : "Search" } ) ) . toBeInTheDocument ( ) ;
56103 expect ( screen . getByRole ( "button" , { name : "Toggle Advanced Search" } ) ) . toBeInTheDocument ( ) ;
57104 } ) ;
105+ it ( "should render a text='Show All' in the default state of searchArea" , ( ) => {
106+ const searchArea = renderWithStoreAndTheme (
107+ < RouteWrappedContent >
108+ < SearchAreaWrapper />
109+ </ RouteWrappedContent > ,
110+ { initialState, theme }
111+ ) ;
112+
113+ expect ( searchArea . getByRole ( "button" , { name : "Search" } ) ) . toHaveTextContent ( "Show All" ) ;
114+ } ) ;
115+ it ( "should render a text='Search' when search bar value != ''" , ( ) => {
116+ const searchArea = renderWithStoreAndTheme (
117+ < RouteWrappedContent >
118+ < SearchAreaWrapper
119+ searchValue = { "somevalue" }
120+ />
121+ </ RouteWrappedContent > ,
122+ { initialState, theme }
123+ ) ;
124+
125+ expect ( searchArea . getByRole ( "button" , { name : "Search" } ) ) . toHaveTextContent ( "Search" ) ;
126+ } ) ;
127+ it ( "should render a text='Show All' when search bar has undefined value" , ( ) => {
128+ const searchArea = renderWithStoreAndTheme (
129+ < RouteWrappedContent >
130+ < SearchAreaWrapper
131+ searchValue = { undefined }
132+ />
133+ </ RouteWrappedContent > ,
134+ { initialState, theme }
135+ ) ;
136+
137+ expect ( searchArea . getByRole ( "button" , { name : "Search" } ) ) . toHaveTextContent ( "Show All" ) ;
138+ } ) ;
139+ it ( "should render a text='Search' when fields != []" , ( ) => {
140+ const searchArea = renderWithStoreAndTheme (
141+ < RouteWrappedContent >
142+ < SearchAreaWrapper
143+ fields = { [ "field1" , "field2" ] }
144+ />
145+ </ RouteWrappedContent > ,
146+ { initialState, theme }
147+ ) ;
148+
149+ expect ( searchArea . getByRole ( "button" , { name : "Search" } ) ) . toHaveTextContent ( "Search" ) ;
150+ } ) ;
151+ it ( "should render a text='Search' when technologies != []" , ( ) => {
152+ const searchArea = renderWithStoreAndTheme (
153+ < RouteWrappedContent >
154+ < SearchAreaWrapper
155+ technologies = { [ "tech1" , "tech2" ] }
156+ />
157+ </ RouteWrappedContent > ,
158+ { initialState, theme }
159+ ) ;
160+
161+ expect ( searchArea . getByRole ( "button" , { name : "Search" } ) ) . toHaveTextContent ( "Search" ) ;
162+ } ) ;
163+ it ( "should render a text='Search' when jobType != INITIAL_JOB_TYPE" , ( ) => {
164+ const searchArea = renderWithStoreAndTheme (
165+ < RouteWrappedContent >
166+ < SearchAreaWrapper
167+ jobType = { "JOB" }
168+ />
169+ </ RouteWrappedContent > ,
170+ { initialState, theme }
171+ ) ;
172+
173+ expect ( searchArea . getByRole ( "button" , { name : "Search" } ) ) . toHaveTextContent ( "Search" ) ;
174+ } ) ;
175+ it ( "should render a text='Search' when showJobDurationSlider = true " , ( ) => {
176+ const searchArea = renderWithStoreAndTheme (
177+ < RouteWrappedContent >
178+ < SearchAreaWrapper
179+ showJobDurationSlider = { true }
180+ />
181+ </ RouteWrappedContent > ,
182+ { initialState, theme }
183+ ) ;
184+
185+ expect ( searchArea . getByRole ( "button" , { name : "Search" } ) ) . toHaveTextContent ( "Search" ) ;
186+ } ) ;
58187 } ) ;
59188
60189 describe ( "interaction" , ( ) => {
@@ -80,6 +209,7 @@ describe("SearchArea", () => {
80209 setJobDuration = { ( ) => { } }
81210 setFields = { ( ) => { } }
82211 setJobType = { ( ) => { } }
212+ setShowHidden = { ( ) => { } }
83213 onSubmit = { onSubmit }
84214 fields = { [ ] }
85215 technologies = { [ ] }
@@ -124,15 +254,13 @@ describe("SearchArea", () => {
124254
125255 renderWithStoreAndTheme (
126256 < RouteWrappedContent url = { url } >
127- < SearchArea
257+ < SearchAreaWrapper
128258 onSubmit = { onSubmit }
129259 setSearchValue = { setSearchValue }
130260 setJobType = { setJobType }
131261 setJobDuration = { setJobDuration }
132262 setShowJobDurationSlider = { setShowJobDurationSlider }
133- fields = { [ ] }
134263 setFields = { setFields }
135- technologies = { [ ] }
136264 setTechs = { setTechs }
137265 />
138266 </ RouteWrappedContent > ,
@@ -157,6 +285,7 @@ describe("SearchArea", () => {
157285 jobDuration : [ 1 , 2 ] ,
158286 fields : [ "field1" , "field2" ] ,
159287 technologies : [ "tech1" , "tech2" ] ,
288+ showHidden : true ,
160289 } ,
161290 } ;
162291 expect ( mapStateToProps ( mockState ) ) . toEqual ( {
@@ -166,6 +295,7 @@ describe("SearchArea", () => {
166295 jobMaxDuration : 2 ,
167296 fields : [ "field1" , "field2" ] ,
168297 technologies : [ "tech1" , "tech2" ] ,
298+ showHidden : true ,
169299 } ) ;
170300 } ) ;
171301
@@ -194,6 +324,10 @@ describe("SearchArea", () => {
194324 props . setShowJobDurationSlider ( filterJobDuration ) ;
195325 expect ( dispatch ) . toHaveBeenCalledWith ( setShowJobDurationSlider ( false ) ) ;
196326
327+ const showHidden = true ;
328+ props . setShowHidden ( showHidden ) ;
329+ expect ( dispatch ) . toHaveBeenCalledWith ( setShowHidden ( true ) ) ;
330+
197331 dispatch . mockClear ( ) ;
198332 props . resetAdvancedSearchFields ( ) ;
199333 expect ( dispatch ) . toHaveBeenCalled ( ) ;
0 commit comments