From 8772585e8862198673b18b9609a3733b53df754d Mon Sep 17 00:00:00 2001 From: Xavier DETANT Date: Fri, 19 Jul 2019 18:00:14 +0200 Subject: [PATCH] Fix order of completion (#447) --- packages/lesspass-pure/src/components/InputSite.vue | 4 ++++ packages/lesspass-pure/src/components/input-site.test.js | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/lesspass-pure/src/components/InputSite.vue b/packages/lesspass-pure/src/components/InputSite.vue index aa2faa5..c1b7f65 100644 --- a/packages/lesspass-pure/src/components/InputSite.vue +++ b/packages/lesspass-pure/src/components/InputSite.vue @@ -59,6 +59,10 @@ this.$emit("passwordProfileSelected", password.value); } }; + this.awesomplete.sort = (a,b) => { + return a.value.site.localeCompare(b.value.site) || + a.value.login.localeCompare(b.value.login); + } }, computed: { site: { diff --git a/packages/lesspass-pure/src/components/input-site.test.js b/packages/lesspass-pure/src/components/input-site.test.js index 60542d2..55cb155 100644 --- a/packages/lesspass-pure/src/components/input-site.test.js +++ b/packages/lesspass-pure/src/components/input-site.test.js @@ -71,17 +71,22 @@ describe('InputSite', () => { let options = optionsFor(wrapper); expect(options.length).toBe(0); }); - it(`prints all options`, () => { + it(`prints options sorted by site then login`, () => { const wrapper = createWrapper({ passwords: [ + {site: "lesspass", login: "guillaume"}, + {site: "passless", login: "xavier"}, + {site: "passless", login: "guillaume"}, {site: "lesspass", login: "xavier"}, - {site: "lesspass", login: "guillaume"}] + ] }); inputField(wrapper).setValue("le"); let options = optionsFor(wrapper); - expect(options.length).toBe(2); - expect(options.at(0).text()).toContain("lesspass"); - expect(options.at(1).text()).toContain("lesspass"); + expect(options.length).toBe(4); + expect(options.at(0).text()).toBe("lesspass guillaume"); + expect(options.at(1).text()).toBe("lesspass xavier"); + expect(options.at(2).text()).toBe("passless guillaume"); + expect(options.at(3).text()).toBe("passless xavier"); }); }); describe('completion', () => {