11import React from "react" ;
22import { render , fireEvent } from "@testing-library/react" ;
3- import {
4- InputFormField ,
5- InvalidInputFormValueClass ,
6- ShowLabelForScreenReadersOnlyClass ,
7- } from "./input-form-field" ;
3+ import { InputFormField , InputFormFieldInvalidClass } from "./input-form-field" ;
84import faker from "faker" ;
5+ import { AccessibilityLabels } from "../../atoms/constants/accessibility-labels" ;
96
107describe ( "InputFormField" , ( ) => {
118 test ( "when default props, renders input with label" , ( ) => {
@@ -23,22 +20,21 @@ describe("InputFormField", () => {
2320
2421 test ( "when errorsMessages prop set, renders with error messages" , ( ) => {
2522 // Arrange
23+ const errorMessages = [ faker . random . words ( ) , faker . random . words ( ) ] ;
2624 const label = faker . random . words ( ) ;
27- const firstErrorMessage = faker . random . words ( ) ;
28- const secondErrorMessage = faker . random . words ( ) ;
2925
3026 // Act
3127 const { getByText } = render (
3228 < InputFormField
33- errorMessages = { [ firstErrorMessage , secondErrorMessage ] }
29+ errorMessages = { errorMessages }
3430 label = { label }
3531 onChange = { ( ) => { } }
3632 />
3733 ) ;
3834
3935 // Assert
40- expect ( getByText ( firstErrorMessage ) ) . not . toBeNil ( ) ;
41- expect ( getByText ( secondErrorMessage ) ) . not . toBeNil ( ) ;
36+ expect ( getByText ( errorMessages [ 0 ] ) ) . not . toBeNil ( ) ;
37+ expect ( getByText ( errorMessages [ 1 ] ) ) . not . toBeNil ( ) ;
4238 } ) ;
4339
4440 test ( "when errorsMessage prop set, renders with error message" , ( ) => {
@@ -59,7 +55,7 @@ describe("InputFormField", () => {
5955 expect ( getByText ( testErrorMessage ) ) . not . toBeNil ( ) ;
6056 } ) ;
6157
62- test ( `when isValid prop set to false, renders with ${ InvalidInputFormValueClass } class name` , ( ) => {
58+ test ( `when isValid prop set to false, renders with ${ InputFormFieldInvalidClass } class name` , ( ) => {
6359 // Arrange
6460 const label = faker . random . words ( ) ;
6561
@@ -68,14 +64,14 @@ describe("InputFormField", () => {
6864 < InputFormField isValid = { false } label = { label } onChange = { ( ) => { } } />
6965 ) ;
7066 const result = container . getElementsByClassName (
71- InvalidInputFormValueClass
67+ InputFormFieldInvalidClass
7268 ) ;
7369
7470 // Assert
7571 expect ( result ) . toHaveLength ( 1 ) ;
7672 } ) ;
7773
78- test ( `when isValid prop set to true, renders without ${ InvalidInputFormValueClass } class name` , ( ) => {
74+ test ( `when isValid prop set to true, renders without ${ InputFormFieldInvalidClass } class name` , ( ) => {
7975 // Arrange
8076 const label = faker . random . words ( ) ;
8177
@@ -84,7 +80,7 @@ describe("InputFormField", () => {
8480 < InputFormField isValid = { true } label = { label } onChange = { ( ) => { } } />
8581 ) ;
8682 const result = container . getElementsByClassName (
87- InvalidInputFormValueClass
83+ InputFormFieldInvalidClass
8884 ) ;
8985
9086 // Assert
@@ -106,7 +102,7 @@ describe("InputFormField", () => {
106102 expect ( htmlLabelTag [ 0 ] . textContent ) . toContain ( requiredText ) ;
107103 } ) ;
108104
109- test ( `when showLabelForScreenReadersOnly prop set, renders with ${ ShowLabelForScreenReadersOnlyClass } class name` , ( ) => {
105+ test ( `when showLabelForScreenReadersOnly prop set, renders with ${ AccessibilityLabels . ScreenReadersOnlyClass } class name` , ( ) => {
110106 // Arrange
111107 const label = faker . random . words ( ) ;
112108
@@ -122,7 +118,7 @@ describe("InputFormField", () => {
122118
123119 // Assert
124120 expect ( htmlLabelTag [ 0 ] . classList ) . toContain (
125- ShowLabelForScreenReadersOnlyClass
121+ AccessibilityLabels . ScreenReadersOnlyClass
126122 ) ;
127123 } ) ;
128124
0 commit comments