/** @odoo-module */ import { Component, onWillRender, useState, xml } from "@odoo/owl"; import { Test } from "../core/test"; import { refresh } from "../core/url"; import { formatTime } from "../hoot_utils"; import { HootTestPath } from "./hoot_test_path"; import { HootTestResult } from "./hoot_test_result"; /** * @typedef {import("../core/expect").Assertion} Assertion * * @typedef {{ * test: Test; * }} HootDebugToolBarProps * * @typedef {import("../core/expect").CaseResult} CaseResult */ /** @extends {Component} */ export class HootDebugToolBar extends Component { static components = { HootTestPath, HootTestResult }; static props = { test: Test, }; static template = xml`
`; formatTime = formatTime; get done() { return Boolean(this.runnerState.done.size); // subscribe to test being added as done } setup() { this.runnerState = useState(this.env.runner.state); this.state = useState({ open: false }); onWillRender(() => { this.info = this.getInfo(); }); } exitDebugMode() { const { runner } = this.env; runner.config.debugTest = false; runner.stop(); } getInfo() { const [status, className] = this.getStatus(); const [assertPassed, assertFailed] = this.groupAssertions( this.props.test.lastResults?.assertions ); return { className, status, passed: assertPassed, failed: assertFailed, }; } getStatus() { if (this.props.test.lastResults) { switch (this.props.test.status) { case Test.PASSED: return ["passed", "pass"]; case Test.FAILED: return ["failed", "fail"]; case Test.ABORTED: return ["aborted", "abort"]; } } return ["running", "skip"]; } /** * @param {Assertion[]} [assertions] */ groupAssertions(assertions) { let passed = 0; let failed = 0; for (const assertion of assertions || []) { if (assertion.pass) { passed++; } else { failed++; } } return [passed, failed]; } restart() { refresh(); } }