-
Notifications
You must be signed in to change notification settings - Fork 79
/
BackButton-test.js
51 lines (45 loc) · 1.68 KB
/
BackButton-test.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
/* global jest, describe, it, expect, beforeEach, Event */
import React from 'react';
// mock sub-components, as they could rely on a Redux store context and not necessary for unit test
jest.mock('components/BackButton/BackButton');
import ReactTestUtils from 'react-dom/test-utils';
import Component from '../BackButton';
describe('BackButton', () => {
let props = null;
beforeEach(() => {
props = {
folder: {
id: 1,
title: 'container folder',
parentId: null,
canView: true,
canEdit: true,
},
onMoveFiles: () => {},
onOpenFolder: () => {},
badges: [],
};
});
describe('render BackButton', () => {
it('should not render if parentId is not set', () => {
const backbutton = ReactTestUtils.renderIntoDocument(<Component {...props} />);
const locator = ReactTestUtils.scryRenderedDOMComponentsWithClass(backbutton, 'gallery__back-container');
expect(locator.length).toBe(0);
});
it('should render a react component if parentId is set', () => {
props.folder.parentId = 15;
const backbutton = ReactTestUtils.renderIntoDocument(<Component {...props} />);
const locator = ReactTestUtils.scryRenderedDOMComponentsWithClass(backbutton, 'gallery__back-container');
expect(locator.length).toBe(1);
});
});
describe('handleBackClick()', () => {
it('should open folder with parentId', () => {
props.folder.parentId = 15;
props.onOpenFolder = jest.fn();
const backbutton = ReactTestUtils.renderIntoDocument(<Component {...props} />);
backbutton.handleBackClick(new Event('click'));
expect(props.onOpenFolder).toBeCalledWith(15);
});
});
});