Skip to content

Commit

Permalink
Merge pull request #12 from DannyFeliz/feature-unit-test
Browse files Browse the repository at this point in the history
Feature unit test
  • Loading branch information
DannyFeliz committed Nov 17, 2019
2 parents 280a7b8 + a884595 commit 4757025
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
languaje: node_js
node_js:
- 10
cache:
directories:
- node_modules
script:
- npm run test:unit
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

A Vue component for autocomplete email domains

[<img src="https://travis-ci.org/DannyFeliz/vue-email-dropdown.svg?branch=master">](https://travis-ci.org/DannyFeliz/vue-email-dropdown)
[<img src="https://img.shields.io/npm/dt/vue-email-dropdown.svg">](https://www.npmjs.com/package/vue-email-dropdown)
[<img src="https://img.shields.io/npm/v/vue-email-dropdown.svg">](https://www.npmjs.com/package/vue-email-dropdown)

Expand Down Expand Up @@ -82,7 +83,7 @@ yarn add vue-email-dropdown
<script>
// Import package
import EmailDropdown from "vue-email-dropdown";
// Import basic styles (optional)
// Import styles
import "vue-email-dropdown/dist/vue-email-dropdown.css";
export default {
Expand All @@ -93,6 +94,7 @@ export default {
return {
domains: [
"yourcompany.com",
"google.com",
"gmx.de",
"googlemail.com",
"hotmail.fr",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"bundle": "./node_modules/@vue/cli-service/bin/vue-cli-service.js build --target lib --name vue-email-dropdown ./src/components/EmailDropdown.vue",
"publish": "npm publish --access public",
"test:unit": "vue-cli-service test:unit",
"test:unit:watch": "vue-cli-service test:unit --watch",
"lint": "vue-cli-service lint"
},
"dependencies": {
Expand Down
3 changes: 0 additions & 3 deletions src/components/EmailDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ export default {
initialValue: {
default: "",
validator(value) {
if (value instanceof InputEvent) {
value = value.target.value;
}
return typeof value === "string";
}
},
Expand Down
64 changes: 64 additions & 0 deletions tests/unit/email-dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { expect } from "chai";
import { shallowMount } from "@vue/test-utils";
import EmailDropdown from "@/components/EmailDropdown.vue";

describe("EmailDropdown.vue", () => {
let propsData;

beforeEach(() => {
propsData = {
initialValue: "hello@",
domains: ["google.com"],
defaultDomains: ["hotmail.com", "outlook.com"],
maxSuggestions: 4,
closeOnClickOutside: true
};
});

it("renders without show suggestions", () => {
propsData.initialValue = "hello";

const wrapper = shallowMount(EmailDropdown, {
propsData
});

expect(wrapper.find(".email-dropdown-list").exists()).to.be.false;
});

it("shows suggestions with default domains", () => {
const wrapper = shallowMount(EmailDropdown, {
propsData
});

const dropdownItems = wrapper.findAll(".email-dropdown-item");
expect(dropdownItems).to.have.length(2);
expect(dropdownItems.at(0).text()).to.equal("hello@hotmail.com");
expect(dropdownItems.at(1).text()).to.equal("hello@outlook.com");
});

it("shows suggestions based in initialValue", () => {
propsData.domains = ["gmail.com", "google.com", "outlook.com"];
propsData.initialValue = "hello@g";

const wrapper = shallowMount(EmailDropdown, {
propsData
});

const dropdownItems = wrapper.findAll(".email-dropdown-item");

expect(dropdownItems).to.have.length(2);
expect(dropdownItems.at(0).text()).to.be.equal("hello@gmail.com");
expect(dropdownItems.at(1).text()).to.be.equal("hello@google.com");
});

it("hides suggestions if email match the suggestion", () => {
propsData.initialValue = "hello@google.com";

const wrapper = shallowMount(EmailDropdown, {
propsData
});

expect(wrapper.text()).to.be.empty;
expect(wrapper.find(".email-dropdown-list").exists()).to.be.false;
});
});

0 comments on commit 4757025

Please sign in to comment.