Skip to content

Fixes #681 - File name update triggers editor change detection #1372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions client/components/__test__/FileNode.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import { shallow } from 'enzyme';
import { FileNode } from '../../modules/IDE/components/FileNode';

beforeAll(() => {});
describe('<FileNode />', () => {
let component;
let props = {};

describe('with valid props', () => {
beforeEach(() => {
props = {
...props,
id: '0',
children: [],
name: 'test.jsx',
fileType: 'dunno',
setSelectedFile: jest.fn(),
deleteFile: jest.fn(),
updateFileName: jest.fn(),
resetSelectedFile: jest.fn(),
newFile: jest.fn(),
newFolder: jest.fn(),
showFolderChildren: jest.fn(),
hideFolderChildren: jest.fn(),
canEdit: true,
authenticated: false
};
component = shallow(<FileNode {...props} />);
});

describe('when changing name', () => {
let input;
let renameTriggerButton;
const changeName = (newFileName) => {
renameTriggerButton.simulate('click');
input.simulate('change', { target: { value: newFileName } });
input.simulate('blur');
};

beforeEach(() => {
input = component.find('.sidebar__file-item-input');
renameTriggerButton = component
.find('.sidebar__file-item-option')
.first();
component.setState({ isEditing: true });
});
it('should render', () => expect(component).toBeDefined());

// it('should debug', () => console.log(component.debug()));

describe('to a valid filename', () => {
const newName = 'newname.jsx';
beforeEach(() => changeName(newName));

it('should save the name', () => {
expect(props.updateFileName).toBeCalledWith(props.id, newName);
});
});

describe('to an empty filename', () => {
const newName = '';
beforeEach(() => changeName(newName));

it('should not save the name', () => {
expect(props.updateFileName).not.toHaveBeenCalled();
});
});
});
});
});
11 changes: 7 additions & 4 deletions client/modules/IDE/actions/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@ export function createFolder(formProps) {
}

export function updateFileName(id, name) {
return {
type: ActionTypes.UPDATE_FILE_NAME,
id,
name
return (dispatch) => {
dispatch(setUnsavedChanges(true));
dispatch({
type: ActionTypes.UPDATE_FILE_NAME,
id,
name
});
};
}

Expand Down
1 change: 1 addition & 0 deletions client/modules/IDE/actions/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function saveProject(selectedFile = null, autosave = false) {
}
const formParams = Object.assign({}, state.project);
formParams.files = [...state.files];

if (selectedFile) {
const fileToUpdate = formParams.files.find(file => file.id === selectedFile.id);
fileToUpdate.content = selectedFile.content;
Expand Down
Loading