Files
raucao 73b34a3ead Add OpenRouter usage stats widget
Add a per-user OpenRouter usage integration that reads the management key
and displays a single spend total next to the Bitcoin ticker.

The total is configurable to Today, This week or This month, defaulting to
Today. Analytics queries are widened to the previous UTC hour boundary and
then filtered locally so buckets in non-whole-hour timezones are not
clipped.
2026-11-13 14:51:38 +04:00

102 lines
3.2 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render } from '@ember/test-helpers';
import Avatar from 'dashtab/components/settings/integrations/avatar';
const PNG_ICON =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
module(
'Integration | Component | settings/integrations/avatar',
function (hooks) {
setupRenderingTest(hooks);
test('it renders a resolved maskable site icon full-bleed', async function (assert) {
this.integration = {
icon: { dataUrl: PNG_ICON, maskable: true },
};
await render(
<template><Avatar @integration={{this.integration}} /></template>
);
assert.dom('img').exists().hasAttribute('src', PNG_ICON);
assert.dom('img').hasClass('object-cover');
assert.dom('span').hasClass('icon-edge-no-highlight');
assert.dom('svg').doesNotExist();
});
test('it renders a non-maskable site icon inset', async function (assert) {
this.integration = {
icon: { dataUrl: PNG_ICON, maskable: false },
};
await render(
<template><Avatar @integration={{this.integration}} /></template>
);
assert.dom('img').hasAttribute('src', PNG_ICON);
assert.dom('img').hasClass('object-contain');
});
test('it renders a bundled image icon', async function (assert) {
this.integration = { iconUrl: '/img/icons/feedbin.png' };
await render(
<template><Avatar @integration={{this.integration}} /></template>
);
assert.dom('img').hasAttribute('src', '/img/icons/feedbin.png');
assert.dom('svg').doesNotExist();
});
test('it renders an inset bundled icon when the icon is not maskable', async function (assert) {
this.integration = {
iconUrl: '/img/icons/openrouter.svg',
iconInset: true,
};
await render(
<template><Avatar @integration={{this.integration}} /></template>
);
assert.dom('img').hasAttribute('src', '/img/icons/openrouter.svg');
assert.dom('img').hasClass('object-contain');
});
test('it paints the backdrop behind a transparent bundled icon', async function (assert) {
this.integration = {
iconUrl: '/img/icons/github-inverted.png',
themeColor: '#1f2937',
};
await render(
<template><Avatar @integration={{this.integration}} /></template>
);
assert.dom('img').hasAttribute('src', '/img/icons/github-inverted.png');
assert
.dom('span')
.hasAttribute('style', /background-color:\s*rgb\(31, 41, 55\)/);
});
test('it falls back to the brand color and glyph', async function (assert) {
this.integration = {
colorClass: 'bg-indigo-500',
iconPath: 'M0 0h24v24H0z',
iconTransform: 'scale(2)',
iconFill: false,
};
await render(
<template><Avatar @integration={{this.integration}} /></template>
);
assert.dom('img').doesNotExist();
assert.dom('svg').exists();
assert.dom('svg path').hasAttribute('d', 'M0 0h24v24H0z');
assert.dom('svg path').hasAttribute('transform', 'scale(2)');
});
}
);