/** @odoo-module */ import { Component, useState, xml } from "@odoo/owl"; import { refresh, subscribeToURLParams } from "../core/url"; import { STORAGE, storageSet } from "../hoot_utils"; import { HootLink } from "./hoot_link"; /** * @typedef {{ * }} HootButtonsProps */ //----------------------------------------------------------------------------- // Global //----------------------------------------------------------------------------- const { clearTimeout, Object: { keys: $keys }, setTimeout, } = globalThis; //----------------------------------------------------------------------------- // Internal //----------------------------------------------------------------------------- const DISABLE_TIMEOUT = 500; //----------------------------------------------------------------------------- // Exports //----------------------------------------------------------------------------- /** @extends {Component} */ export class HootButtons extends Component { static components = { HootLink }; static props = {}; static template = xml`
Run all tests Run failed tests Run failed suites
`; setup() { const { runner } = this.env; this.state = useState({ disable: false, open: false, }); this.runnerState = useState(runner.state); this.disableTimeout = 0; subscribeToURLParams(...$keys(runner.config)); } getFailedSuiteIds() { const { tests } = this.env.runner; const suiteIds = []; for (const id of this.runnerState.failedIds) { const test = tests.get(id); if (test && !suiteIds.includes(test.parent.id)) { suiteIds.push(test.parent.id); } } return suiteIds; } onRunClick() { const { runner } = this.env; switch (runner.state.status) { case "done": { refresh(); break; } case "ready": { if (runner.config.manual) { runner.manualStart(); } else { refresh(); } break; } case "running": { runner.stop(); if (this.disableTimeout) { clearTimeout(this.disableTimeout); } this.state.disable = true; this.disableTimeout = setTimeout( () => (this.state.disable = false), DISABLE_TIMEOUT ); break; } } } onRunFailedClick() { storageSet(STORAGE.failed, []); } }