Skip to content

Commit

Permalink
Merge pull request #23 from DannyFeliz/fix-default-suggestions
Browse files Browse the repository at this point in the history
Fix default suggestions
  • Loading branch information
DannyFeliz authored Dec 5, 2019
2 parents 16dab28 + 1512f20 commit f4cbe30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/components/EmailDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
@keyup.up="handleListNavigation('up')"
@keyup.down="handleListNavigation('down')"
@keyup="convertCharToText"
>
{{ emailWithoutDomain }}@{{ domain }}
</li>
>{{ emailWithoutDomain }}@{{ domain }}</li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -125,14 +123,20 @@ 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
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.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()))
Expand All @@ -144,7 +148,7 @@ export default {
this.$emit("input", this.email);
this.resetFocusIndex();
if (this.isEscPressed) {
this.isEscPressed = false
this.isEscPressed = false;
}
}
},
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 16 additions & 5 deletions tests/unit/email-dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -84,7 +84,6 @@ describe("EmailDropdown.vue", () => {
expect(wrapper.find(".email-dropdown-item").text()).to.be.equal("[email protected]");
});


it("hides suggestion list if remove '@' from the email", async () => {
const wrapper = shallowMount(EmailDropdown, {
propsData
Expand All @@ -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);
Expand All @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down

0 comments on commit f4cbe30

Please sign in to comment.