File size: 3,087 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
/**
 * @jest-environment jsdom
 */
// @ts-nocheck - TODO: Fix TypeScript issues
import { render } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import {
	ACTIVATE_PLUGIN,
	DEACTIVATE_PLUGIN,
	ENABLE_AUTOUPDATE_PLUGIN,
	DISABLE_AUTOUPDATE_PLUGIN,
	REMOVE_PLUGIN,
} from 'calypso/lib/plugins/constants';
import PluginActionStatus from '../plugin-action-status';
import { plugin, site } from './utils/constants';

const currentStatus = {
	action: ACTIVATE_PLUGIN,
	pluginId: plugin.id,
	siteId: site.ID,
	status: 'inProgress',
};

const props = {
	currentSiteStatuses: [ currentStatus ],
	selectedSite: site,
};

describe( '<PluginActionStatus>', () => {
	const mockStore = configureStore();
	const store = mockStore( {} );

	test( 'should render correctly and show activating status on single-site', () => {
		const { container } = render(
			<Provider store={ store }>
				<PluginActionStatus { ...props } />
			</Provider>
		);

		const [ status ] = container.getElementsByClassName( 'plugin-action-status' );
		expect( status.textContent ).toEqual( 'Activating' );
	} );

	test( 'should render correctly and show removing status on single-site', () => {
		currentStatus.action = REMOVE_PLUGIN;
		const { container } = render(
			<Provider store={ store }>
				<PluginActionStatus { ...props } />
			</Provider>
		);

		const [ status ] = container.getElementsByClassName( 'plugin-action-status' );
		expect( status.textContent ).toEqual( 'Removing Plugin' );
	} );

	test( 'should render correctly and show deactivated status on single-site', () => {
		currentStatus.action = DEACTIVATE_PLUGIN;
		currentStatus.status = 'completed';
		const { container } = render(
			<Provider store={ store }>
				<PluginActionStatus { ...props } />
			</Provider>
		);
		const [ status ] = container.getElementsByClassName( 'plugin-action-status' );
		expect( status.textContent ).toEqual( 'Deactivated' );
	} );

	test( 'should render correctly and show failed to enable auto-update status on multi-site(1 site)', () => {
		const props = { currentSiteStatuses: [ currentStatus ] };
		currentStatus.action = ENABLE_AUTOUPDATE_PLUGIN;
		currentStatus.status = 'error';
		const { container } = render(
			<Provider store={ store }>
				<PluginActionStatus { ...props } />
			</Provider>
		);
		const [ status ] = container.getElementsByClassName( 'plugin-action-status' );
		expect( status.textContent ).toEqual( 'Failed to enable auto-updates on 1 site' );
	} );

	test( 'should render correctly and show failed to enable auto-update status on multi-site(2 sites)', () => {
		const props = { currentSiteStatuses: [ currentStatus, currentStatus ] };
		currentStatus.action = DISABLE_AUTOUPDATE_PLUGIN;
		const { container } = render(
			<Provider store={ store }>
				<PluginActionStatus { ...props } />
			</Provider>
		);
		const [ status ] = container.getElementsByClassName( 'plugin-action-status' );
		expect( status.textContent ).toEqual( 'Failed to disable auto-updates on 2 sites' );
	} );
} );