-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
56 lines (43 loc) · 1.1 KB
/
index.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
/**
* External dependencies
*/
import { render, screen, within } from '@testing-library/react';
/**
* Internal dependencies
*/
import AlignmentMatrixControl from '../';
const __windowFocus = window.focus;
beforeAll( () => {
window.focus = jest.fn();
} );
afterAll( () => {
window.focus = __windowFocus;
} );
const getControl = () => {
return screen.getByRole( 'grid' );
};
const getCell = ( name ) => {
return within( getControl() ).getByRole( 'gridcell', { name } );
};
describe( 'AlignmentMatrixControl', () => {
describe( 'Basic rendering', () => {
it( 'should render', () => {
render( <AlignmentMatrixControl /> );
expect( getControl() ).toBeInTheDocument();
} );
} );
describe( 'Change value', () => {
const alignments = [ 'center left', 'center center', 'bottom center' ];
it.each( alignments )(
'should change value on %s cell click',
( alignment ) => {
const spy = jest.fn();
render(
<AlignmentMatrixControl value="center" onChange={ spy } />
);
getCell( alignment ).focus();
expect( spy ).toHaveBeenCalledWith( alignment );
}
);
} );
} );