File size: 1,561 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
import {
	GRAVATAR_UPLOAD_RECEIVE,
	GRAVATAR_UPLOAD_REQUEST,
	GRAVATAR_UPLOAD_REQUEST_SUCCESS,
	GRAVATAR_UPLOAD_REQUEST_FAILURE,
} from 'calypso/state/action-types';
import reducer, { isUploading, tempImage } from '../reducer';

describe( 'reducer', () => {
	test( 'exports expected reducer keys', () => {
		const state = reducer( undefined, {} );
		expect( state ).toHaveProperty( 'isUploading' );
		expect( state ).toHaveProperty( 'tempImage' );
	} );

	describe( '#isUploading', () => {
		test( 'returns false by default', () => {
			const state = isUploading( undefined, {} );
			expect( state ).toBe( false );
		} );

		test( 'returns true when request is made', () => {
			expect(
				isUploading( false, {
					type: GRAVATAR_UPLOAD_REQUEST,
				} )
			).toBe( true );
		} );

		test( 'returns false when request succeeds', () => {
			expect(
				isUploading( true, {
					type: GRAVATAR_UPLOAD_REQUEST_SUCCESS,
				} )
			).toBe( false );
		} );

		test( 'returns false when request fails', () => {
			expect(
				isUploading( true, {
					type: GRAVATAR_UPLOAD_REQUEST_FAILURE,
				} )
			).toBe( false );
		} );
	} );

	describe( '#tempImage', () => {
		const imageSrc = 'image';

		test( 'returns empty object by default', () => {
			const state = tempImage( undefined, {} );
			expect( state ).toBe( null );
		} );

		test( 'returns object with image src when response is received', () => {
			const state = tempImage( undefined, {
				type: GRAVATAR_UPLOAD_RECEIVE,
				src: imageSrc,
			} );
			expect( state ).toBe( imageSrc );
		} );
	} );
} );