43 lines
1.7 KiB
JavaScript
43 lines
1.7 KiB
JavaScript
import { TestCase } from "./framework/test_case.js";
|
|
import { setupDom, teardownDom } from "./framework/dom.js";
|
|
import { valueText, valueNode, resourceNode } from "../client/js/ui/value.js";
|
|
import { setCurrency } from "../client/js/currency.js";
|
|
|
|
export class ValueTest extends TestCase {
|
|
async test_a_value_reads_unit_first_then_a_signed_number() {
|
|
const env = await setupDom();
|
|
try {
|
|
setCurrency({ symbol: "€" });
|
|
this.assertEqual(valueText(1234, { unit: "money" }), "€1\u00a0234");
|
|
this.assertEqual(
|
|
valueText(-1234, { unit: "money", signed: true }),
|
|
"€\u22121\u00a0234",
|
|
"a cost is signed and reads the symbol first"
|
|
);
|
|
this.assertEqual(valueText(1500000, { compact: true }), "1.5M");
|
|
|
|
const $positive = valueNode(1234, { unit: "money", signed: true });
|
|
this.assertEqual($positive.text(), "€+1\u00a0234");
|
|
this.assertTrue($positive.find(".value-number").hasClass("positive"));
|
|
const $negative = valueNode(-1234, { unit: "money", signed: true });
|
|
this.assertTrue($negative.find(".value-number").hasClass("negative"));
|
|
const $stock = valueNode(1234, { unit: "money" });
|
|
this.assertFalse($stock.find(".value-number").hasClass("positive"), "a stock is uncoloured");
|
|
} finally {
|
|
teardownDom(env);
|
|
}
|
|
}
|
|
|
|
async test_a_resource_reads_its_icon_and_unit() {
|
|
const env = await setupDom();
|
|
try {
|
|
const plain = resourceNode("steel", 1234);
|
|
this.assertEqual(plain.text(), "1\u00a0234\u00a0t", "the material keeps its unit");
|
|
const withIcon = resourceNode("steel", 1234, { icon: true });
|
|
this.assertEqual(withIcon.find("img").length, 1, "the icon leads the value");
|
|
} finally {
|
|
teardownDom(env);
|
|
}
|
|
}
|
|
}
|