Files
outlier-saver-extension/test/vidiq.test.js
T
2026-10-25 10:49:23 +03:00

33 lines
1.3 KiB
JavaScript

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);
});