Warning, /firebird/packages/firebird-ng/api/src/lib/batch-status.service.spec.ts is written in an unsupported language. File is not indexed.
0001 /**
0002 * BatchStatusService publishes display readiness to `window.firebird`, the
0003 * contract `pyrobird screenshot` and other headless drivers wait on: `ready`
0004 * turns true once the startup commands ran and no geometry or event load is
0005 * in flight, also when a load failed (`errors` then says so).
0006 */
0007 import { TestBed } from '@angular/core/testing';
0008 import { provideZonelessChangeDetection } from '@angular/core';
0009 import { CommandBusService } from '@dexvis/app-features';
0010 import { BatchStatusService } from './batch-status.service';
0011
0012 describe('BatchStatusService', () => {
0013 let status: BatchStatusService;
0014 let commandBus: CommandBusService;
0015
0016 /** Runs the effect that writes window.firebird, then reads it. */
0017 const published = () => {
0018 TestBed.tick();
0019 return window.firebird!;
0020 };
0021
0022 beforeEach(() => {
0023 delete window.firebird;
0024 TestBed.configureTestingModule({ providers: [provideZonelessChangeDetection()] });
0025 status = TestBed.inject(BatchStatusService);
0026 commandBus = TestBed.inject(CommandBusService);
0027 });
0028
0029 afterEach(() => {
0030 delete window.firebird;
0031 });
0032
0033 it('is not ready before the startup commands ran', () => {
0034 expect(published()).toEqual({
0035 geometryReady: false,
0036 startupCommandsDone: false,
0037 pendingLoads: 0,
0038 ready: false,
0039 errors: [],
0040 });
0041 });
0042
0043 it('is ready once the startup commands ran and nothing is loading', async () => {
0044 await commandBus.runStartupCommands();
0045 expect(published()).toMatchObject({ startupCommandsDone: true, geometryReady: true, ready: true });
0046 });
0047
0048 it('waits for every geometry and event load in flight', async () => {
0049 await commandBus.runStartupCommands();
0050 status.beginGeometryLoad();
0051 status.beginEventLoad();
0052 status.beginEventLoad();
0053 expect(published()).toMatchObject({ pendingLoads: 3, geometryReady: false, ready: false });
0054
0055 status.endGeometryLoad(true);
0056 status.endEventLoad();
0057 expect(published()).toMatchObject({ pendingLoads: 1, geometryReady: true, ready: false });
0058
0059 status.endEventLoad();
0060 expect(published()).toMatchObject({ pendingLoads: 0, ready: true });
0061 });
0062
0063 it('reports geometry ready after a successful load even before the startup commands ran', () => {
0064 status.beginGeometryLoad();
0065 status.endGeometryLoad(true);
0066 expect(published()).toMatchObject({ geometryReady: true, ready: false });
0067 });
0068
0069 it('settles after a failed load and lists the failure in errors', async () => {
0070 status.beginGeometryLoad();
0071 status.endGeometryLoad(false);
0072 status.addError('Geometry: HTTP 404');
0073 expect(published()).toMatchObject({ geometryReady: false, ready: false });
0074
0075 await commandBus.runStartupCommands();
0076 expect(published()).toMatchObject({ geometryReady: true, ready: true, errors: ['Geometry: HTTP 404'] });
0077 });
0078
0079 it('never counts below zero when a load ends twice', async () => {
0080 await commandBus.runStartupCommands();
0081 status.endEventLoad();
0082 status.endGeometryLoad(false);
0083 status.beginEventLoad();
0084 expect(published()).toMatchObject({ pendingLoads: 1, ready: false });
0085 });
0086 });