From 6fb4a677d4cb720baa0bc2a7114a9d7862e9179c Mon Sep 17 00:00:00 2001 From: Darren Jennings Date: Tue, 17 Jul 2018 12:45:07 -0700 Subject: [PATCH 1/2] style(tests) code format --- __tests__/autosuggest.test.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/__tests__/autosuggest.test.js b/__tests__/autosuggest.test.js index 179219d..61dae12 100644 --- a/__tests__/autosuggest.test.js +++ b/__tests__/autosuggest.test.js @@ -127,7 +127,7 @@ describe("Autosuggest", () => { const input = wrapper.find("input"); input.trigger("click"); wrapper.setData({ searchInput: "G" }); - + input.trigger("keydown.up"); // Check it doesn't offset the selection by going up first when nothing is selected. // TODO: test these keys are actually returning early. @@ -385,7 +385,12 @@ describe("Autosuggest", () => { props.suggestions = [ { data: [ - { id: 1, name: "Frodo", avatar: "https://upload.wikimedia.org/wikipedia/en/4/4e/Elijah_Wood_as_Frodo_Baggins.png" } + { + id: 1, + name: "Frodo", + avatar: + "https://upload.wikimedia.org/wikipedia/en/4/4e/Elijah_Wood_as_Frodo_Baggins.png" + } ] } ]; @@ -400,7 +405,7 @@ describe("Autosuggest", () => { const input = wrapper.find("input"); input.trigger("click"); wrapper.setData({ searchInput: "F" }); - + input.trigger("keydown.down"); input.trigger("keydown.enter"); From 6eff625d3f5c9064a23bcab08a0a0f96019443ae Mon Sep 17 00:00:00 2001 From: Darren Jennings Date: Tue, 17 Jul 2018 13:06:45 -0700 Subject: [PATCH 2/2] fix(prop) add number to searchinput prop validation --- __tests__/autosuggest.test.js | 40 +++++++++++++++++++++++++++++++++++ src/parts/DefaultSection.js | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/__tests__/autosuggest.test.js b/__tests__/autosuggest.test.js index 61dae12..4bd3510 100644 --- a/__tests__/autosuggest.test.js +++ b/__tests__/autosuggest.test.js @@ -429,4 +429,44 @@ describe("Autosuggest", () => { const input = wrapper.find("input"); expect(input.attributes()["name"]).toBe("my-input"); }); + + it("search input prop type handles string and integers only", async () => { + let props = Object.assign({}, defaultProps); + + const mockConsole = jest.fn(); + console.error = mockConsole; + + const blurred = () => {}; + props.inputProps.onBlur = blurred; + + const wrapper = mount(Autosuggest, { + propsData: props + }); + + const input = wrapper.find("input"); + + // Integers + input.trigger("click"); + wrapper.setData({ searchInput: 1 }); + await wrapper.vm.$nextTick(() => {}); + input.trigger("blur"); + + // Strings + input.trigger("click"); + wrapper.setData({ searchInput: "Hello" }); + await wrapper.vm.$nextTick(() => {}); + input.trigger("blur"); + + // Should not throw any errors + expect(mockConsole).toHaveBeenCalledTimes(0); + + // Functions + input.trigger("click"); + wrapper.setData({ searchInput: () => { /* BAD */ } }); + await wrapper.vm.$nextTick(() => {}); + input.trigger("blur"); + + // Should throw validation error + expect(mockConsole).toHaveBeenCalled(); + }); }); diff --git a/src/parts/DefaultSection.js b/src/parts/DefaultSection.js index aa8b50f..3753e33 100644 --- a/src/parts/DefaultSection.js +++ b/src/parts/DefaultSection.js @@ -4,7 +4,7 @@ const DefaultSection = { section: { type: Object, required: true }, currentIndex: { type: Number, required: false, default: Infinity }, updateCurrentIndex: { type: Function, required: true }, - searchInput: { type: String, required: false, default: "" }, + searchInput: { type: [String, Number], required: false, default: "" }, renderSuggestion: { type: Function, required: true }, normalizeItemFunction: { type: Function, required: true } },