mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-09-16 01:33:09 +00:00
Merge PR #526: охват сегментов и прогресс доставки на странице отправки
This commit is contained in:
27
src/utils/broadcastStatus.test.ts
Normal file
27
src/utils/broadcastStatus.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { broadcastPollInterval, isBroadcastInFlight } from './broadcastStatus';
|
||||
|
||||
describe('broadcastStatus', () => {
|
||||
it('treats queued, in-progress and cancelling deliveries as running', () => {
|
||||
expect(isBroadcastInFlight('queued')).toBe(true);
|
||||
expect(isBroadcastInFlight('in_progress')).toBe(true);
|
||||
expect(isBroadcastInFlight('cancelling')).toBe(true);
|
||||
});
|
||||
|
||||
it('treats finished deliveries as done', () => {
|
||||
expect(isBroadcastInFlight('completed')).toBe(false);
|
||||
expect(isBroadcastInFlight('partial')).toBe(false);
|
||||
expect(isBroadcastInFlight('failed')).toBe(false);
|
||||
expect(isBroadcastInFlight('cancelled')).toBe(false);
|
||||
});
|
||||
|
||||
it('handles a missing status without polling', () => {
|
||||
expect(isBroadcastInFlight(undefined)).toBe(false);
|
||||
expect(broadcastPollInterval(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it('polls only while the delivery is running', () => {
|
||||
expect(broadcastPollInterval('in_progress')).toBe(3000);
|
||||
expect(broadcastPollInterval('completed')).toBe(false);
|
||||
});
|
||||
});
|
||||
13
src/utils/broadcastStatus.ts
Normal file
13
src/utils/broadcastStatus.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/** Статусы, при которых доставка ещё идёт и запись рассылки нужно перезапрашивать. */
|
||||
export const BROADCAST_IN_FLIGHT_STATUSES = ['queued', 'in_progress', 'cancelling'] as const;
|
||||
|
||||
/** Доставка ещё не завершена: показываем прогресс и продолжаем поллинг. */
|
||||
export function isBroadcastInFlight(status: string | undefined): boolean {
|
||||
if (!status) return false;
|
||||
return (BROADCAST_IN_FLIGHT_STATUSES as readonly string[]).includes(status);
|
||||
}
|
||||
|
||||
/** Интервал поллинга для react-query: пока идёт доставка — 3 секунды, иначе не опрашиваем. */
|
||||
export function broadcastPollInterval(status: string | undefined): number | false {
|
||||
return isBroadcastInFlight(status) ? 3000 : false;
|
||||
}
|
||||
Reference in New Issue
Block a user