Files
dotnet__skills/eng/dashboard/skill-value.test.js
Abhitej John f8184593b2 Remove duplicate Skill Value sample column (#1148)
* Remove duplicate dashboard sample column

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3f54e78b-35cc-4a23-923e-fae37fb232d1

* Harden Skill Value dashboard test

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3f54e78b-35cc-4a23-923e-fae37fb232d1

---------

Copilot-Session: 3f54e78b-35cc-4a23-923e-fae37fb232d1
2026-09-10 12:58:11 +02:00

88 lines
2.4 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
test('skill value table shows one shared sample-count column', async (t) => {
const previousGlobals = {
document: globalThis.document,
window: globalThis.window,
fetch: globalThis.fetch,
};
const hadGlobal = {
document: Object.hasOwn(globalThis, 'document'),
window: Object.hasOwn(globalThis, 'window'),
fetch: Object.hasOwn(globalThis, 'fetch'),
};
const modulePath = require.resolve('./skill-value.js');
t.after(() => {
for (const name of Object.keys(previousGlobals)) {
if (hadGlobal[name]) {
globalThis[name] = previousGlobals[name];
} else {
delete globalThis[name];
}
}
delete require.cache[modulePath];
});
const elements = new Map();
const wrap = {
innerHTML: '',
querySelector: () => null,
querySelectorAll: () => [],
};
const container = {
innerHTML: '',
querySelector(selector) {
if (selector === '#sv-table-wrap') return wrap;
if (!elements.has(selector)) {
elements.set(selector, {
value: '',
addEventListener: () => {},
});
}
return elements.get(selector);
},
};
globalThis.document = {
createElement: () => ({
set textContent(value) { this.innerHTML = String(value); },
innerHTML: '',
}),
getElementById: () => container,
};
globalThis.window = {};
globalThis.fetch = async () => ({
ok: true,
json: async () => ({
entries: [{
plugin: 'plugin',
model: 'executor',
judgeModel: 'judge',
date: 1,
skills: [{
skill: 'skill',
baseline: { n: 6, timeMs: 1000, tokens: 100 },
treatment: { n: 6, timeMs: 800, tokens: 80 },
activationExpected: 6,
activationFired: 6,
passTotal: 6,
baselineFail: 2,
treatmentFail: 1,
hasPassData: true,
}],
}],
}),
});
require(modulePath);
await window.initSkillValue();
const headerMatch = wrap.innerHTML.match(/<thead><tr>(.*?)<\/tr><\/thead>/s);
assert.ok(headerMatch, 'rendered table contains a header row');
const header = headerMatch[1];
assert.equal((header.match(/<th/g) || []).length, 7);
assert.equal((header.match(/>n<\/th>/g) || []).length, 1);
assert.match(wrap.innerHTML, /colspan="7"/);
});