File size: 1,224 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
import { getPluginStatusesByType } from 'calypso/state/plugins/installed/selectors';
import { getPluginActionStatuses } from '../get-plugin-action-statuses';

jest.mock( 'calypso/state/plugins/installed/selectors', () => ( {
	...jest.requireActual( 'calypso/state/plugins/installed/selectors' ),
	getPluginStatusesByType: jest.fn(),
} ) );

const FAKE_RESULT = { siteId: '', pluginId: '' };

describe( 'getPluginActionStatuses', () => {
	beforeEach( () => {
		jest.resetAllMocks();
	} );

	it.each( [ [ 'inProgress' ], [ 'completed' ], [ 'error' ], [ 'up-to-date' ] ] )(
		'returns all "%s" statuses',
		( status ) => {
			getPluginStatusesByType.mockImplementation( ( state, type ) =>
				type === status ? [ FAKE_RESULT ] : []
			);

			const results = getPluginActionStatuses( {} );
			expect( results.length ).toBe( 1 );
			expect( results[ 0 ] ).toBe( FAKE_RESULT );
		}
	);

	it.each( [ [ 'mystatus' ], [ 'elderberries' ], [ 'hamster' ] ] )(
		'does not return other status types',
		( status ) => {
			getPluginStatusesByType.mockImplementation( ( state, type ) =>
				type === status ? [ FAKE_RESULT ] : []
			);

			const results = getPluginActionStatuses( {} );
			expect( results.length ).toBe( 0 );
		}
	);
} );