Debian Codegraph @

addons/web/static/lib/hoot/ui/hoot_test_path.js

raw
1 /** @odoo-module */
2
3 import { Component, useState, xml } from "@odoo/owl";
4 import { Test } from "../core/test";
5 import { HootCopyButton } from "./hoot_copy_button";
6 import { HootLink } from "./hoot_link";
7 import { HootTagButton } from "./hoot_tag_button";
8
9 /**
10 * @typedef {{
11 * canCopy?: boolean;
12 * full?: boolean;
13 * inert?: boolean;
14 * showStatus?: boolean;
15 * test: Test;
16 * }} HootTestPathProps
17 */
18
19 /** @extends {Component<HootTestPathProps, import("../hoot").Environment>} */
20 export class HootTestPath extends Component {
21 static components = { HootCopyButton, HootLink, HootTagButton };
22
23 static props = {
24 canCopy: { type: Boolean, optional: true },
25 full: { type: Boolean, optional: true },
26 inert: { type: Boolean, optional: true },
27 showStatus: { type: Boolean, optional: true },
28 test: Test,
29 };
30
31 static template = xml`
32 <t t-set="statusInfo" t-value="getStatusInfo()" />
33 <div class="flex items-center gap-1 whitespace-nowrap overflow-hidden">
34 <t t-if="props.showStatus">
35 <span
36 t-attf-class="inline-flex min-w-3 min-h-3 rounded-full bg-{{ statusInfo.className }}"
37 t-att-title="statusInfo.text"
38 />
39 </t>
40 <span class="flex items-center overflow-hidden">
41 <t t-if="uiState.selectedSuiteId and !props.full">
42 <span class="text-gray font-bold p-1 select-none hidden md:inline">...</span>
43 <span class="select-none hidden md:inline">/</span>
44 </t>
45 <t t-foreach="getTestPath()" t-as="suite" t-key="suite.id">
46 <t t-if="props.inert">
47 <span
48 class="text-gray whitespace-nowrap font-bold p-1 hidden md:inline transition-colors"
49 t-esc="suite.name"
50 />
51 </t>
52 <t t-else="">
53 <HootLink
54 ids="{ id: suite.id }"
55 class="'text-gray hover:text-primary hover:underline whitespace-nowrap font-bold p-1 hidden md:inline transition-colors'"
56 title="'Run ' + suite.fullName"
57 t-esc="suite.name"
58 />
59 <t t-if="suite.config.multi">
60 <strong class="text-amber whitespace-nowrap me-1">
61 x<t t-esc="suite.config.multi" />
62 </strong>
63 </t>
64 </t>
65 <span class="select-none hidden md:inline" t-att-class="{ 'text-cyan': suite.config.skip }">/</span>
66 </t>
67 <span
68 class="text-primary truncate font-bold p-1"
69 t-att-class="{ 'text-cyan': props.test.config.skip }"
70 t-att-title="props.test.name"
71 t-esc="props.test.name"
72 />
73 <t t-if="props.canCopy">
74 <HootCopyButton text="props.test.name" altText="props.test.id" />
75 </t>
76 <t t-if="results.length > 1">
77 <strong class="text-amber whitespace-nowrap mx-1">
78 x<t t-esc="results.length" />
79 </strong>
80 </t>
81 </span>
82 <t t-if="props.test.tags.length">
83 <ul class="flex items-center gap-1">
84 <t t-foreach="props.test.tags.slice(0, 5)" t-as="tag" t-key="tag.name">
85 <li class="flex">
86 <HootTagButton tag="tag" />
87 </li>
88 </t>
89 </ul>
90 </t>
91 </div>
92 `;
93
94 setup() {
95 this.results = useState(this.props.test.results);
96 this.uiState = useState(this.env.ui);
97 }
98
99 getStatusInfo() {
100 switch (this.props.test.status) {
101 case Test.ABORTED: {
102 return { className: "amber", text: "aborted" };
103 }
104 case Test.FAILED: {
105 if (this.props.test.config.todo) {
106 return { className: "purple", text: "todo" };
107 } else {
108 return { className: "rose", text: "failed" };
109 }
110 }
111 case Test.PASSED: {
112 if (this.props.test.config.todo) {
113 return { className: "purple", text: "todo" };
114 } else {
115 return { className: "emerald", text: "passed" };
116 }
117 }
118 default: {
119 return { className: "cyan", text: "skipped" };
120 }
121 }
122 }
123
124 /**
125 * @param {import("../core/suite").Suite} suite
126 */
127 getSuiteInfo(suite) {
128 let suites = 0;
129 let tests = 0;
130 let assertions = 0;
131 for (const job of suite.jobs) {
132 if (job instanceof Test) {
133 tests++;
134 assertions += job.lastResults?.counts.assertion || 0;
135 } else {
136 suites++;
137 }
138 }
139 return {
140 id: suite.id,
141 name: suite.name,
142 parent: suite.parent?.name || null,
143 suites,
144 tests,
145 assertions,
146 };
147 }
148
149 getTestPath() {
150 const { selectedSuiteId } = this.uiState;
151 const { test } = this.props;
152 const path = test.path.slice(0, -1);
153 if (this.props.full || !selectedSuiteId) {
154 return path;
155 }
156 const index = path.findIndex((suite) => suite.id === selectedSuiteId) + 1;
157 return path.slice(index);
158 }
159 }