chore [UKD-346]: фикс детекта ошибок
This commit is contained in:
1 parent
00a6c9d98b
commit
36b46a6083
5 files changed
+681
-7
No files matched your search
@@ -39,6 +39,41 @@ function payload() {
|
||||
}
|
||||
const flush = () => new Promise(resolve => setImmediate(resolve));
|
||||
|
||||
test('null response is a data error and preserves previous readings', async () => {
|
||||
let data = null;
|
||||
const ui = setup(async () => ({ ok: true, json: async () => data }));
|
||||
await flush();
|
||||
assert.equal(ui.elements.get('.metrics-panel').dataset.state, 'error');
|
||||
assert.match(ui.elements.get('#metrics-note').textContent, /Некорректные данные/);
|
||||
data = payload();
|
||||
await vm.runInContext('pollMetrics()', ui.context);
|
||||
data = null;
|
||||
await vm.runInContext('pollMetrics()', ui.context);
|
||||
assert.equal(ui.elements.get('.metrics-panel').dataset.state, 'stale');
|
||||
assert.equal(ui.elements.get('#cpu-value').textContent, '15%');
|
||||
assert.match(ui.elements.get('#metrics-note').textContent, /Некорректные данные/);
|
||||
});
|
||||
|
||||
test('invalid JSON is reported as a data error', async () => {
|
||||
const ui = setup(async () => ({ ok: true, json: async () => { throw new SyntaxError('Invalid JSON'); } }));
|
||||
await flush();
|
||||
assert.equal(ui.elements.get('.metrics-panel').dataset.state, 'error');
|
||||
assert.match(ui.elements.get('#metrics-note').textContent, /Некорректные данные/);
|
||||
});
|
||||
|
||||
test('network and body transfer failures are reported as connection errors', async () => {
|
||||
for (const fetch of [
|
||||
async () => { throw new TypeError('Failed to fetch'); },
|
||||
async () => ({ ok: true, json: async () => { throw new TypeError('Connection lost'); } }),
|
||||
async () => ({ ok: true, json: async () => { throw new DOMException('Aborted', 'AbortError'); } }),
|
||||
]) {
|
||||
const ui = setup(fetch);
|
||||
await flush();
|
||||
assert.equal(ui.elements.get('.metrics-panel').dataset.state, 'error');
|
||||
assert.match(ui.elements.get('#metrics-note').textContent, /Нет связи/);
|
||||
}
|
||||
});
|
||||
|
||||
test('live → stale → recovered preserves the last readings', async () => {
|
||||
let online = true;
|
||||
const ui = setup(async () => ({ ok: online, json: async () => online ? payload() : { error: 'metrics_unavailable' } }));
|
||||
|
||||
Reference in new issue
Block a user