-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathpost-publish-button-or-toggle.js
78 lines (68 loc) · 2.21 KB
/
post-publish-button-or-toggle.js
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
/**
* External dependencies
*/
import { render, screen } from '@testing-library/react';
/**
* WordPress dependencies
*/
import { useViewportMatch } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import PostPublishButtonOrToggle from '../post-publish-button-or-toggle';
jest.mock( '@wordpress/compose/src/hooks/use-viewport-match' );
jest.mock( '@wordpress/data/src/components/use-select', () => jest.fn() );
describe( 'PostPublishButtonOrToggle should render a', () => {
afterEach( () => {
useViewportMatch.mockRestore();
} );
it( 'button when the post is published (1)', () => {
useSelect.mockImplementation( () => ( {
isPublished: true,
} ) );
render( <PostPublishButtonOrToggle /> );
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toBeVisible();
} );
it( 'button when the post is scheduled (2)', () => {
useSelect.mockImplementation( () => ( {
isScheduled: true,
isBeingScheduled: true,
} ) );
render( <PostPublishButtonOrToggle /> );
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toBeVisible();
} );
it( 'button when the post is pending and cannot be published but the viewport is >= medium (3)', () => {
useSelect.mockImplementation( () => ( {
isPending: true,
hasPublishAction: false,
} ) );
render( <PostPublishButtonOrToggle /> );
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toBeVisible();
} );
it( 'toggle when post is not (1), (2), (3), the viewport is <= medium, and the publish sidebar is enabled', () => {
useViewportMatch.mockReturnValue( true );
useSelect.mockImplementation( () => ( {
isPublishSidebarEnabled: true,
} ) );
render( <PostPublishButtonOrToggle isPublishSidebarEnabled /> );
expect(
screen.getByRole( 'button', { name: 'Publish' } )
).toBeVisible();
} );
it( 'button when post is not (1), (2), (3), the viewport is >= medium, and the publish sidebar is disabled', () => {
useSelect.mockImplementation( () => ( {
isPublishSidebarEnabled: false,
} ) );
render( <PostPublishButtonOrToggle /> );
expect(
screen.getByRole( 'button', { name: 'Submit for Review' } )
).toBeVisible();
} );
} );