Skip to content
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

fix(editors): select editor inline blur save before destroy, fixes #752 #755

Merged
merged 2 commits into from
May 10, 2021
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"jquery-ui-dist": "^1.12.1",
"moment-mini": "^2.24.0",
"rxjs": "^6.3.3",
"slickgrid": "^2.4.34",
"slickgrid": "^2.4.35",
"text-encoding-utf-8": "^1.0.2"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('CheckboxEditor', () => {
grid: gridStub,
column: mockColumn,
item: mockItemData,
event: null,
event: null as any,
cancelChanges: jest.fn(),
commitChanges: jest.fn(),
container: divContainer,
Expand All @@ -61,7 +61,7 @@ describe('CheckboxEditor', () => {
describe('with invalid Editor instance', () => {
it('should throw an error when trying to call init without any arguments', (done) => {
try {
editor = new CheckboxEditor(null);
editor = new CheckboxEditor(null as any);
} catch (e) {
expect(e.toString()).toContain(`[Angular-SlickGrid] Something is wrong with this grid, an Editor must always have valid arguments.`);
done();
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('CheckboxEditor', () => {
});

it('should initialize the editor even when user define his own editor options', () => {
mockColumn.internalColumnEditor.editorOptions = { minLength: 3 } as AutocompleteOption;
mockColumn.internalColumnEditor!.editorOptions = { minLength: 3 } as AutocompleteOption;
editor = new CheckboxEditor(editorArguments);
const editorCount = divContainer.querySelectorAll('input.editor-checkbox.editor-isActive').length;

Expand All @@ -98,11 +98,11 @@ describe('CheckboxEditor', () => {

it('should have a title (tooltip) when defined in its column definition', () => {
const testValue = 'test title';
mockColumn.internalColumnEditor.title = testValue;
mockColumn.internalColumnEditor!.title = testValue;

editor = new CheckboxEditor(editorArguments);
const editorElmJquery = editor.editorDomElement;
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-checkbox.editor-isActive');
const editorElm = divContainer.querySelector('input.editor-checkbox.editor-isActive') as HTMLInputElement;

expect(editorElm.title).toBe(testValue);
expect(editorElmJquery[0].title).toBe(testValue);
Expand Down Expand Up @@ -139,6 +139,15 @@ describe('CheckboxEditor', () => {
expect(editor.getValue()).toBe(false);
});

it('should call "preClick" and expect the "checked" attribute to be toggled', () => {
editor = new CheckboxEditor(editorArguments);
const previousValue = editor.getValue();
editor.preClick();
const newValue = editor.getValue();

expect(previousValue).not.toEqual(newValue);
});

it('should define an item datacontext containing a string as cell value and expect this value to be loaded in the editor when calling "loadValue"', () => {
editor = new CheckboxEditor(editorArguments);
editor.loadValue(mockItemData);
Expand All @@ -153,7 +162,7 @@ describe('CheckboxEditor', () => {
const spy = jest.spyOn(editor, 'save');
editor.loadValue({ id: 2, title: 'task 1', isActive: true });

const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-isActive');
const editorElm = divContainer.querySelector('input.editor-isActive') as HTMLInputElement;
editorElm.dispatchEvent(new (window.window as any).CustomEvent('click'));

expect(editor.isValueChanged()).toBe(true);
Expand All @@ -164,7 +173,7 @@ describe('CheckboxEditor', () => {
const event = new (window.window as any).KeyboardEvent('keydown', { keyCode: KEY_CHAR_SPACE, bubbles: true, cancelable: true });

editor = new CheckboxEditor(editorArguments);
const editorElm = divContainer.querySelector<HTMLInputElement>('input.editor-isActive');
const editorElm = divContainer.querySelector('input.editor-isActive') as HTMLInputElement;

editor.loadValue({ id: 1, title: 'task 1', isActive: true });
editor.focus();
Expand All @@ -176,7 +185,7 @@ describe('CheckboxEditor', () => {

describe('applyValue method', () => {
it('should apply the value to the isActive property when it passes validation', () => {
mockColumn.internalColumnEditor.validator = null;
mockColumn.internalColumnEditor!.validator = null as any;
mockItemData = { id: 1, title: 'task 1', isActive: true };

editor = new CheckboxEditor(editorArguments);
Expand All @@ -186,7 +195,7 @@ describe('CheckboxEditor', () => {
});

it('should apply the value to the title property with a field having dot notation (complex object) that passes validation', () => {
mockColumn.internalColumnEditor.validator = null;
mockColumn.internalColumnEditor!.validator = null as any;
mockColumn.field = 'part.isActive';
mockItemData = { id: 1, part: { isActive: true } };

Expand Down Expand Up @@ -293,7 +302,7 @@ describe('CheckboxEditor', () => {

it('should not call anything when the input value is false but is required', () => {
mockItemData = { id: 1, title: 'task 1', isActive: false };
mockColumn.internalColumnEditor.required = true;
mockColumn.internalColumnEditor!.required = true;
gridOptionMock.autoCommitEdit = true;
const spy = jest.spyOn(gridStub.getEditorLock(), 'commitCurrentEdit');

Expand All @@ -307,7 +316,7 @@ describe('CheckboxEditor', () => {

it('should not call anything when the input value is null but is required', () => {
mockItemData = { id: 1, title: 'task 1', isActive: null };
mockColumn.internalColumnEditor.required = true;
mockColumn.internalColumnEditor!.required = true;
gridOptionMock.autoCommitEdit = true;
const spy = jest.spyOn(gridStub.getEditorLock(), 'commitCurrentEdit');

Expand All @@ -320,7 +329,7 @@ describe('CheckboxEditor', () => {
});

it('should not save when custom validation fails', () => {
mockColumn.internalColumnEditor.validator = (value: any, args: EditorArgs) => {
mockColumn.internalColumnEditor!.validator = (value: any) => {
if (!value) {
return { valid: false, msg: 'This must be accepted' };
}
Expand All @@ -341,7 +350,7 @@ describe('CheckboxEditor', () => {
describe('validate method', () => {
it('should return False when field is required and field is empty, null or false', () => {
const expectation = { valid: false, msg: 'Field is required' };
mockColumn.internalColumnEditor.required = true;
mockColumn.internalColumnEditor!.required = true;
editor = new CheckboxEditor(editorArguments);
const validation1 = editor.validate('');
const validation2 = editor.validate(null);
Expand All @@ -353,15 +362,15 @@ describe('CheckboxEditor', () => {
});

it('should return True when field is required and input is provided with True', () => {
mockColumn.internalColumnEditor.required = true;
mockColumn.internalColumnEditor!.required = true;
editor = new CheckboxEditor(editorArguments);
const validation = editor.validate(true);

expect(validation).toEqual({ valid: true, msg: null });
});

it('should return True when field is required and input is provided with any text', () => {
mockColumn.internalColumnEditor.required = true;
mockColumn.internalColumnEditor!.required = true;
editor = new CheckboxEditor(editorArguments);
const validation = editor.validate('text');

Expand Down
Loading