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

/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["TestUtils.*"] }] */

import { Gridicon } from '@automattic/components';
import ReactDom from 'react-dom';
import TestUtils from 'react-dom/test-utils';
import FormRange from '../';

describe( 'index', () => {
	afterEach( () => {
		ReactDom.unmountComponentAtNode( document.body );
	} );

	test( 'should render beginning content if passed a `minContent` prop', () => {
		const range = TestUtils.renderIntoDocument(
			<FormRange minContent={ <Gridicon icon="minus-small" /> } />
		);
		TestUtils.findRenderedDOMComponentWithClass( range, 'gridicons-minus-small' );
	} );

	test( 'should not render ending content if not passed a `maxContent` prop', () => {
		const range = TestUtils.renderIntoDocument(
			<FormRange minContent={ <Gridicon icon="minus-small" /> } />
		);
		const content = TestUtils.scryRenderedDOMComponentsWithClass( range, 'range__content' );

		expect( content ).toHaveLength( 1 );
		expect( content[ 0 ].getAttribute( 'class' ) ).toEqual( expect.stringContaining( 'is-min' ) );
	} );

	test( 'should render ending content if passed a `maxContent` prop', () => {
		const range = TestUtils.renderIntoDocument(
			<FormRange maxContent={ <Gridicon icon="plus-small" /> } />
		);
		TestUtils.findRenderedDOMComponentWithClass( range, 'gridicons-plus-small' );
	} );

	test( 'should not render beginning content if not passed a `minContent` prop', () => {
		const range = TestUtils.renderIntoDocument(
			<FormRange maxContent={ <Gridicon icon="plus-small" /> } />
		);
		const content = TestUtils.scryRenderedDOMComponentsWithClass( range, 'range__content' );

		expect( content ).toHaveLength( 1 );
		expect( content[ 0 ].getAttribute( 'class' ) ).toEqual( expect.stringContaining( 'is-max' ) );
	} );

	test( 'should render a value label if passed a truthy `showValueLabel` prop', () => {
		const range = TestUtils.renderIntoDocument( <FormRange value={ 8 } showValueLabel readOnly /> );
		const label = TestUtils.findRenderedDOMComponentWithClass( range, 'range__label' );

		expect( label.textContent ).toEqual( '8' );
	} );
} );