File size: 4,771 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
import {
getCurrentUserId,
getCurrentUser,
getCurrentUserLocale,
getCurrentUserDate,
isUserLoggedIn,
getCurrentUserEmail,
isCurrentUserBootstrapped,
} from '../selectors';
describe( 'selectors', () => {
describe( 'getCurrentUserId()', () => {
test( 'should return the current user ID', () => {
const currentUserId = getCurrentUserId( {
currentUser: {
id: 73705554,
},
} );
expect( currentUserId ).toBe( 73705554 );
} );
} );
describe( 'isUserLoggedIn', () => {
test( 'should return true if we have a non-null user id', () => {
expect(
isUserLoggedIn( {
currentUser: { id: 1234 },
} )
).toBe( true );
} );
test( 'should return false if we have a null user id', () => {
expect(
isUserLoggedIn( {
currentUser: { id: null },
} )
).toBe( false );
} );
} );
describe( '#getCurrentUser()', () => {
test( 'should return null if no current user', () => {
const selected = getCurrentUser( {
currentUser: {
id: null,
},
} );
expect( selected ).toBeNull();
} );
test( 'should return the object for the current user', () => {
const selected = getCurrentUser( {
currentUser: {
id: 73705554,
user: { ID: 73705554, login: 'testonesite2014' },
},
} );
expect( selected ).toEqual( { ID: 73705554, login: 'testonesite2014' } );
} );
} );
describe( '#getCurrentUserLocale', () => {
test( 'should return null if the current user is not set', () => {
const locale = getCurrentUserLocale( {
currentUser: {
id: null,
},
} );
expect( locale ).toBeNull();
} );
test( 'should return null if the current user locale slug is not set', () => {
const locale = getCurrentUserLocale( {
currentUser: {
id: 73705554,
user: { ID: 73705554, login: 'testonesite2014' },
},
} );
expect( locale ).toBeNull();
} );
test( 'should return the current user locale slug', () => {
const locale = getCurrentUserLocale( {
currentUser: {
id: 73705554,
user: { ID: 73705554, login: 'testonesite2014', localeSlug: 'fr' },
},
} );
expect( locale ).toBe( 'fr' );
} );
} );
describe( 'getCurrentUserDate()', () => {
test( 'should return the current user registration date', () => {
const currentUserDate = getCurrentUserDate( {
currentUser: {
id: 73705554,
user: { ID: 73705554, login: 'testonesite2014', date: '2014-10-18T17:14:52+00:00' },
},
} );
expect( currentUserDate ).toBe( '2014-10-18T17:14:52+00:00' );
} );
test( 'should return null if the registration date is missing', () => {
const currentUserDate = getCurrentUserDate( {
currentUser: {
id: 73705554,
user: { ID: 73705554, login: 'testonesite2014' },
},
} );
expect( currentUserDate ).toBeNull();
} );
test( 'should return null if the user is missing', () => {
const currentUserDate = getCurrentUserDate( {
currentUser: {
id: 73705554,
user: { ID: 12345678, login: 'testuser' },
},
} );
expect( currentUserDate ).toBeNull();
} );
} );
describe( 'getCurrentUserEmail', () => {
test( 'should return a null it the current user is not there for whatever reasons', () => {
const selected = getCurrentUserEmail( {
currentUser: {
id: 123456,
},
} );
expect( selected ).toBeNull();
} );
test( 'should return a null if the primary email is not set', () => {
const selected = getCurrentUserEmail( {
currentUser: {
id: 123456,
user: { ID: 123456 },
},
} );
expect( selected ).toBeNull();
} );
test( 'should return value if the email is set', () => {
const testEmail = 'test@example.com';
const selected = getCurrentUserEmail( {
currentUser: {
id: 123456,
user: {
ID: 123456,
email: testEmail,
},
},
} );
expect( selected ).toBe( testEmail );
} );
} );
describe( 'isCurrentUserBootstrapped', () => {
test( 'should return false it the current user is not there for whatever reasons', () => {
const selected = isCurrentUserBootstrapped( {
currentUser: {
id: 123456,
},
} );
expect( selected ).toBe( false );
} );
test( 'should return false if the user was not bootstrapped', () => {
const selected = isCurrentUserBootstrapped( {
currentUser: {
id: 123456,
user: {
ID: 123456,
bootstrapped: false,
},
},
} );
expect( selected ).toBe( false );
} );
test( 'should return true if the user was bootstrapped', () => {
const selected = isCurrentUserBootstrapped( {
currentUser: {
id: 123456,
user: {
ID: 123456,
bootstrapped: true,
},
},
} );
expect( selected ).toBe( true );
} );
} );
} );
|