/** @odoo-module */ import { Component, onWillRender, useState, xml } from "@odoo/owl"; import { Test } from "../core/test"; import { formatTime, parseQuery } from "../hoot_utils"; import { HootJobButtons } from "./hoot_job_buttons"; import { HootLogCounters } from "./hoot_log_counters"; import { HootTestPath } from "./hoot_test_path"; import { HootTestResult } from "./hoot_test_result"; /** * @typedef {import("../core/test").Test} Test * * @typedef {{ * }} HootReportingProps */ //----------------------------------------------------------------------------- // Global //----------------------------------------------------------------------------- const { Boolean } = globalThis; //----------------------------------------------------------------------------- // Internal //----------------------------------------------------------------------------- /** * @param {keyof import("../core/runner").Runner["state"]} varName * @param {string} colorClassName */ const issueTemplate = (varName, colorClassName) => /* xml */ `

Global (x) : stack trace available in the console

`; /** * @param {Test} a * @param {Test} b */ function sortByDurationAscending(a, b) { return a.duration - b.duration; } /** * @param {Test} a * @param {Test} b */ function sortByDurationDescending(a, b) { return b.duration - a.duration; } const COLORS = { failed: "text-rose", passed: "text-emerald", skipped: "text-cyan", todo: "text-purple", }; //----------------------------------------------------------------------------- // Exports //----------------------------------------------------------------------------- /** @extends {Component} */ export class HootReporting extends Component { static components = { HootLogCounters, HootJobButtons, HootTestPath, HootTestResult, }; static props = {}; static template = xml`
${issueTemplate("globalErrors", "rose")} ${issueTemplate("globalWarnings", "amber")}
skipped aborted after
No tests found matching in suite .

Test runner is ready

or press Enter Waiting for assets

/ tests completed

  • tests passed
  • tests failed
  • tests skipped
  • tests to do
`; Test = Test; formatTime = formatTime; setup() { const { runner, ui } = this.env; this.config = useState(runner.config); this.runnerReporting = useState(runner.reporting); this.runnerState = useState(runner.state); this.state = useState({ /** @type {string[]} */ openGroups: [], /** @type {string[]} */ openTests: [], }); this.uiState = useState(ui); const { showdetail } = this.config; let didShowDetail = false; runner.afterPostTest((test) => { if ( showdetail && !(showdetail === "first-fail" && didShowDetail) && [Test.FAILED, Test.ABORTED].includes(test.status) ) { didShowDetail = true; this.state.openTests.push(test.id); } }); onWillRender(() => { this.filteredResults = this.computeFilteredResults(); this.uiState.totalResults = this.filteredResults.length; }); } computeFilteredResults() { const { selectedSuiteId, sortResults, statusFilter } = this.uiState; const queryFilter = this.getQueryFilter(); const results = []; for (const test of this.runnerState.done) { let matchFilter = false; switch (statusFilter) { case "failed": { matchFilter = !test.config.skip && test.results.some((r) => !r.pass); break; } case "passed": { matchFilter = !test.config.todo && !test.config.skip && test.results.some((r) => r.pass); break; } case "skipped": { matchFilter = test.config.skip; break; } case "todo": { matchFilter = test.config.todo; break; } default: { matchFilter = Boolean(selectedSuiteId) || test.results.some((r) => !r.pass); break; } } if (matchFilter && selectedSuiteId) { matchFilter = test.path.some((suite) => suite.id === selectedSuiteId); } if (matchFilter && queryFilter) { matchFilter = queryFilter(test.key); } if (!matchFilter) { continue; } results.push({ duration: test.lastResults?.duration, status: test.status, id: `test#${test.id}`, test: test, }); } if (!sortResults) { return results; } return results.sort( sortResults === "asc" ? sortByDurationAscending : sortByDurationDescending ); } /** * @param {typeof this.uiState.statusFilter} status */ filterResults(status) { this.uiState.resultsPage = 0; if (this.uiState.statusFilter === status) { this.uiState.statusFilter = null; } else { this.uiState.statusFilter = status; } } getEmptyMessage() { const { selectedSuiteId, statusFilter } = this.uiState; if (!statusFilter && !selectedSuiteId) { return null; } return { statusFilter, statusFilterClassName: COLORS[statusFilter], filter: this.config.filter, selectedSuiteName: selectedSuiteId && this.env.runner.suites.get(selectedSuiteId).name, }; } getQueryFilter() { const parsedQuery = parseQuery(this.config.filter || ""); if (!parsedQuery.length) { return null; } return (key) => parsedQuery.every((qp) => { const pass = qp.matchValue(key); return qp.exclude ? !pass : pass; }); } onRunClick() { this.env.runner.manualStart(); } /** * @param {PointerEvent} ev * @param {string} id */ toggleGroup(ev, id) { const index = this.state.openGroups.indexOf(id); if (ev.altKey) { if (index in this.state.openGroups) { this.state.openGroups = []; } else { this.state.openGroups = this.filteredResults .filter((r) => r.suite) .map((r) => r.suite.id); } } else { if (index in this.state.openGroups) { this.state.openGroups.splice(index, 1); } else { this.state.openGroups.push(id); } } } }