/
view_scale_selector.test.js
140 lines (133 loc) · 4.71 KB
/
view_scale_selector.test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { expect, test } from "@odoo/hoot";
import { click, queryAll } from "@odoo/hoot-dom";
import { animationFrame } from "@odoo/hoot-mock";
import { Component, useState, xml } from "@odoo/owl";
import { contains, mountWithCleanup } from "@web/../tests/web_test_helpers";
import { ViewScaleSelector } from "@web/views/view_components/view_scale_selector";
test("basic ViewScaleSelector component usage", async () => {
class Parent extends Component {
static components = { ViewScaleSelector };
static template = xml`<ViewScaleSelector t-props="compProps" />`;
static props = ["*"];
setup() {
this.state = useState({
scale: "week",
});
}
get compProps() {
return {
scales: {
day: {
description: "Daily",
},
week: {
description: "Weekly",
hotkey: "o",
},
year: {
description: "Yearly",
},
},
isWeekendVisible: true,
setScale: (scale) => {
this.state.scale = scale;
expect.step(scale);
},
toggleWeekendVisibility: () => {
expect.step("toggleWeekendVisibility");
},
currentScale: this.state.scale,
};
}
}
await mountWithCleanup(Parent);
expect(".o_view_scale_selector").toHaveCount(1);
expect([]).toVerifySteps();
expect(".o_view_scale_selector").toHaveText("Weekly");
expect(".scale_button_selection").toHaveAttribute("data-hotkey", "v");
click(".scale_button_selection");
await animationFrame();
expect(".o-dropdown--menu").toHaveCount(1);
expect(queryAll(".o-dropdown--menu .active")[0], {
message: "the active option is selected",
}).toHaveText("Weekly");
expect(".o-dropdown--menu span:nth-child(2)", {
message: "'week' scale has the right hotkey",
}).toHaveAttribute("data-hotkey", "o");
click(".o_scale_button_day");
await animationFrame();
expect(["day"]).toVerifySteps();
expect(".o_view_scale_selector").toHaveText("Daily");
click(".scale_button_selection");
await contains(".dropdown-item:last-child").click();
expect(["toggleWeekendVisibility"]).toVerifySteps();
});
test("ViewScaleSelector with only one scale available", async () => {
class Parent extends Component {
static components = { ViewScaleSelector };
static template = xml`<ViewScaleSelector t-props="compProps" />`;
static props = ["*"];
setup() {
this.state = useState({
scale: "day",
});
}
get compProps() {
return {
scales: {
day: {
description: "Daily",
},
},
setScale: () => {},
isWeekendVisible: false,
toggleWeekendVisibility: () => {},
currentScale: this.state.scale,
};
}
}
await mountWithCleanup(Parent);
expect(".o_view_scale_selector").toHaveCount(0);
});
test("ViewScaleSelector show weekends button is disabled when scale is day", async () => {
class Parent extends Component {
static components = { ViewScaleSelector };
static template = xml`<ViewScaleSelector t-props="compProps"/>`;
static props = ["*"];
setup() {
this.state = useState({
scale: "day",
});
}
get compProps() {
return {
scales: {
day: {
description: "Daily",
},
week: {
description: "Weekly",
hotkey: "o",
},
year: {
description: "Yearly",
},
},
setScale: (key) => (this.state.scale = key),
isWeekendVisible: false,
toggleWeekendVisibility: () => {},
currentScale: this.state.scale,
};
}
}
await mountWithCleanup(Parent);
expect(".o_view_scale_selector").toHaveCount(1);
click(".scale_button_selection");
await animationFrame();
expect(".o_show_weekends").toHaveClass("disabled");
click(".dropdown-item:nth-child(2)");
await animationFrame();
click(".scale_button_selection");
await animationFrame();
expect(".o_show_weekends").not.toHaveClass("disabled");
});