| 1 |
/** @odoo-module */ |
| 2 |
|
| 3 |
import { Component, useState, xml } from "@odoo/owl"; |
| 4 |
import { createUrl, refresh } from "../core/url"; |
| 5 |
import { callHootKey, useHootKey, useWindowListener } from "../hoot_utils"; |
| 6 |
import { HootButtons } from "./hoot_buttons"; |
| 7 |
import { HootConfigMenu } from "./hoot_config_menu"; |
| 8 |
import { HootDebugToolBar } from "./hoot_debug_toolbar"; |
| 9 |
import { HootDropdown } from "./hoot_dropdown"; |
| 10 |
import { HootReporting } from "./hoot_reporting"; |
| 11 |
import { HootSearch } from "./hoot_search"; |
| 12 |
import { HootSideBar } from "./hoot_side_bar"; |
| 13 |
import { HootStatusPanel } from "./hoot_status_panel"; |
| 14 |
|
| 15 |
/** |
| 16 |
* @typedef {{ |
| 17 |
* }} HootMainProps |
| 18 |
*/ |
| 19 |
|
| 20 |
//----------------------------------------------------------------------------- |
| 21 |
// Global |
| 22 |
//----------------------------------------------------------------------------- |
| 23 |
|
| 24 |
const { setTimeout } = globalThis; |
| 25 |
|
| 26 |
//----------------------------------------------------------------------------- |
| 27 |
// Internal |
| 28 |
//----------------------------------------------------------------------------- |
| 29 |
|
| 30 |
// Indenpendant from Hoot style classes since it is not loaded in headless |
| 31 |
const HEADLESS_CONTAINER_STYLE = [ |
| 32 |
"position: absolute", |
| 33 |
"bottom: 0", |
| 34 |
"inset-inline-start: 50%", |
| 35 |
"transform: translateX(-50%)", |
| 36 |
"display: flex", |
| 37 |
"z-index: 4", |
| 38 |
"margin-bottom: 1rem", |
| 39 |
"padding-left: 1rem", |
| 40 |
"padding-right: 1rem", |
| 41 |
"padding-top: 0.5rem", |
| 42 |
"padding-bottom: 0.5rem", |
| 43 |
"gap: 0.5rem", |
| 44 |
"white-space: nowrap", |
| 45 |
"border-radius: 9999px", |
| 46 |
"box-shadow: 2px 1px 5px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)", |
| 47 |
"background-color: #e2e8f0", |
| 48 |
].join(";"); |
| 49 |
const HEADLESS_LINK_STYLE = ["color: #714b67", "text-decoration: underline"].join(";"); |
| 50 |
|
| 51 |
//----------------------------------------------------------------------------- |
| 52 |
// Exports |
| 53 |
//----------------------------------------------------------------------------- |
| 54 |
|
| 55 |
/** @extends {Component<HootMainProps, import("../hoot").Environment>} */ |
| 56 |
export class HootMain extends Component { |
| 57 |
static components = { |
| 58 |
HootButtons, |
| 59 |
HootConfigMenu, |
| 60 |
HootDebugToolBar, |
| 61 |
HootDropdown, |
| 62 |
HootReporting, |
| 63 |
HootSearch, |
| 64 |
HootSideBar, |
| 65 |
HootStatusPanel, |
| 66 |
}; |
| 67 |
|
| 68 |
static props = {}; |
| 69 |
|
| 70 |
static template = xml` |
| 71 |
<t t-if="env.runner.headless"> |
| 72 |
<div style="${HEADLESS_CONTAINER_STYLE}"> |
| 73 |
Running in headless mode |
| 74 |
<a style="${HEADLESS_LINK_STYLE}" t-att-href="createUrl({ headless: null })"> |
| 75 |
Run with UI |
| 76 |
</a> |
| 77 |
</div> |
| 78 |
</t> |
| 79 |
<t t-else=""> |
| 80 |
<main |
| 81 |
class="${HootMain.name} flex flex-col w-full h-full bg-base relative" |
| 82 |
t-att-class="{ 'hoot-animations': env.runner.config.fun }" |
| 83 |
> |
| 84 |
<header class="flex flex-col bg-gray-200 dark:bg-gray-800"> |
| 85 |
<nav class="hoot-controls py-1 px-2"> |
| 86 |
<h1 |
| 87 |
class="hoot-logo m-0 select-none" |
| 88 |
title="Hierarchically Organized Odoo Tests" |
| 89 |
> |
| 90 |
<strong class="flex">HOOT</strong> |
| 91 |
</h1> |
| 92 |
<HootButtons /> |
| 93 |
<HootSearch /> |
| 94 |
<HootDropdown buttonClassName="'bg-btn'"> |
| 95 |
<t t-set-slot="toggler" t-slot-scope="dropdownState"> |
| 96 |
<i class="fa fa-cog transition" t-att-class="{ 'rotate-90': dropdownState.open }" /> |
| 97 |
</t> |
| 98 |
<t t-set-slot="menu"> |
| 99 |
<HootConfigMenu /> |
| 100 |
</t> |
| 101 |
</HootDropdown> |
| 102 |
</nav> |
| 103 |
</header> |
| 104 |
<HootStatusPanel /> |
| 105 |
<div class="flex h-full overflow-y-auto"> |
| 106 |
<HootSideBar /> |
| 107 |
<HootReporting /> |
| 108 |
</div> |
| 109 |
</main> |
| 110 |
<t t-if="state.debugTest"> |
| 111 |
<HootDebugToolBar test="state.debugTest" /> |
| 112 |
</t> |
| 113 |
</t> |
| 114 |
`; |
| 115 |
|
| 116 |
createUrl = createUrl; |
| 117 |
escapeKeyPresses = 0; |
| 118 |
|
| 119 |
setup() { |
| 120 |
const { runner } = this.env; |
| 121 |
this.state = useState({ |
| 122 |
debugTest: null, |
| 123 |
}); |
| 124 |
|
| 125 |
runner.beforeAll(() => { |
| 126 |
if (!runner.debug) { |
| 127 |
return; |
| 128 |
} |
| 129 |
if (runner.debug === true) { |
| 130 |
this.state.debugTest = runner.state.tests[0]; |
| 131 |
} else { |
| 132 |
this.state.debugTest = runner.debug; |
| 133 |
} |
| 134 |
}); |
| 135 |
runner.afterAll(() => { |
| 136 |
this.state.debugTest = null; |
| 137 |
}); |
| 138 |
|
| 139 |
useWindowListener("resize", (ev) => this.onWindowResize(ev)); |
| 140 |
useWindowListener("keydown", callHootKey, { capture: true }); |
| 141 |
useHootKey(["Enter"], this.manualStart); |
| 142 |
useHootKey(["Escape"], this.abort); |
| 143 |
|
| 144 |
if (!runner.config.headless) { |
| 145 |
useHootKey(["Alt", "d"], this.toggleDebug); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* @param {KeyboardEvent} ev |
| 151 |
*/ |
| 152 |
abort(ev) { |
| 153 |
const { runner } = this.env; |
| 154 |
this.escapeKeyPresses++; |
| 155 |
setTimeout(() => this.escapeKeyPresses--, 500); |
| 156 |
|
| 157 |
if (runner.state.status === "running" && this.escapeKeyPresses >= 2) { |
| 158 |
ev.preventDefault(); |
| 159 |
runner.stop(); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* @param {KeyboardEvent} ev |
| 165 |
*/ |
| 166 |
manualStart(ev) { |
| 167 |
const { runner } = this.env; |
| 168 |
if (runner.state.status !== "ready") { |
| 169 |
return; |
| 170 |
} |
| 171 |
|
| 172 |
ev.preventDefault(); |
| 173 |
|
| 174 |
if (runner.config.manual) { |
| 175 |
runner.manualStart(); |
| 176 |
} else { |
| 177 |
refresh(); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
onWindowResize() { |
| 182 |
this.env.runner.checkPresetForViewPort(); |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* @param {KeyboardEvent} ev |
| 187 |
*/ |
| 188 |
toggleDebug(ev) { |
| 189 |
ev.preventDefault(); |
| 190 |
|
| 191 |
const { runner } = this.env; |
| 192 |
runner.config.debugTest = !runner.config.debugTest; |
| 193 |
} |
| 194 |
} |