Match the OpenRouter widget's icon style: a small circular badge with the bitcoin glyph in white before the price. Export the bitcoin glyph path and transform from the integrations registry so the ticker and the avatar use the same source.
132 lines
4.1 KiB
Plaintext
132 lines
4.1 KiB
Plaintext
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
|
import { render, click } from '@ember/test-helpers';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import BitcoinTicker from 'dashtab/components/bitcoin-ticker';
|
|
|
|
class FakeBitcoinService {
|
|
@tracked enabled = false;
|
|
@tracked price = null;
|
|
@tracked changePercent = null;
|
|
@tracked error = null;
|
|
}
|
|
|
|
class FakeModalService {
|
|
opened = null;
|
|
|
|
open(descriptor) {
|
|
this.opened = descriptor;
|
|
}
|
|
}
|
|
|
|
module('Integration | Component | bitcoin-ticker', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test('it renders nothing when disabled', async function (assert) {
|
|
const bitcoin = new FakeBitcoinService();
|
|
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
|
|
|
await render(<template><BitcoinTicker /></template>);
|
|
|
|
assert.dom().doesNotContainText('Bitcoin');
|
|
assert.dom('button').doesNotExist();
|
|
});
|
|
|
|
test('it opens the bitcoin settings when enabled', async function (assert) {
|
|
const bitcoin = new FakeBitcoinService();
|
|
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
|
const modal = new FakeModalService();
|
|
this.owner.register('service:modal', modal, { instantiate: false });
|
|
|
|
bitcoin.enabled = true;
|
|
|
|
await render(<template><BitcoinTicker /></template>);
|
|
|
|
assert.dom('button').exists();
|
|
|
|
await click('button');
|
|
|
|
assert.ok(modal.opened.component);
|
|
assert.strictEqual(modal.opened.props.mode, 'edit');
|
|
assert.strictEqual(modal.opened.size, 'md');
|
|
});
|
|
|
|
test('it renders the price and an up triangle when enabled', async function (assert) {
|
|
const bitcoin = new FakeBitcoinService();
|
|
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
|
|
|
bitcoin.enabled = true;
|
|
bitcoin.price = 86246.18;
|
|
bitcoin.changePercent = 3.43;
|
|
|
|
await render(<template><BitcoinTicker /></template>);
|
|
|
|
assert.dom().containsText('$86,246');
|
|
assert.dom('[data-direction="up"]').exists();
|
|
assert.dom('.text-green-400').exists();
|
|
assert.dom().doesNotContainText('%');
|
|
});
|
|
|
|
test('it renders the bitcoin icon circle', async function (assert) {
|
|
const bitcoin = new FakeBitcoinService();
|
|
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
|
|
|
bitcoin.enabled = true;
|
|
|
|
await render(<template><BitcoinTicker /></template>);
|
|
|
|
assert.dom('[data-test-bitcoin-icon]').exists();
|
|
});
|
|
|
|
test('it shows an error message when the fetch fails', async function (assert) {
|
|
const bitcoin = new FakeBitcoinService();
|
|
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
|
|
|
bitcoin.enabled = true;
|
|
bitcoin.error = 'Unable to load the bitcoin price';
|
|
|
|
await render(<template><BitcoinTicker /></template>);
|
|
|
|
assert.dom().containsText('Unable to load the bitcoin price');
|
|
});
|
|
|
|
test('it renders a down triangle for a negative change', async function (assert) {
|
|
const bitcoin = new FakeBitcoinService();
|
|
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
|
|
|
bitcoin.enabled = true;
|
|
bitcoin.price = 86246.18;
|
|
bitcoin.changePercent = -3.43;
|
|
|
|
await render(<template><BitcoinTicker /></template>);
|
|
|
|
assert.dom('[data-direction="down"]').exists();
|
|
assert.dom('.text-red-400').exists();
|
|
assert.dom('.text-green-400').doesNotExist();
|
|
});
|
|
|
|
test('it renders a placeholder before the first price arrives', async function (assert) {
|
|
const bitcoin = new FakeBitcoinService();
|
|
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
|
|
|
bitcoin.enabled = true;
|
|
|
|
await render(<template><BitcoinTicker /></template>);
|
|
|
|
assert.dom().containsText('—');
|
|
});
|
|
|
|
test('it treats a zero change as positive', async function (assert) {
|
|
const bitcoin = new FakeBitcoinService();
|
|
this.owner.register('service:bitcoin', bitcoin, { instantiate: false });
|
|
|
|
bitcoin.enabled = true;
|
|
bitcoin.price = 100;
|
|
bitcoin.changePercent = 0;
|
|
|
|
await render(<template><BitcoinTicker /></template>);
|
|
|
|
assert.dom('[data-direction="up"]').exists();
|
|
});
|
|
});
|