From efc5fca3da576c419069b09293dbf8ae28871396 Mon Sep 17 00:00:00 2001 From: Danny Feliz Date: Thu, 5 Dec 2019 17:28:42 -0400 Subject: [PATCH 1/2] Don't show the default domains with the regular domains --- src/components/EmailDropdown.vue | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/EmailDropdown.vue b/src/components/EmailDropdown.vue index 4c3b8ed..69d2dbb 100644 --- a/src/components/EmailDropdown.vue +++ b/src/components/EmailDropdown.vue @@ -32,9 +32,7 @@ @keyup.up="handleListNavigation('up')" @keyup.down="handleListNavigation('down')" @keyup="convertCharToText" - > - {{ emailWithoutDomain }}@{{ domain }} - + >{{ emailWithoutDomain }}@{{ domain }} @@ -125,7 +123,9 @@ export default { return this.suggestionList.includes(this.email.toLowerCase()); }, domainsList() { - if (!this.includesAt) return []; + if (!this.includesAt) { + return []; + } if (!this.emailDomain.length && this.defaultDomains.length) { return this.defaultDomains @@ -133,6 +133,10 @@ export default { .slice(0, this.maxSuggestions); } + if (!this.emailDomain) { + return []; + } + return this.domains .filter(domain => domain.startsWith(this.emailDomain)) .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())) @@ -144,7 +148,7 @@ export default { this.$emit("input", this.email); this.resetFocusIndex(); if (this.isEscPressed) { - this.isEscPressed = false + this.isEscPressed = false; } } }, @@ -276,7 +280,8 @@ export default { border-top: none; } - &:hover, &:focus { + &:hover, + &:focus { background-color: #f2f2f2; border: 0.1px solid darkgrey; box-sizing: border-box; From 1512f202732aa1ad59ea2b7bbcbb885fd44a1351 Mon Sep 17 00:00:00 2001 From: Danny Feliz Date: Thu, 5 Dec 2019 17:29:36 -0400 Subject: [PATCH 2/2] Add unit test to handle the suggestions without default domains --- tests/unit/email-dropdown.spec.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/unit/email-dropdown.spec.js b/tests/unit/email-dropdown.spec.js index 32cd28e..66ab22b 100644 --- a/tests/unit/email-dropdown.spec.js +++ b/tests/unit/email-dropdown.spec.js @@ -1,4 +1,4 @@ -import Vue from "vue" +import Vue from "vue"; import { expect } from "chai"; import { shallowMount } from "@vue/test-utils"; import EmailDropdown from "@/components/EmailDropdown.vue"; @@ -84,7 +84,6 @@ describe("EmailDropdown.vue", () => { expect(wrapper.find(".email-dropdown-item").text()).to.be.equal("hello@gmail.com"); }); - it("hides suggestion list if remove '@' from the email", async () => { const wrapper = shallowMount(EmailDropdown, { propsData @@ -99,11 +98,11 @@ describe("EmailDropdown.vue", () => { describe("events", () => { it("emits 'input' on email change", async () => { propsData.domains = ["gmail.com", "google.com"]; - + const wrapper = shallowMount(EmailDropdown, { propsData }); - + wrapper.find("input").setValue("hello@gmail"); await Vue.nextTick(); expect(wrapper.emitted().input[0]).to.have.length(1); @@ -113,7 +112,7 @@ describe("EmailDropdown.vue", () => { expect(wrapper.emitted().input[1]).to.have.length(1); expect(wrapper.emitted().input[1][0]).to.be.equal("hello@gmail."); }); - }) + }); describe("computed", () => { describe("includesAt", () => { @@ -215,6 +214,18 @@ describe("EmailDropdown.vue", () => { expect(wrapper.vm.emailDomain).to.be.have.length(1); expect(wrapper.vm.domainsList).to.deep.equalInAnyOrder(propsData.domains); }); + + it("return an empty list if doesn't have default domains", () => { + propsData.domains = ["google.com", "gmail.com"]; + propsData.defaultDomains = []; + propsData.initialValue = "hello@"; + + const wrapper = shallowMount(EmailDropdown, { + propsData + }); + + expect(wrapper.vm.domainsList).to.be.have.length(0); + }); }); describe("suggestionList", () => {