-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: errors in XAxisTimeLabelsGenerator after prepending candles
- Loading branch information
Showing
5 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import './env'; | ||
import { createChart } from '../../index'; | ||
import { generateCandlesDataTS } from '../utils/candles-generator-ts.utils'; | ||
|
||
describe('chart', () => { | ||
const candles = generateCandlesDataTS({ quantity: 50 }); | ||
|
||
it.each([ | ||
['zero -> non-zero candles', [[], candles]], | ||
['prepend candles', [candles.slice(10), candles.slice(0, 10)]], | ||
['prepend with a gap', [candles.slice(0, 10), candles.slice(20, 30)]], | ||
['prepend with overlap', [candles.slice(10), candles.slice(0, 20)]], | ||
['only update existing candles', [candles, candles.slice(10, 20)]], | ||
['update all candles', [candles, candles]], | ||
['append candles', [candles.slice(0, 10), candles.slice(10)]], | ||
['append candles with a gap', [candles.slice(0, 10), candles.slice(20)]], | ||
['append candles with overlap', [candles.slice(0, 20), candles.slice(10)]], | ||
['prepend and append', [candles.slice(10, 20), candles.slice(0, 30)]], | ||
[ | ||
"fill in the gap (won't work but should not error)", | ||
[candles.slice(0, 10), candles.slice(11, 20), candles.slice(10, 11)], | ||
], | ||
])('should update candles in various scenarios: %s', async (scenario, updates) => { | ||
const div = document.createElement('div'); | ||
const chart = createChart(div); | ||
updates.forEach((update, i) => { | ||
if (i === 0) { | ||
chart.setData({ candles: update }); | ||
} else { | ||
chart.updateData({ candles: update }); | ||
} | ||
}); | ||
// wait for async tasks to complete successfully | ||
await new Promise(done => setTimeout(done, 100)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* @see https://jestjs.io/docs/29.4/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom */ | ||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation(query => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // deprecated | ||
removeListener: jest.fn(), // deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn(), | ||
})), | ||
}); | ||
|
||
Object.defineProperty(window, 'ResizeObserver', { | ||
writable: true, | ||
value: jest.fn().mockImplementation( | ||
(): ResizeObserver => ({ | ||
observe: jest.fn(), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn(), | ||
}), | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters