From 313da7807a2bcb506e5b9aeb099e78175f7c8271 Mon Sep 17 00:00:00 2001 From: Ghislain Beaulac Date: Tue, 24 Sep 2019 15:04:08 -0400 Subject: [PATCH] feat(tests): add AutoComplete missing test --- .../__tests__/autoCompleteEditor.spec.ts | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/app/modules/angular-slickgrid/editors/__tests__/autoCompleteEditor.spec.ts b/src/app/modules/angular-slickgrid/editors/__tests__/autoCompleteEditor.spec.ts index 35d842c74..fcb268029 100644 --- a/src/app/modules/angular-slickgrid/editors/__tests__/autoCompleteEditor.spec.ts +++ b/src/app/modules/angular-slickgrid/editors/__tests__/autoCompleteEditor.spec.ts @@ -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 }; @@ -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; @@ -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 };