Skip to content

Conversation

@akulakum
Copy link
Contributor

@akulakum akulakum commented Feb 4, 2026

COMPLETES #https://jira-eng-sjc12.cisco.com/jira/browse/CAI-7458

This pull request addresses

Adding comprehensive unit tests for the cc-digital-channels package to improve code coverage and test reliability.

by making the following changes

  • Added unit tests for useDigitalChannelsInit and useDigitalChannelsData hooks covering initialization, error handling, and edge cases.
  • Created dedicated DigitalChannelsComponent.test.tsx for presentational component tests (theme rendering, props validation).
  • Added ErrorBoundary integration test for DigitalChannels component
Screenshot 2026-02-05 at 3 44 04 PM

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

  • The testing is done with the amplify link
    < ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >

The GAI Coding Policy And Copyright Annotation Best Practices

  • GAI was not used (or, no additional notation is required)
  • Code was generated entirely by GAI
  • GAI was used to create a draft that was subsequently customized or modified
  • Coder created a draft manually that was non-substantively modified by GAI (e.g., refactoring was performed by GAI on manually written code)
  • Tool used for AI assistance (GitHub Copilot / Other - specify)
    • Github Copilot
    • Other - Please Specify
  • This PR is related to
    • Feature
    • Defect fix
    • Tech Debt
    • Automation

Checklist before merging

  • I have not skipped any automated checks
  • All existing and new tests passed
  • I have updated the testing document
  • I have tested the functionality with amplify link

Make sure to have followed the contributing guidelines before submitting.

@akulakum akulakum added the validated Indicates that the PR is ready for actions label Feb 4, 2026
@aws-amplify-us-east-2
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-611.d1b38q61t1z947.amplifyapp.com

Copy link
Contributor

@adhmenon adhmenon left a comment

Choose a reason for hiding this comment

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

LGTM. One question, only.

const storeModule = require('@webex/cc-store');
expect(storeModule.default.currentTask).toBeTruthy();
expect(storeModule.default.logger).toBeTruthy();
expect(storeModule.default.dataCenter).toBe('produs1');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know this is always going to be the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! 'produs1' is not a default value - it's a mock test value we configure in the test setup. I've refactored to use a MOCK_DATA_CENTER constant to make this clearer. The test verifies that the component correctly receives whatever dataCenter value is configured in the store.

Copy link
Contributor

@rsarika rsarika left a comment

Choose a reason for hiding this comment

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

Great work on adding comprehensive unit tests for the cc-digital-channels package! The tests are well-structured, follow proper MobX/React testing patterns, and cover important edge cases including error handling.

Highlights:

  • Good use of act() with runInAction() for MobX state updates
  • Proper mock strategy using jest.requireActual
  • Nice refactor to use named constants for mock values
  • Good coverage of error scenarios

Left a few minor suggestions as inline comments - these are non-blocking improvements for future consideration.

expect(screen.container.querySelector('div > md-theme')).toBeNull();
expect(screen.queryByTestId('engage-widget')).toBeNull();
expect(screen.container.innerHTML).toBe('');

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion (non-blocking): Consider extracting the store state restoration logic into a nested describe block with afterEach for cleaner test isolation:

describe('when dataCenter is empty', () => {
  let originalDataCenter: string;
  
  beforeEach(() => {
    originalDataCenter = store.dataCenter;
    act(() => { runInAction(() => { store.dataCenter = ''; }); });
  });
  
  afterEach(() => {
    act(() => { runInAction(() => { store.dataCenter = originalDataCenter; }); });
  });
  
  it('should not render', async () => { /* ... */ });
});

This pattern makes test cleanup more explicit and less error-prone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! Refactored to use nested describe blocks with beforeEach/afterEach for dataCenter and currentTask tests. This makes the test cleanup more explicit and isolated.


const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
mockShouldThrow = true;

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion (non-blocking): The consoleErrorSpy pattern is used multiple times. Consider extracting to a reusable helper or using beforeEach/afterEach:

let consoleErrorSpy: jest.SpyInstance;

beforeEach(() => {
  consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(() => {
  consoleErrorSpy.mockRestore();
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Moved consoleErrorSpy to beforeEach/afterEach in the ErrorBoundary describe block. Also reset mockShouldThrow in afterEach for cleaner test isolation.

const {result} = renderHook(() =>
useDigitalChannelsData({
getAccessToken,
currentTask: defaultTask,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion (non-blocking): Consider a more descriptive test name that captures the full scenario:

it('should handle token fetch error gracefully when logger is undefined')

This makes test failures easier to diagnose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the test name to 'should handle token fetch error gracefully when logger is undefined' for better clarity on what scenario is being tested.

storeWrapper['store'].cc.webex.credentials.getUserToken = jest
.fn()
.mockResolvedValue({access_token: mockAccessToken});

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion (non-blocking): There are several @ts-expect-error comments in these tests for the webex credentials API. For future maintainability, consider:

  1. Creating a typed mock interface for the credentials API, or
  2. Adding type definitions to the store's type declarations

This would improve IDE support and catch potential type mismatches early.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a larger refactoring effort for future consideration - no changes made as it's non-blocking.

@akulakum akulakum merged commit bfba443 into webex:next Feb 10, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

validated Indicates that the PR is ready for actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants