1+ import React from 'react' ;
2+ import SettingsAddress from '../SettingsAddress' ;
3+ import { mountWithIntl } from 'enzyme-react-intl' ;
4+
5+ describe ( '<SettingsSelfExclusion />' , ( ) => {
6+ // test max_balance as an input which should be number and being validated (other inputs behave like this too)
7+ it ( 'Component should be rendered' , ( ) => {
8+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
9+
10+ expect ( wrapper . type ( ) ) . toBeDefined ( ) ;
11+ } ) ;
12+
13+ it ( 'address line 1 should have required error when input is empty' , ( ) => {
14+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
15+ const addressLine1 = wrapper . find ( '#address_line_1' ) ;
16+ addressLine1 . node . value = null ;
17+ addressLine1 . simulate ( 'change' ) ;
18+ const errors = wrapper . state ( 'errors' ) ;
19+
20+ expect ( errors . address_line_1 [ 0 ] ) . toEqual ( 'This field is required.' ) ;
21+ } ) ;
22+
23+ it ( 'address line 1 should be valid when format is valid' , ( ) => {
24+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
25+ const addressLine1 = wrapper . find ( '#address_line_1' ) ;
26+ addressLine1 . node . value = 'test 123 test' ;
27+ addressLine1 . simulate ( 'change' ) ;
28+ const errors = wrapper . state ( 'errors' ) ;
29+
30+ expect ( errors . address_line_1 ) . toBeUndefined ( ) ;
31+ } ) ;
32+
33+ it ( 'address line 1 should not be valid when format is not valid' , ( ) => {
34+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
35+ const addressLine1 = wrapper . find ( '#address_line_1' ) ;
36+ addressLine1 . node . value = 'test " test' ;
37+ addressLine1 . simulate ( 'change' ) ;
38+ const errors = wrapper . state ( 'errors' ) ;
39+
40+ expect ( errors . address_line_1 [ 0 ] ) . toEqual ( 'Only letters, numbers, space, hyphen, period, and apostrophe are allowed.' ) ;
41+ } ) ;
42+
43+ it ( 'address line 2 should not have required error when input is empty' , ( ) => {
44+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
45+ const addressLine2 = wrapper . find ( '#address_line_2' ) ;
46+ addressLine2 . node . value = null ;
47+ addressLine2 . simulate ( 'change' ) ;
48+ const errors = wrapper . state ( 'errors' ) ;
49+
50+ expect ( errors . address_line_2s ) . toBeUndefined ( ) ;
51+ } ) ;
52+
53+ it ( 'address city should be valid when format is valid' , ( ) => {
54+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
55+ const addressCity = wrapper . find ( '#address_city' ) ;
56+ addressCity . node . value = 'test test' ;
57+ addressCity . simulate ( 'change' ) ;
58+ const errors = wrapper . state ( 'errors' ) ;
59+
60+ expect ( errors . address_city ) . toBeUndefined ( ) ;
61+ } ) ;
62+
63+ it ( 'address city should not be valid when format is not valid' , ( ) => {
64+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
65+ const addressCity = wrapper . find ( '#address_city' ) ;
66+ addressCity . node . value = 'test " test' ;
67+ addressCity . simulate ( 'change' ) ;
68+ const errors = wrapper . state ( 'errors' ) ;
69+
70+ expect ( errors . address_city [ 0 ] ) . toEqual ( 'Only letters, space, hyphen, period, and apostrophe are allowed.' ) ;
71+ } ) ;
72+
73+ it ( 'address city should be valid when format is valid' , ( ) => {
74+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
75+ const addressPostCode = wrapper . find ( '#address_postcode' ) ;
76+ addressPostCode . node . value = 'test 123 test' ;
77+ addressPostCode . simulate ( 'change' ) ;
78+ const errors = wrapper . state ( 'errors' ) ;
79+
80+ expect ( errors . address_postcode ) . toBeUndefined ( ) ;
81+ } ) ;
82+
83+ it ( 'address city should not be valid when format is not valid' , ( ) => {
84+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
85+ const addressPostCode = wrapper . find ( '#address_postcode' ) ;
86+ addressPostCode . node . value = 'test " test' ;
87+ addressPostCode . simulate ( 'change' ) ;
88+ const errors = wrapper . state ( 'errors' ) ;
89+
90+ expect ( errors . address_postcode [ 0 ] ) . toEqual ( 'Only letters, numbers, space, and hyphen are allowed.' ) ;
91+ } ) ;
92+
93+ it ( 'phone should be valid when format is valid' , ( ) => {
94+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
95+ const phone = wrapper . find ( '#phone' ) ;
96+ phone . node . value = '123 456 789' ;
97+ phone . simulate ( 'change' ) ;
98+ const errors = wrapper . state ( 'errors' ) ;
99+
100+ expect ( errors . phone ) . toBeUndefined ( ) ;
101+ } ) ;
102+
103+ it ( 'phone should not be valid when format is not valid' , ( ) => {
104+ const wrapper = mountWithIntl ( < SettingsAddress /> ) ;
105+ const phone = wrapper . find ( '#phone' ) ;
106+ phone . node . value = 'test 123' ;
107+ phone . simulate ( 'change' ) ;
108+ const errors = wrapper . state ( 'errors' ) ;
109+
110+ expect ( errors . phone [ 0 ] ) . toEqual ( 'Only numbers and spaces are allowed.' ) ;
111+ } ) ;
112+
113+ } ) ;
0 commit comments