refactor: helper to compute suggestions
This commit is contained in:
@@ -8,6 +8,9 @@ const props = {
|
|||||||
source: ["app", "apple", "appliance", "brian", "bob", "alice"],
|
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) =>
|
const factory = (props) =>
|
||||||
mount(autocomplete, {
|
mount(autocomplete, {
|
||||||
propsData: props,
|
propsData: props,
|
||||||
@@ -43,10 +46,7 @@ describe("autocomplete", () => {
|
|||||||
|
|
||||||
const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text())
|
const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text())
|
||||||
|
|
||||||
expect(suggestions).toContain("pp")
|
suggestionStr.forEach((str) => expect(suggestions).toContain(str))
|
||||||
expect(suggestions).toContain("pple")
|
|
||||||
expect(suggestions).toContain("ppliance")
|
|
||||||
expect(suggestions).toContain("lice")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("doesnt show non-matching suggestions", async () => {
|
test("doesnt show non-matching suggestions", async () => {
|
||||||
@@ -59,10 +59,7 @@ describe("autocomplete", () => {
|
|||||||
|
|
||||||
const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text())
|
const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text())
|
||||||
|
|
||||||
expect(suggestions).not.toContain("pp")
|
suggestionStr.forEach((str) => expect(suggestions).not.toContain(str))
|
||||||
expect(suggestions).not.toContain("pple")
|
|
||||||
expect(suggestions).not.toContain("ppliance")
|
|
||||||
expect(suggestions).not.toContain("lice")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("updates suggestions on input", async () => {
|
test("updates suggestions on input", async () => {
|
||||||
@@ -75,10 +72,7 @@ describe("autocomplete", () => {
|
|||||||
|
|
||||||
const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text())
|
const suggestions = wrapper.findAll("li").wrappers.map((el) => el.text())
|
||||||
|
|
||||||
expect(suggestions).not.toContain("pp")
|
suggestionStr.forEach((str) => expect(suggestions).not.toContain(str))
|
||||||
expect(suggestions).not.toContain("pple")
|
|
||||||
expect(suggestions).not.toContain("ppliance")
|
|
||||||
expect(suggestions).not.toContain("lice")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("applies suggestion on clicking", async () => {
|
test("applies suggestion on clicking", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user