forked from phantom603/online-store-finished
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.js
68 lines (57 loc) · 1.57 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Page from "./index.js";
const categories = ["Monitors", "Laptops", "Video cards"];
const brands = ["Asus", "Acer", "Apple"];
const products = [
{
id: "76w0hz7015kkr9kjkav",
images: [
"https://content2.rozetka.com.ua/goods/images/big_tile/370191080.jpg",
],
title:
"Acer Aspire 5 A515-57-59VX Steel Gray (NX.KN4EU.00C) / Intel Core i5-12450H / RAM 16 ГБ / SSD 512 ГБ",
rating: 2.89,
price: 15999,
category: "laptops",
brand: "acer",
},
];
describe("Page", () => {
let page;
beforeEach(() => {
fetchMock.mockResponses(
[JSON.stringify(categories), { status: 200 }],
[JSON.stringify(brands), { status: 200 }],
[
JSON.stringify(products),
{
status: 200,
headers: {
"X-Total-Count": "100",
},
},
],
);
page = new Page("http://example.com/");
document.body.append(page.element);
});
afterEach(() => {
fetchMock.resetMocks();
page.destroy();
page = null;
document.body.innerHTML = "";
});
it("should be rendered correctly", () => {
expect(page.element).toBeInTheDocument();
expect(page.element).toBeVisible();
});
it("should show modal cart", async () => {
const { cartBtn } = page.subElements;
cartBtn.dispatchEvent(new CustomEvent("pointerdown"));
expect(page.modal.element).toBeInTheDocument();
expect(page.modal.element).toBeVisible();
});
it("should have ability to be destroyed", () => {
page.destroy();
expect(page.element).not.toBeInTheDocument();
});
});