File size: 3,923 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import {
	CONCIERGE_SIGNUP_FORM_UPDATE,
	CONCIERGE_UPDATE_BOOKING_STATUS,
} from 'calypso/state/action-types';
import signupForm, {
	firstname,
	lastname,
	timezone,
	message,
	phoneNumber,
	countryCode,
	phoneNumberWithoutCountryCode,
	status,
} from '../reducer';

describe( 'concierge/signupForm/reducer', () => {
	const mockSignupForm = {
		firstname: 'Foo',
		lastname: 'Bar',
		timezone: 'Asia/Kolkata',
		message: 'hello',
		phoneNumber: '+910123456789',
		countryCode: 'IN',
		phoneNumberWithoutCountryCode: '987654321',
		status: 'booking',
	};
	const mockStatus = 'booking';

	const updateForm = {
		type: CONCIERGE_SIGNUP_FORM_UPDATE,
		signupForm: mockSignupForm,
	};

	const updateStatus = {
		type: CONCIERGE_UPDATE_BOOKING_STATUS,
		status: mockStatus,
	};

	describe( 'firstname', () => {
		test( 'should be default as empty string.', () => {
			expect( firstname( undefined, {} ) ).toEqual( '' );
		} );

		test( 'should return the firstname of the update action.', () => {
			expect( firstname( {}, updateForm ) ).toEqual( mockSignupForm.firstname );
		} );
	} );

	describe( 'lastname', () => {
		test( 'should be default as empty string.', () => {
			expect( lastname( undefined, {} ) ).toEqual( '' );
		} );

		test( 'should return the lastname of the update action.', () => {
			expect( lastname( {}, updateForm ) ).toEqual( mockSignupForm.lastname );
		} );
	} );

	describe( 'timezone', () => {
		test( 'should use the default detected timezone.', () => {
			expect( timezone( undefined, {} ) ).toEqual( 'UTC' );
		} );

		test( 'should return the timezone of the update action', () => {
			expect( timezone( {}, updateForm ) ).toEqual( mockSignupForm.timezone );
		} );
	} );

	describe( 'message', () => {
		test( 'should be defaulted as empty string.', () => {
			expect( message( undefined, {} ) ).toEqual( '' );
		} );

		test( 'should return the message of the update action', () => {
			expect( message( {}, updateForm ) ).toEqual( mockSignupForm.message );
		} );
	} );

	describe( 'phoneNumber', () => {
		test( 'should be defaulted as empty string.', () => {
			expect( phoneNumber( undefined, {} ) ).toEqual( '' );
		} );

		test( 'should return the phone number of the update action', () => {
			expect( phoneNumber( {}, updateForm ) ).toEqual( mockSignupForm.phoneNumber );
		} );
	} );

	describe( 'countryCode', () => {
		test( 'should be defaulted as empty string.', () => {
			expect( countryCode( undefined, {} ) ).toEqual( '' );
		} );

		test( 'should return the country code of the update action', () => {
			expect( countryCode( {}, updateForm ) ).toEqual( mockSignupForm.countryCode );
		} );
	} );

	describe( 'phoneNumberWithoutCountryCode', () => {
		test( 'should be defaulted as empty string.', () => {
			expect( phoneNumberWithoutCountryCode( undefined, {} ) ).toEqual( '' );
		} );

		test( 'should return the phone number without country code of the update action', () => {
			expect( phoneNumberWithoutCountryCode( {}, updateForm ) ).toEqual(
				mockSignupForm.phoneNumberWithoutCountryCode
			);
		} );
	} );

	describe( 'status', () => {
		test( 'should be defaulted as null', () => {
			expect( status( undefined, {} ) ).toBeNull();
		} );

		test( 'should return the status of the update action', () => {
			expect( status( {}, updateStatus ) ).toEqual( mockStatus );
		} );
	} );

	describe( 'signupForm', () => {
		test( 'should combine all defaults as null.', () => {
			expect( signupForm( undefined, {} ) ).toEqual( {
				firstname: '',
				lastname: '',
				timezone: 'UTC',
				message: '',
				phoneNumber: '',
				countryCode: '',
				phoneNumberWithoutCountryCode: '',
				status: null,
			} );
		} );

		test( 'should return the proper message and timezone of the update action', () => {
			const expectedFields = {
				...mockSignupForm,
				status: null,
			};
			expect( signupForm( {}, updateForm ) ).toEqual( expectedFields );
		} );
	} );
} );