From de7d1c2baa51ba17a2df4b010f3c8885237c3a70 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Sat, 29 Aug 2020 11:01:15 +0530 Subject: [PATCH] refactor: helper to compute suggestions --- components/ui/__tests__/autocomplete.spec.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/components/ui/__tests__/autocomplete.spec.js b/components/ui/__tests__/autocomplete.spec.js index 2754a4b5f..40463bf4e 100644 --- a/components/ui/__tests__/autocomplete.spec.js +++ b/components/ui/__tests__/autocomplete.spec.js @@ -8,6 +8,9 @@ const props = { source: ["app", "apple", "appliance", "brian", "bob", "alice"], } +// ["pp", "pple", "ppliance", "lice"] +const suggestionStr = props.source.filter((str) => str.startsWith("a")).map((str) => str.slice(1)) + const factory = (props) => mount(autocomplete, { propsData: props, @@ -43,10 +46,7 @@ describe("autocomplete", () => { const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text()) - expect(suggestions).toContain("pp") - expect(suggestions).toContain("pple") - expect(suggestions).toContain("ppliance") - expect(suggestions).toContain("lice") + suggestionStr.forEach((str) => expect(suggestions).toContain(str)) }) test("doesnt show non-matching suggestions", async () => { @@ -59,10 +59,7 @@ describe("autocomplete", () => { const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text()) - expect(suggestions).not.toContain("pp") - expect(suggestions).not.toContain("pple") - expect(suggestions).not.toContain("ppliance") - expect(suggestions).not.toContain("lice") + suggestionStr.forEach((str) => expect(suggestions).not.toContain(str)) }) test("updates suggestions on input", async () => { @@ -75,10 +72,7 @@ describe("autocomplete", () => { const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text()) - expect(suggestions).not.toContain("pp") - expect(suggestions).not.toContain("pple") - expect(suggestions).not.toContain("ppliance") - expect(suggestions).not.toContain("lice") + suggestionStr.forEach((str) => expect(suggestions).not.toContain(str)) }) test("applies suggestion on clicking", async () => {