diff --git a/src/app/components/apps-view/apps-view.component.spec.ts b/src/app/components/apps-view/apps-view.component.spec.ts index 951b932e..a1b90dc6 100644 --- a/src/app/components/apps-view/apps-view.component.spec.ts +++ b/src/app/components/apps-view/apps-view.component.spec.ts @@ -30,7 +30,7 @@ import { MatTooltipModule } from '@angular/material/tooltip'; import { By, HAMMER_LOADER } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; -import { AppInfo } from '@app/models/app-info.model'; +import { AppInfo, StateLog } from '@app/models/app-info.model'; import { SchedulerService } from '@app/services/scheduler/scheduler.service'; import { MockNgxSpinnerService, MockSchedulerService } from '@app/testing/mocks'; import { NgxSpinnerService } from 'ngx-spinner'; @@ -108,4 +108,47 @@ describe('AppsViewComponent', () => { copyButton.triggerEventHandler('click', null); expect(copyButtonSpy).toHaveBeenCalled(); }); -}); + + it('should set lastStateChangeTime to the latest time in stateLog', () => { + const stateLogs = [ + new StateLog(100, 'SUBMITTED'), + new StateLog(200, 'RUNNING'), + new StateLog(300, 'FINISHED') + ]; + const appInfo = new AppInfo( + 'app-test', + 'Memory: 10.0 MB, CPU: 1, pods: 1', + 'Memory: 0.0 bytes, CPU: 0, pods: n/a', + '', + 123, + null, + stateLogs, + null, + 'FINISHED', + [] + ); + + appInfo.setLastStateChangeTime(); + + expect(appInfo.lastStateChangeTime).toBe(300); + }); + + it('should set lastStateChangeTime to 0 if stateLog is empty', () => { + const appInfo = new AppInfo( + 'app-empty', + 'Memory: 10.0 MB, CPU: 1, pods: 1', + 'Memory: 0.0 bytes, CPU: 0, pods: n/a', + '', + 123, + null, + [], + null, + 'SUBMITTED', + [] + ); + + appInfo.setLastStateChangeTime(); + + expect(appInfo.lastStateChangeTime).toBe(0); + }); +}); \ No newline at end of file diff --git a/src/app/models/app-info.model.ts b/src/app/models/app-info.model.ts index 3e3c1a07..76055a53 100644 --- a/src/app/models/app-info.model.ts +++ b/src/app/models/app-info.model.ts @@ -30,11 +30,16 @@ export class AppInfo { public maxUsedResource: string, public submissionTime: number, public finishedTime: null | number, - public stateLog: Array, + public stateLog: Array = [], // Default to empty array public lastStateChangeTime: null | number, public applicationState: string, public allocations: AllocationInfo[] | null - ) {} + ) { + // Ensure stateLog is always an array + if (!Array.isArray(this.stateLog)) { + this.stateLog = []; + } + } get formattedSubmissionTime() { const millisecs = Math.round(this.submissionTime / (1000 * 1000));