|
| 1 | +import React from 'react'; |
| 2 | +import { shallow } from 'enzyme'; |
| 3 | +import { FileNode } from '../../modules/IDE/components/FileNode'; |
| 4 | + |
| 5 | +beforeAll(() => {}); |
| 6 | +describe('<FileNode />', () => { |
| 7 | + let component; |
| 8 | + let props = {}; |
| 9 | + |
| 10 | + describe('with valid props', () => { |
| 11 | + beforeEach(() => { |
| 12 | + props = { |
| 13 | + ...props, |
| 14 | + id: '0', |
| 15 | + children: [], |
| 16 | + name: 'test.jsx', |
| 17 | + fileType: 'dunno', |
| 18 | + setSelectedFile: jest.fn(), |
| 19 | + deleteFile: jest.fn(), |
| 20 | + updateFileName: jest.fn(), |
| 21 | + resetSelectedFile: jest.fn(), |
| 22 | + newFile: jest.fn(), |
| 23 | + newFolder: jest.fn(), |
| 24 | + showFolderChildren: jest.fn(), |
| 25 | + hideFolderChildren: jest.fn(), |
| 26 | + canEdit: true, |
| 27 | + authenticated: false |
| 28 | + }; |
| 29 | + component = shallow(<FileNode {...props} />); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('when changing name', () => { |
| 33 | + let input; |
| 34 | + let renameTriggerButton; |
| 35 | + const changeName = (newFileName) => { |
| 36 | + renameTriggerButton.simulate('click'); |
| 37 | + input.simulate('change', { target: { value: newFileName } }); |
| 38 | + input.simulate('blur'); |
| 39 | + }; |
| 40 | + |
| 41 | + beforeEach(() => { |
| 42 | + input = component.find('.sidebar__file-item-input'); |
| 43 | + renameTriggerButton = component |
| 44 | + .find('.sidebar__file-item-option') |
| 45 | + .first(); |
| 46 | + component.setState({ isEditing: true }); |
| 47 | + }); |
| 48 | + it('should render', () => expect(component).toBeDefined()); |
| 49 | + |
| 50 | + // it('should debug', () => console.log(component.debug())); |
| 51 | + |
| 52 | + describe('to a valid filename', () => { |
| 53 | + const newName = 'newname.jsx'; |
| 54 | + beforeEach(() => changeName(newName)); |
| 55 | + |
| 56 | + it('should save the name', () => { |
| 57 | + expect(props.updateFileName).toBeCalledWith(props.id, newName); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('to an empty filename', () => { |
| 62 | + const newName = ''; |
| 63 | + beforeEach(() => changeName(newName)); |
| 64 | + |
| 65 | + it('should not save the name', () => { |
| 66 | + expect(props.updateFileName).not.toHaveBeenCalled(); |
| 67 | + }); |
| 68 | + }); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments