Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 19, 2025

Overview

Fixed two failing unit tests in the time-planning-pn plugin components that were preventing the CI/CD pipeline from passing.

Issues Fixed

1. AssignedSiteDialogComponent Test Expectations

The test should copy break settings from global settings for monday was failing because it expected numeric minute values, but the implementation converts these to time strings.

The Problem:

// Test expected:
expect(mondayBreak?.get('breakMinutesDivider')?.value).toBe(480);

// But copyBreakSettings() calls getConvertedValue() which returns:
getConvertedValue(480) // Returns "08:00"

The Fix:
Updated test expectations to match the actual converted string format:

  • 480 minutes → "08:00"
  • 30 minutes → "00:30"
  • 60 minutes → "01:00"

2. DownloadExcelDialogComponent RxJS Error

The onDownloadExcelReportAllWorkers and onDownloadExcelReport methods were using catchError incorrectly, causing the error:

TypeError: You provided an invalid object where a stream was expected.

The Problem:

.pipe(catchError(
  (caught) => {
    this.toastrService.error('Error downloading report');
    return caught; // ❌ Invalid: caught is not an observable
  }))

The Fix:

  • Imported EMPTY from rxjs
  • Changed catchError to return EMPTY (a valid empty observable)
  • Updated parameter naming from caught to error for clarity
.pipe(catchError(
  (error) => {
    this.toastrService.error('Error downloading report');
    return EMPTY; // ✅ Valid: EMPTY is a proper observable
  }))

Test Results

All 119 tests in the time-planning-pn module now pass:

  • ✅ AssignedSiteDialogComponent: 23 tests
  • ✅ DownloadExcelDialogComponent: 9 tests
  • ✅ Other time-planning-pn components: 87 tests

The console warnings about navigation in jsdom are expected browser API limitations in the test environment and do not affect test functionality.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix broken unit tests</issue_title>
<issue_description>```
FAIL src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/assigned-site/assigned-site-dialog.component.spec.ts (30.226 s)
● AssignedSiteDialogComponent › Break Settings › should copy break settings from global settings for monday

expect(received).toBe(expected) // Object.is equality

Expected: 480
Received: "08:00"

  232 |       
  233 |       const mondayBreak = component.assignedSiteForm.get('autoBreakSettings')?.get('monday');
> 234 |       expect(mondayBreak?.get('breakMinutesDivider')?.value).toBe(480);
      |                                                              ^
  235 |       expect(mondayBreak?.get('breakMinutesPrDivider')?.value).toBe(30);
  236 |       expect(mondayBreak?.get('breakMinutesUpperLimit')?.value).toBe(60);
  237 |     });

  at src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/assigned-site/assigned-site-dialog.component.spec.ts:234:62
  at _ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:410:32)
  at ProxyZoneSpec.onInvoke (node_modules/zone.js/bundles/zone-testing.umd.js:2219:43)
  at _ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:409:38)
  at ZoneImpl.run (node_modules/zone.js/bundles/zone.umd.js:145:47)
  at Object.wrappedFunc (node_modules/zone.js/bundles/zone-testing.umd.js:449:38)

FAIL src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/download-excel/download-excel-dialog.component.spec.ts (7.579 s)
● Console

console.error
  Error: Not implemented: navigation (except hash changes)
      at module.exports (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
      at navigateFetch (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/window/navigation.js:77:3)
      at exports.navigate (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/window/navigation.js:55:3)
      at Timeout._onTimeout (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/nodes/HTMLHyperlinkElementUtils-impl.js:81:7)
      at listOnTimeout (node:internal/timers:581:17)
      at processTimers (node:internal/timers:519:7) {
    type: 'not implemented'
  }

  at VirtualConsole.<anonymous> (node_modules/jest-environment-jsdom/build/index.js:63:23)

console.error
  Error: Uncaught [TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.]
      at reportException (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
      at Timeout.task [as _onTimeout] (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js:525:9)
      at listOnTimeout (node:internal/timers:581:17)
      at processTimers (node:internal/timers:519:7) {
    detail: TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.
        at Object.createInvalidObservableTypeError (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/util/throwUnobservableError.js:5:12)
        at Object.innerFrom (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/observable/innerFrom.js:93:36)
        at /home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/operators/catchError.js:13:41
        at OperatorSubscriber._this._error (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/operators/OperatorSub...

Fixes #1121


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Fix broken unit tests for AssignedSiteDialogComponent Fix broken unit tests in time-planning-pn components Oct 19, 2025
@Copilot Copilot AI requested a review from renemadsen October 19, 2025 11:06
Copilot finished work on behalf of renemadsen October 19, 2025 11:06
@renemadsen renemadsen marked this pull request as ready for review October 19, 2025 17:14
@renemadsen renemadsen merged commit 4833f3b into master Oct 19, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix broken unit tests

2 participants