Skip to content

WEB-882: Add unit tests for CloseClientComponent#3425

Open
Agaba-Ed wants to merge 1 commit intoopenMF:devfrom
Agaba-Ed:unit-test-close-client
Open

WEB-882: Add unit tests for CloseClientComponent#3425
Agaba-Ed wants to merge 1 commit intoopenMF:devfrom
Agaba-Ed:unit-test-close-client

Conversation

@Agaba-Ed
Copy link

@Agaba-Ed Agaba-Ed commented Mar 21, 2026

Description

Added unit test coverage for CloseClientComponent, which previously had no test file. The tests verify component initialization, form validation for the two required fields (closureDate and closureReasonId), date formatting logic for both Date objects and raw strings, correct API payload structure on submit, post-submission navigation, and graceful handling of API errors.

Related issues and discussion

#WEB-882

Summary by CodeRabbit

  • Tests
    • Added a comprehensive unit test suite for the Close Client component. Covers component initialization, form validation state transitions, submission behavior, date formatting logic, successful API interactions and navigation, and error handling when the API call fails.

@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'pre_merge_checks'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 17e708ee-621f-48c4-a641-435e422d11e7

📥 Commits

Reviewing files that changed from the base of the PR and between ad35397 and 7a4b8ea.

📒 Files selected for processing (1)
  • src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts

Walkthrough

Adds a Jest-based Angular unit test suite for CloseClientComponent validating initialization, form validation, date formatting behavior, ClientsService call payloads, and navigation/error handling on submit. (49 words)

Changes

Cohort / File(s) Summary
Test Suite for CloseClientComponent
src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts
New Jest unit tests: sets up TestBed with mocked Router/ActivatedRoute/ClientsService/SettingsService/Dates; verifies clientId and maxDate initialization, form validity transitions, Dates.formatDate usage (and non-usage when date is string), ClientsService.executeClientCommand payload, and router navigation behavior on success/error.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • steinwinde
  • alberto-art3ch
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding unit tests for CloseClientComponent, which aligns with the changeset that adds a comprehensive test suite file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (4)
src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts (4)

70-75: Type the date parameter explicitly.

The date parameter is typed as any, but based on usage it should be Date | string.

♻️ Suggested fix
-  const fillValidForm = (date: any = new Date(2025, 10, 3)) => {
+  const fillValidForm = (date: Date | string = new Date(2025, 10, 3)) => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts`
around lines 70 - 75, The helper function fillValidForm declares its date
parameter as any; change the parameter type to Date | string to match how
closureDate is used and avoid any typing gaps — update the signature of
fillValidForm(date: Date | string = new Date(2025, 10, 3)) and ensure any calls
passing strings or Date objects still work with
component.closeClientForm.patchValue({ closureDate: date, closureReasonId: 1 }).

130-138: Consider adding an assertion for error state.

The test verifies that navigation doesn't occur on failure, which is good. However, it doesn't assert that the component actually handles the error gracefully (e.g., an error message state or that no exception is thrown). Consider adding an assertion to verify the component's error state or that no unhandled errors propagate.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts`
around lines 130 - 138, The test currently stubs
clientsService.executeClientCommand to throw and only asserts router.navigate
was not called; update the test to also assert the component's error handling by
checking a visible error state or flag (e.g., component.errorMessage or
component.hasError) after calling fillValidForm() and component.submit(), and/or
assert that component.submit() does not throw (wrap call in try/catch or use
expect(() => component.submit()).not.toThrow()); reference
clientsService.executeClientCommand, fillValidForm(), component.submit(), and
router.navigate to locate where to add these assertions.

27-41: Consider using stricter mock typing instead of as any.

The mocks use as any to bypass type checking, which reduces type safety. Per project learnings, avoid using any as a pattern. Consider using Partial<T> or jest.Mocked<Partial<T>> for better type safety while still allowing partial mocks.

♻️ Suggested improvement
-    router = { navigate: jest.fn() } as any;
+    router = { navigate: jest.fn() } as jest.Mocked<Pick<Router, 'navigate'>>;

-    clientsService = {
-      executeClientCommand: jest.fn(() => of({}))
-    } as any;
+    clientsService = {
+      executeClientCommand: jest.fn(() => of({}))
+    } as jest.Mocked<Pick<ClientsService, 'executeClientCommand'>>;

-    settingsService = {
-      language: { code: 'en' },
-      dateFormat: 'dd MMMM yyyy',
-      businessDate
-    } as any;
+    settingsService = {
+      language: { code: 'en' },
+      dateFormat: 'dd MMMM yyyy',
+      businessDate
+    } as Partial<SettingsService> as SettingsService;

-    dates = {
-      formatDate: jest.fn(() => '20 March 2026')
-    } as any;
+    dates = {
+      formatDate: jest.fn(() => '20 March 2026')
+    } as jest.Mocked<Pick<Dates, 'formatDate'>>;

Based on learnings: "avoid using Observable as a project-wide pattern for API responses... introduce specific interfaces/types... and use proper typing instead of any."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts`
around lines 27 - 41, Replace the loose "as any" mocks with properly typed
partial mocks: declare router as Partial<Router> or jest.Mocked<Partial<Router>>
with navigate: jest.fn(); clientsService as Partial<ClientsService> or
jest.Mocked<Partial<ClientsService>> and type executeClientCommand as a jest
mock returning of({}); settingsService as Partial<SettingsService> with
language, dateFormat and businessDate typed; and dates as Partial<DatesService>
with formatDate mocked. Import the relevant interfaces/types (Router,
ClientsService, SettingsService, DatesService) and use Partial<T> or
jest.Mocked<Partial<T>> so TypeScript enforces correct shapes while keeping the
existing jest.fn() mocks (referencing the identifiers router,
clientsService.executeClientCommand, settingsService, and dates.formatDate).

140-149: This test partially duplicates the earlier submit test.

Lines 108-109 already assert locale and dateFormat in the payload. This test provides explicit isolation of that concern, which is acceptable for documentation purposes, but consider whether it adds enough value given the redundancy.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts`
around lines 140 - 149, This test duplicates assertions already checked in the
earlier submit test; remove the redundant "should always include locale and
dateFormat" test (including calls to fillValidForm, component.submit, and the
clientsService.executeClientCommand payload assertions) or, alternatively,
collapse its assertions into the earlier submit test so only one test verifies
payload.locale and payload.dateFormat; if you choose to keep it, change it to a
minimal, focused unit test that only constructs the payload and asserts
locale/dateFormat without duplicating full form submission logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts`:
- Around line 70-75: The helper function fillValidForm declares its date
parameter as any; change the parameter type to Date | string to match how
closureDate is used and avoid any typing gaps — update the signature of
fillValidForm(date: Date | string = new Date(2025, 10, 3)) and ensure any calls
passing strings or Date objects still work with
component.closeClientForm.patchValue({ closureDate: date, closureReasonId: 1 }).
- Around line 130-138: The test currently stubs
clientsService.executeClientCommand to throw and only asserts router.navigate
was not called; update the test to also assert the component's error handling by
checking a visible error state or flag (e.g., component.errorMessage or
component.hasError) after calling fillValidForm() and component.submit(), and/or
assert that component.submit() does not throw (wrap call in try/catch or use
expect(() => component.submit()).not.toThrow()); reference
clientsService.executeClientCommand, fillValidForm(), component.submit(), and
router.navigate to locate where to add these assertions.
- Around line 27-41: Replace the loose "as any" mocks with properly typed
partial mocks: declare router as Partial<Router> or jest.Mocked<Partial<Router>>
with navigate: jest.fn(); clientsService as Partial<ClientsService> or
jest.Mocked<Partial<ClientsService>> and type executeClientCommand as a jest
mock returning of({}); settingsService as Partial<SettingsService> with
language, dateFormat and businessDate typed; and dates as Partial<DatesService>
with formatDate mocked. Import the relevant interfaces/types (Router,
ClientsService, SettingsService, DatesService) and use Partial<T> or
jest.Mocked<Partial<T>> so TypeScript enforces correct shapes while keeping the
existing jest.fn() mocks (referencing the identifiers router,
clientsService.executeClientCommand, settingsService, and dates.formatDate).
- Around line 140-149: This test duplicates assertions already checked in the
earlier submit test; remove the redundant "should always include locale and
dateFormat" test (including calls to fillValidForm, component.submit, and the
clientsService.executeClientCommand payload assertions) or, alternatively,
collapse its assertions into the earlier submit test so only one test verifies
payload.locale and payload.dateFormat; if you choose to keep it, change it to a
minimal, focused unit test that only constructs the payload and asserts
locale/dateFormat without duplicating full form submission logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 73ed65a9-284f-403e-a81b-4aed0c7d265f

📥 Commits

Reviewing files that changed from the base of the PR and between eeba54b and ad35397.

📒 Files selected for processing (1)
  • src/app/clients/clients-view/client-actions/close-client/close-client.component.spec.ts

@Agaba-Ed Agaba-Ed force-pushed the unit-test-close-client branch from 4d37f5d to 7a4b8ea Compare March 22, 2026 09:20
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.

1 participant