File size: 3,478 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
import { last } from 'lodash';
import { REASONS_FOR_MANUAL_RENEWAL } from '../constants';
import {
	wasImmediateLoginAttempted,
	wasManualRenewalImmediateLoginAttempted,
	wasImmediateLoginSuccessfulAccordingToClient,
	getImmediateLoginReason,
	getImmediateLoginEmail,
	getImmediateLoginLocale,
} from '../selectors';

describe( 'immediate-login/selectors', () => {
	describe( 'wasImmediateLoginAttempted', () => {
		test( 'should return correct value from state [1]', () => {
			expect( wasImmediateLoginAttempted( {} ) ).toEqual( false );
		} );

		test( 'should return correct value from state [2]', () => {
			expect( wasImmediateLoginAttempted( { immediateLogin: { attempt: false } } ) ).toEqual(
				false
			);
		} );

		test( 'should return correct value from state [3]', () => {
			expect( wasImmediateLoginAttempted( { immediateLogin: { attempt: true } } ) ).toEqual( true );
		} );
	} );
	describe( 'wasManualRenewalImmediateLoginAttempted', () => {
		test( 'should return correct value from state [1]', () => {
			expect( wasManualRenewalImmediateLoginAttempted( {} ) ).toEqual( false );
		} );

		test( 'should return correct value from state [2]', () => {
			expect(
				wasManualRenewalImmediateLoginAttempted( {
					immediateLogin: { reason: 'test reason' },
				} )
			).toEqual( false );
		} );

		test( 'should return correct value from state [3]', () => {
			expect(
				wasManualRenewalImmediateLoginAttempted( {
					immediateLogin: { reason: REASONS_FOR_MANUAL_RENEWAL[ 0 ] },
				} )
			).toEqual( true );
		} );

		test( 'should return correct value from state [4]', () => {
			expect(
				wasManualRenewalImmediateLoginAttempted( {
					immediateLogin: { reason: last( REASONS_FOR_MANUAL_RENEWAL ) },
				} )
			).toEqual( true );
		} );
	} );
	describe( 'wasImmediateLoginSuccessfulAccordingToClient', () => {
		test( 'should return correct value from state [1]', () => {
			expect( wasImmediateLoginSuccessfulAccordingToClient( {} ) ).toEqual( false );
		} );

		test( 'should return correct value from state [2]', () => {
			expect(
				wasImmediateLoginSuccessfulAccordingToClient( { immediateLogin: { success: false } } )
			).toEqual( false );
		} );

		test( 'should return correct value from state [3]', () => {
			expect(
				wasImmediateLoginSuccessfulAccordingToClient( { immediateLogin: { success: true } } )
			).toEqual( true );
		} );
	} );
	describe( 'getImmediateLoginReason', () => {
		test( 'should return correct value from state [1]', () => {
			expect( getImmediateLoginReason( {} ) ).toEqual( null );
		} );

		test( 'should return correct value from state [2]', () => {
			expect( getImmediateLoginReason( { immediateLogin: { reason: 'test reason' } } ) ).toEqual(
				'test reason'
			);
		} );
	} );
	describe( 'getImmediateLoginEmail', () => {
		test( 'should return correct value from state [1]', () => {
			expect( getImmediateLoginEmail( {} ) ).toEqual( null );
		} );

		test( 'should return correct value from state [2]', () => {
			expect( getImmediateLoginEmail( { immediateLogin: { email: 'test@example.com' } } ) ).toEqual(
				'test@example.com'
			);
		} );
	} );
	describe( 'getImmediateLoginLocale', () => {
		test( 'should return correct value from state [1]', () => {
			expect( getImmediateLoginLocale( {} ) ).toEqual( null );
		} );

		test( 'should return correct value from state [2]', () => {
			expect( getImmediateLoginLocale( { immediateLogin: { locale: 'fr' } } ) ).toEqual( 'fr' );
		} );
	} );
} );