File size: 2,286 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
/**
 * @jest-environment jsdom
 */

import { render, within } from '@testing-library/react';
import { JetpackConnectMainWrapper } from '../main-wrapper';

jest.mock( 'calypso/components/data/document-head', () => () => 'DocumentHead' );

describe( 'JetpackConnectMainWrapper', () => {
	const translate = ( string ) => string;

	test( 'should render the passed children as children of the component', () => {
		const { container } = render(
			<JetpackConnectMainWrapper translate={ translate }>
				<span data-testid="test__child" />
			</JetpackConnectMainWrapper>
		);

		expect( within( container.firstChild ).getByTestId( 'test__child' ) ).toBeVisible();
	} );

	test( 'should always specify the jetpack-connect__main class', () => {
		const { container } = render( <JetpackConnectMainWrapper translate={ translate } /> );

		expect( container.firstChild ).toHaveClass( 'jetpack-connect__main' );
	} );

	test( 'should allow more classes to be added', () => {
		const { container } = render(
			<JetpackConnectMainWrapper className="test__class" translate={ translate } />
		);

		expect( container.firstChild ).toHaveClass( 'jetpack-connect__main' );
		expect( container.firstChild ).toHaveClass( 'test__class' );
	} );

	test( 'should not contain the is-wide modifier class by default', () => {
		const { container } = render( <JetpackConnectMainWrapper translate={ translate } /> );

		expect( container.firstChild ).not.toHaveClass( 'is-wide' );
	} );

	test( 'should contain the is-wide modifier class if prop is specified', () => {
		const { container } = render( <JetpackConnectMainWrapper isWide translate={ translate } /> );

		expect( container.firstChild ).toHaveClass( 'is-wide' );
	} );

	test( 'should not contain the is-mobile-app-flow modifier class by default', () => {
		const { container } = render( <JetpackConnectMainWrapper translate={ translate } /> );

		expect( container.firstChild ).not.toHaveClass( 'is-mobile-app-flow' );
	} );

	test( 'should contain the is-mobile-app-flow modifier if cookie is set', () => {
		document.cookie = 'jetpack_connect_mobile_redirect=some url';
		const { container } = render( <JetpackConnectMainWrapper isWide translate={ translate } /> );

		expect( container.firstChild ).toHaveClass( 'is-mobile-app-flow' );
	} );
} );