-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bruno Garcia
committed
Feb 20, 2021
1 parent
54ab52c
commit 30b254d
Showing
6 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "@testing-library/jest-dom"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,13 @@ | ||
import { shallowMount } from "@vue/test-utils"; | ||
import { render } from "@testing-library/vue"; | ||
import ProductList from "@/components/ProductList.vue"; | ||
import ProductItem from "@/components/ProductItem.vue"; | ||
import mockStore from "../mocks/mockStore"; | ||
|
||
const store = mockStore(); | ||
import store from "../mocks/mockStore2"; | ||
|
||
describe("ProductList.vue", () => { | ||
it("Must have a main container", () => { | ||
const wrapper = shallowMount(ProductList, { | ||
global: { | ||
plugins: [store] | ||
} | ||
}); | ||
|
||
expect(wrapper.find('[data-test="products-list"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
it("Must use ProductItem component", () => { | ||
const wrapper = shallowMount(ProductList, { | ||
global: { | ||
plugins: [store] | ||
} | ||
}); | ||
it("Must render the products", () => { | ||
const { getByText } = render(ProductList, { store }); | ||
|
||
expect(wrapper.findAllComponents(ProductItem).length).toBe(3); | ||
expect(getByText("Cap")).toBeInTheDocument(); | ||
expect(getByText("Shirt")).toBeInTheDocument(); | ||
expect(getByText("Mug")).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import store from "@/store"; | ||
|
||
function mockStore(): object { | ||
return { | ||
modules: { | ||
shopping: { | ||
...store.modules.shopping, | ||
state: { | ||
products: [ | ||
{ | ||
id: "X3W2OPY", | ||
code: "CAP", | ||
name: "Cap", | ||
price: 5, | ||
discounts: ["TWO_X_ONE"], | ||
currency: "€" | ||
}, | ||
{ | ||
id: "X7R2OPX", | ||
code: "TSHIRT", | ||
name: "Shirt", | ||
price: 20, | ||
discounts: ["BULK"], | ||
currency: "€" | ||
}, | ||
{ | ||
id: "X2G2OPZ", | ||
code: "MUG", | ||
name: "Mug", | ||
price: 7.5, | ||
discounts: [], | ||
currency: "€" | ||
} | ||
], | ||
summary: { | ||
totalCost: 40, | ||
totalItems: 5, | ||
discountsApplied: [ | ||
{ | ||
code: "test code 1", | ||
literal: "test literal 1", | ||
total: 3 | ||
}, | ||
{ | ||
code: "test code 2", | ||
literal: "test literal 2", | ||
total: 9 | ||
} | ||
], | ||
totalCostWithDiscounts: 23 | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
export default mockStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters