Skip to content

Conversation

@lposen
Copy link
Contributor

@lposen lposen commented Oct 17, 2025

🔹 JIRA Ticket(s) if any

✏️ Description

Created tests for IterableInboxMessageDisplay

@lposen lposen requested a review from Copilot October 17, 2025 19:28
@lposen lposen added the tests This issue or PR concerns test coverage. If PR, it should only contain tests. label Oct 17, 2025
@qltysh
Copy link

qltysh bot commented Oct 17, 2025

Diff Coverage: The code coverage on the diff in this pull request is 100.0%.

Total Coverage: This PR will increase coverage by 10.34%.

File Coverage Changes
Path File Coverage Δ Indirect
src/inbox/components/IterableInboxMessageDisplay.tsx 97.2
src/inbox/components/IterableInboxMessageList.tsx 87.5
🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

This is from Qlty Cloud, the successor to Code Climate Quality. Learn more.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds comprehensive test suites for IterableInboxMessageDisplay and (existing) IterableInboxMessageList, plus minor formatting/documentation changes in Iterable core class and updates eslint ignore patterns.

  • Introduces extensive rendering, interaction, and edge-case tests for IterableInboxMessageDisplay.
  • Adds broad (but shallow) rendering and prop variation tests for IterableInboxMessageList.
  • Adjusts require style in Iterable.ts and removes an Android-specific doc tag; adds coverage/ to .eslintignore.

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 11 comments.

File Description
src/inbox/components/IterableInboxMessageList.test.tsx New test suite covering rendering and prop variations for message list.
src/inbox/components/IterableInboxMessageDisplay.test.tsx New detailed test suite for display component interactions, async content, and handlers.
src/core/classes/Iterable.ts Reformats lazy require block and removes Android-only doc tag from wakeApp JSDoc.
.eslintignore Adds coverage/ directory to ignore list.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 277 to 283
it('should handle updateVisibleMessageImpressions with different implementations', () => {
const customUpdateCallback = jest.fn((rowInfos: IterableInboxImpressionRowInfo[]) => {
// Custom implementation
rowInfos.forEach(rowInfo => {
console.log(`Message ${rowInfo.messageId} is visible`);
});
});
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Using console.log in tests adds noise and slows execution. Remove the logging or replace with assertions on rowInfos after invoking the viewability handler to keep tests focused and deterministic.

Copilot uses AI. Check for mistakes.
Comment on lines 447 to 470
it('should handle very large number of row view models', () => {
const largeRowViewModels = Array.from({ length: 1000 }, (_, i) => ({
inAppMessage: new IterableInAppMessage(
`messageId${i}`,
i,
new IterableInAppTrigger(IterableInAppTriggerType.immediate),
new Date(),
undefined,
true,
new IterableInboxMetadata(`Title ${i}`, `Subtitle ${i}`, `imageUrl${i}.png`),
undefined,
false,
i
),
title: `Title ${i}`,
subtitle: `Subtitle ${i}`,
imageUrl: `imageUrl${i}.png`,
read: false,
createdAt: new Date(),
}));

const propsWithLargeData = { ...defaultProps, rowViewModels: largeRowViewModels };
expect(() => render(<IterableInboxMessageList {...propsWithLargeData} />)).not.toThrow();
});
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Generating 1000 complex objects increases test time; reduce to a representative subset (e.g., 50–100) or mock rowViewModels minimally to validate scalability while keeping suite fast.

Copilot uses AI. Check for mistakes.
Comment on lines 366 to 368
deleteRow: undefined as unknown as (messageId: string) => void,
handleMessageSelect: undefined as unknown as (messageId: string, index: number) => void,
messageListItemLayout: undefined as unknown as (last: boolean, rowViewModel: IterableInboxRowViewModel) => [React.ReactElement | null, number],
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Casting undefined to function types with unknown as masks type safety; if these props are optional, pass undefined directly, otherwise provide no-op jest.fn() to clearly express intent.

Suggested change
deleteRow: undefined as unknown as (messageId: string) => void,
handleMessageSelect: undefined as unknown as (messageId: string, index: number) => void,
messageListItemLayout: undefined as unknown as (last: boolean, rowViewModel: IterableInboxRowViewModel) => [React.ReactElement | null, number],
deleteRow: undefined,
handleMessageSelect: undefined,
messageListItemLayout: undefined,

Copilot uses AI. Check for mistakes.
Comment on lines +309 to +313
expect(Iterable.trackInAppClose).toHaveBeenCalledWith(
mockRowViewModel.inAppMessage,
1, // IterableInAppLocation.inbox
0 // IterableInAppCloseSource.back
);
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Hard-coded enum numeric values reduce clarity and may break if enum ordering changes; import and use the actual enum constants (e.g., IterableInAppLocation.inbox, IterableInAppCloseSource.back) in the expectation.

Copilot uses AI. Check for mistakes.
Comment on lines +644 to +648
expect(Iterable.trackInAppClick).toHaveBeenCalledWith(
mockRowViewModel.inAppMessage,
1, // IterableInAppLocation.inbox
'https://example.com'
);
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Replace the magic number 1 with the corresponding enum constant for location to improve readability and resilience to enum changes.

Copilot uses AI. Check for mistakes.
Comment on lines +662 to +667
expect(Iterable.trackInAppClose).toHaveBeenCalledWith(
mockRowViewModel.inAppMessage,
1, // IterableInAppLocation.inbox
1, // IterableInAppCloseSource.link
'https://example.com'
);
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Use enum constants instead of raw numeric values (1) for location and close source to avoid magic numbers in assertions.

Copilot uses AI. Check for mistakes.
Comment on lines +525 to +536
type: 'customAction',
data: 'action://customAction',
userInput: '',
}),
expect.objectContaining({
action: expect.objectContaining({
type: 'customAction',
data: 'action://customAction',
userInput: '',
}),
source: 2, // IterableActionSource.inApp
})
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

The magic number 2 for action source should be replaced with the enum (IterableActionSource.inApp) to make the test self-explanatory and resilient.

Copilot uses AI. Check for mistakes.
Comment on lines +567 to +575
'myapp://deep-link',
expect.objectContaining({
action: expect.objectContaining({
type: 'openUrl',
data: 'myapp://deep-link',
userInput: '',
}),
source: 2, // IterableActionSource.inApp
})
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Replace numeric source value 2 with the corresponding enum constant for clarity and to avoid brittle coupling to enum ordering.

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +17
const originalError = console.error;
beforeAll(() => {
console.error = jest.fn();
});

afterAll(() => {
console.error = originalError;
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Overriding console.error globally can hide unexpected errors; prefer jest.spyOn(console, 'error') and selectively filtering known warnings or restoring after each test to avoid masking failures.

Suggested change
const originalError = console.error;
beforeAll(() => {
console.error = jest.fn();
});
afterAll(() => {
console.error = originalError;
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation((...args) => {
// Suppress only act() warnings, log others
const actWarning = /Warning: An update to .* inside a test was not wrapped in act/;
if (typeof args[0] === 'string' && actWarning.test(args[0])) {
return;
}
// Call the original error for other messages
// @ts-ignore
return console.error.mock.calls.length ? undefined : console.error(...args);
});
});
afterEach(() => {
// @ts-ignore
if (console.error.mockRestore) {
console.error.mockRestore();
}

Copilot uses AI. Check for mistakes.
Comment on lines +721 to +722
returnToInbox: undefined as unknown as (callback?: () => void) => void,
deleteRow: undefined as unknown as (id: string) => void,
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Casting undefined to function types reduces type safety; if these props are optional pass undefined directly, or use no-op jest.fn() to communicate intent without unsafe casts.

Suggested change
returnToInbox: undefined as unknown as (callback?: () => void) => void,
deleteRow: undefined as unknown as (id: string) => void,
returnToInbox: undefined,
deleteRow: undefined,

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Oct 17, 2025

Lines Statements Branches Functions
Coverage: 77%
77.96% (375/481) 55.02% (104/189) 72.43% (113/156)

lposen and others added 2 commits October 17, 2025 13:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@lposen lposen closed this Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests This issue or PR concerns test coverage. If PR, it should only contain tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants