feat: add VidIQ badge reader with unset selector

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
IgorVolochay
2026-10-25 10:49:23 +03:00
co-authored by Claude Sonnet 5.5
parent b52c847068
commit 10f5c095b2
2 changed files with 46 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { VIDIQ_BADGE_SELECTOR, parseVidiqScore, readVidiqScore } from '../src/lib/vidiq.js';
test('parseVidiqScore extracts the first number', () => {
assert.equal(parseVidiqScore('12.5x'), 12.5);
assert.equal(parseVidiqScore('5,2x'), 5.2);
assert.equal(parseVidiqScore('Outlier 8'), 8);
});
test('parseVidiqScore returns null when there is no number', () => {
assert.equal(parseVidiqScore('no digits here'), null);
assert.equal(parseVidiqScore(''), null);
assert.equal(parseVidiqScore(null), null);
assert.equal(parseVidiqScore(undefined), null);
});
test('readVidiqScore returns null while no selector is configured', () => {
assert.equal(VIDIQ_BADGE_SELECTOR, null);
const card = { querySelector: () => ({ textContent: '9x' }) };
assert.equal(readVidiqScore(card), null);
});
test('readVidiqScore reads the badge inside a card', () => {
const card = { querySelector: (selector) => (selector === '.badge' ? { textContent: '7.5x' } : null) };
assert.equal(readVidiqScore(card, '.badge'), 7.5);
});
test('readVidiqScore returns null when the card has no badge or no card is given', () => {
assert.equal(readVidiqScore({ querySelector: () => null }, '.badge'), null);
assert.equal(readVidiqScore(null, '.badge'), null);
});