Skip to content

Commit

Permalink
feat(tests): add AutoComplete missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding-SE committed Sep 24, 2019
1 parent 24487a4 commit 313da78
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ describe('AutoCompleteEditor', () => {
});

describe('onSelect method', () => {
it('should expect "setValue" and "autoCommitEdit" to have been called with a string when item provided is a string', (done) => {
const spyCommitEdit = jest.spyOn(gridStub.getEditorLock(), 'commitCurrentEdit');
it('should expect "setValue" to have been called but not "autoCommitEdit" when "autoCommitEdit" is disabled', () => {
const spyCommitEdit = jest.spyOn(gridStub, 'getEditorLock');
gridOptionMock.autoCommitEdit = false;
mockColumn.internalColumnEditor.collection = ['male', 'female'];
mockItemData = { id: 123, gender: 'female', isActive: true };
Expand All @@ -391,6 +391,21 @@ describe('AutoCompleteEditor', () => {
const spySetValue = jest.spyOn(editor, 'setValue');
const output = editor.onSelect(null, { item: mockItemData.gender });

expect(output).toBe(false);
expect(spyCommitEdit).not.toHaveBeenCalled();
expect(spySetValue).toHaveBeenCalledWith('female');
});

it('should expect "setValue" and "autoCommitEdit" to have been called with a string when item provided is a string', (done) => {
const spyCommitEdit = jest.spyOn(gridStub, 'getEditorLock');
gridOptionMock.autoCommitEdit = true;
mockColumn.internalColumnEditor.collection = ['male', 'female'];
mockItemData = { id: 123, gender: 'female', isActive: true };

editor = new AutoCompleteEditor(editorArguments);
const spySetValue = jest.spyOn(editor, 'setValue');
const output = editor.onSelect(null, { item: mockItemData.gender });

// HOW DO WE TRIGGER the jQuery UI autocomplete select event? The following works only on "autocompleteselect"
// but that doesn't trigger the "select" (onSelect) directly
// const editorElm = editor.editorDomElement;
Expand All @@ -406,8 +421,8 @@ describe('AutoCompleteEditor', () => {
});

it('should expect "setValue" and "autoCommitEdit" to have been called with the string label when item provided is an object', () => {
const spyCommitEdit = jest.spyOn(gridStub.getEditorLock(), 'commitCurrentEdit');
gridOptionMock.autoCommitEdit = false;
const spyCommitEdit = jest.spyOn(gridStub, 'getEditorLock');
gridOptionMock.autoCommitEdit = true;
mockColumn.internalColumnEditor.collection = [{ value: 'm', label: 'Male' }, { value: 'f', label: 'Female' }];
mockItemData = { id: 123, gender: { value: 'f', label: 'Female' }, isActive: true };

Expand Down

0 comments on commit 313da78

Please sign in to comment.