/** @odoo-module */ import { Component, useState, xml } from "@odoo/owl"; import { CONFIG_KEYS } from "../core/config"; import { LOG_LEVELS } from "../core/logger"; import { refresh } from "../core/url"; import { CASE_EVENT_TYPES, strictEqual } from "../hoot_utils"; import { generateSeed, internalRandom } from "../mock/math"; import { toggleColorScheme, useColorScheme } from "./hoot_colors"; import { HootCopyButton } from "./hoot_copy_button"; /** * @typedef {"dark" | "light"} ColorScheme * * @typedef {{ * }} HootConfigMenuProps */ //----------------------------------------------------------------------------- // Global //----------------------------------------------------------------------------- const { Object: { entries: $entries, keys: $keys, values: $values }, } = globalThis; //----------------------------------------------------------------------------- // Exports //----------------------------------------------------------------------------- /** @extends {Component} */ export class HootConfigMenu extends Component { static components = { HootCopyButton }; static props = {}; static template = xml`

Behavior

Preset
Execution order
Seed: Failed tests: Level:

Display

Events
`; CASE_EVENT_TYPES = CASE_EVENT_TYPES; executionOrders = [ { value: "fifo", title: "First in, first out", icon: "fa-sort-numeric-asc" }, { value: "lifo", title: "Last in, first out", icon: "fa-sort-numeric-desc" }, { value: "random", title: "Random", icon: "fa-random" }, ]; LOG_LEVELS = $entries(LOG_LEVELS) .filter(([, value]) => value) .map(([label, value]) => ({ label, value })); refresh = refresh; toggleColorScheme = toggleColorScheme; setup() { const { runner, ui } = this.env; this.color = useColorScheme(); this.config = useState(runner.config); this.uiState = useState(ui); } doesNotNeedRefresh() { return CONFIG_KEYS.every((key) => strictEqual(this.config[key], this.env.runner.initialConfig[key]) ); } hasPresets() { return $keys(this.env.runner.presets).filter(Boolean).length > 0; } /** * @param {keyof CASE_EVENT_TYPES} sType */ isEventDisplayed(sType) { return this.config.events & CASE_EVENT_TYPES[sType].value; } /** * @param {Event & { currentTarget: HTMLInputElement }} ev */ onBailChange(ev) { this.config.bail = ev.currentTarget.checked ? 1 : 0; } /** * @param {Event & { currentTarget: HTMLInputElement }} ev */ onLogLevelChange(ev) { this.config.loglevel = ev.currentTarget.checked ? LOG_LEVELS.suites : LOG_LEVELS.runner; } /** * @param {string} presetId */ onPresetChange(presetId) { this.config.preset = this.config.preset === presetId ? "" : presetId; } resetSeed() { const newSeed = generateSeed(); this.config.random = newSeed; internalRandom.seed = newSeed; } /** * @param {"fifo" | "lifo" | "random"} order */ setExecutionOrder(order) { this.config.order = order; if (order === "random" && !this.config.random) { this.resetSeed(); } else if (this.config.random) { this.config.random = 0; } } /** * @param {PointerEvent} ev * @param {import("../core/expect").CaseEventType} sType */ toggleEventType(ev, sType) { const nType = CASE_EVENT_TYPES[sType].value; if (this.config.events & nType) { if (ev.altKey) { this.config.events = 0; } else { this.config.events &= ~nType; } } else { if (ev.altKey) { // Aggregate all event types this.config.events = $values(CASE_EVENT_TYPES).reduce((acc, t) => acc + t.value, 0); } else { this.config.events |= nType; } } } toggleSortResults() { this.uiState.resultsPage = 0; if (!this.uiState.sortResults) { this.uiState.sortResults = "desc"; } else if (this.uiState.sortResults === "desc") { this.uiState.sortResults = "asc"; } else { this.uiState.sortResults = false; } } }