@@ -24,7 +24,17 @@ beforeAll(() => server.listen());
2424afterEach ( ( ) => server . resetHandlers ( ) ) ;
2525afterAll ( ( ) => server . close ( ) ) ;
2626
27- const Form = ( { name = "" , url = "" , options = [ ] , type = "" , styles, handleChange, disabled, value } ) => {
27+ const Form = ( {
28+ name = "" ,
29+ url = "" ,
30+ options = [ ] ,
31+ type = "" ,
32+ styles,
33+ handleChange,
34+ disabled,
35+ value,
36+ caseInsensitive
37+ } ) => {
2838 const [ make , setMake ] = React . useState ( ) ;
2939 const [ formData , setFormData ] = React . useState ( ) ;
3040 const handleSubmit = ( e ) => {
@@ -43,6 +53,7 @@ const Form = ({ name = "", url = "", options = [], type = "", styles, handleChan
4353 options = { options }
4454 styles = { styles }
4555 disabled = { disabled ? true : false }
56+ caseInsensitive = { caseInsensitive }
4657 />
4758 < button > Submit</ button >
4859 </ form >
@@ -767,4 +778,85 @@ test("Input value should update if changed -- client", async () => {
767778 expect ( countryAnnouncement ) . not . toHaveTextContent (
768779 "3 suggestions displayed. To navigate, use up and down arrow keys."
769780 ) ;
781+ } ) ;
782+ describe ( "Client version should perform case-insensitive matche if caseInsensitive is true" , async ( ) => {
783+ test ( "when options are strings" , ( ) => {
784+ const options = [ "abba" , "ABB" , "aBbott" , "Abberette" ] ;
785+ render ( < Form options = { options } name = "Name" caseInsensitive = { true } /> ) ;
786+ const input = screen . getByRole ( "textbox" , { name : "Name" } ) ;
787+ fireEvent . change ( input , { target : { value : "Abb" } } ) ;
788+ expect ( screen . getByRole ( "option" , { name : "abba" } ) ) ;
789+ expect ( screen . getByRole ( "option" , { name : "ABB" } ) ) ;
790+ expect ( screen . getByRole ( "option" , { name : "aBbott" } ) ) ;
791+ expect ( screen . getByRole ( "option" , { name : "Abberette" } ) ) ;
792+ } ) ;
793+ test ( "when options are objects" , ( ) => {
794+ const options = [
795+ { name : "abba" , value : "abba" } ,
796+ { name : "ABB" , value : "ABB" } ,
797+ { name : "aBbott" , value : "aBbott" } ,
798+ { name : "Abberette" , value : "Abberette" }
799+ ] ;
800+ render ( < Form options = { options } name = "Name" caseInsensitive = { true } /> ) ;
801+ const input = screen . getByRole ( "textbox" , { name : "Name" } ) ;
802+ fireEvent . change ( input , { target : { value : "Abb" } } ) ;
803+ expect ( screen . getByRole ( "option" , { name : "abba" } ) ) ;
804+ expect ( screen . getByRole ( "option" , { name : "ABB" } ) ) ;
805+ expect ( screen . getByRole ( "option" , { name : "aBbott" } ) ) ;
806+ expect ( screen . getByRole ( "option" , { name : "Abberette" } ) ) ;
807+ } ) ;
808+ } ) ;
809+ describe ( "Client version should perform case-insensitive match by default" , async ( ) => {
810+ test ( "when options are strings" , ( ) => {
811+ const options = [ "abba" , "ABB" , "aBbott" , "Abberette" ] ;
812+ render ( < Form options = { options } name = "Name" /> ) ;
813+ const input = screen . getByRole ( "textbox" , { name : "Name" } ) ;
814+ fireEvent . change ( input , { target : { value : "Abb" } } ) ;
815+ expect ( screen . getByRole ( "option" , { name : "abba" } ) ) ;
816+ expect ( screen . getByRole ( "option" , { name : "ABB" } ) ) ;
817+ expect ( screen . getByRole ( "option" , { name : "aBbott" } ) ) ;
818+ expect ( screen . getByRole ( "option" , { name : "Abberette" } ) ) ;
819+ } ) ;
820+ test ( "when options are objects" , ( ) => {
821+ const options = [
822+ { name : "abba" , value : "abba" } ,
823+ { name : "ABB" , value : "ABB" } ,
824+ { name : "aBbott" , value : "aBbott" } ,
825+ { name : "Abberette" , value : "Abberette" }
826+ ] ;
827+ render ( < Form options = { options } name = "Name" /> ) ;
828+ const input = screen . getByRole ( "textbox" , { name : "Name" } ) ;
829+ fireEvent . change ( input , { target : { value : "Abb" } } ) ;
830+ expect ( screen . getByRole ( "option" , { name : "abba" } ) ) ;
831+ expect ( screen . getByRole ( "option" , { name : "ABB" } ) ) ;
832+ expect ( screen . getByRole ( "option" , { name : "aBbott" } ) ) ;
833+ expect ( screen . getByRole ( "option" , { name : "Abberette" } ) ) ;
834+ } ) ;
835+ } ) ;
836+ describe ( "Client version should not perform case-insensitive matches if caseInsensitive is false" , async ( ) => {
837+ test ( "when options are strings" , ( ) => {
838+ const options = [ "abba" , "ABB" , "aBbott" , "Abberette" ] ;
839+ render ( < Form options = { options } name = "Name" caseInsensitive = { false } /> ) ;
840+ const input = screen . getByRole ( "textbox" , { name : "Name" } ) ;
841+ fireEvent . change ( input , { target : { value : "a" } } ) ;
842+ expect ( screen . getByRole ( "option" , { name : "abba" } ) ) ;
843+ expect ( screen . getByRole ( "option" , { name : "aBbott" } ) ) ;
844+ expect ( screen . queryByRole ( "option" , { name : "ABB" } ) ) . toBeNull ( ) ;
845+ expect ( screen . queryByRole ( "option" , { name : "Abberette" } ) ) . toBeNull ( ) ;
846+ } ) ;
847+ test ( "when options are objects" , ( ) => {
848+ const options = [
849+ { name : "abba" , value : "abba" } ,
850+ { name : "ABB" , value : "ABB" } ,
851+ { name : "aBbott" , value : "aBbott" } ,
852+ { name : "Abberette" , value : "Abberette" }
853+ ] ;
854+ render ( < Form options = { options } name = "Name" caseInsensitive = { false } /> ) ;
855+ const input = screen . getByRole ( "textbox" , { name : "Name" } ) ;
856+ fireEvent . change ( input , { target : { value : "a" } } ) ;
857+ expect ( screen . getByRole ( "option" , { name : "abba" } ) ) ;
858+ expect ( screen . getByRole ( "option" , { name : "aBbott" } ) ) ;
859+ expect ( screen . queryByRole ( "option" , { name : "ABB" } ) ) . toBeNull ( ) ;
860+ expect ( screen . queryByRole ( "option" , { name : "Abberette" } ) ) . toBeNull ( ) ;
861+ } ) ;
770862} ) ;
0 commit comments