|
1 | | -const ticker = require("../com.courcelle.cryptoticker.sdPlugin/js/ticker.js"); |
| 1 | +const ticker = require("../com.courcelle.cryptoticker-dev.sdPlugin/js/ticker.js"); |
2 | 2 |
|
3 | 3 | test("subscription key builds with conversion", () => { |
4 | 4 | const key = ticker.getSubscriptionContextKey("BITFINEX", "BTCUSD", "USD", "EUR"); |
@@ -28,3 +28,29 @@ test("rounded value adjusts for large numbers", () => { |
28 | 28 | test("normalize value", () => { |
29 | 29 | expect(ticker.normalizeValue(5, 0, 10)).toBeCloseTo(0.5); |
30 | 30 | }); |
| 31 | + |
| 32 | +test("prepareCandlesForDisplay keeps latest entries ordered", () => { |
| 33 | + const candles = [ |
| 34 | + { ts: 100, open: 1, close: 1, high: 2, low: 0, volumeQuote: 10 }, |
| 35 | + { ts: 300, open: 3, close: 4, high: 5, low: 3, volumeQuote: 30 }, |
| 36 | + { ts: 200, open: 2, close: 2, high: 3, low: 1, volumeQuote: 20 } |
| 37 | + ]; |
| 38 | + |
| 39 | + const prepared = ticker.prepareCandlesForDisplay(candles, 2); |
| 40 | + |
| 41 | + expect(prepared).toHaveLength(2); |
| 42 | + expect(prepared[0].ts).toBe(200); |
| 43 | + expect(prepared[1].ts).toBe(300); |
| 44 | +}); |
| 45 | + |
| 46 | +test("getCandlesNormalized spans full width for prepared candles", () => { |
| 47 | + const candles = ticker.prepareCandlesForDisplay([ |
| 48 | + { ts: 100, open: 1, close: 1.5, high: 2, low: 1, volumeQuote: 10 }, |
| 49 | + { ts: 200, open: 1.5, close: 2, high: 2.5, low: 1.5, volumeQuote: 15 } |
| 50 | + ], 2); |
| 51 | + |
| 52 | + const normalized = ticker.getCandlesNormalized(candles); |
| 53 | + |
| 54 | + expect(normalized[0].timePercent).toBeCloseTo(0); |
| 55 | + expect(normalized[normalized.length - 1].timePercent).toBeCloseTo(1); |
| 56 | +}); |
0 commit comments