Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Added unit tests for the cc merchant info #3372

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

devendrafyle
Copy link
Contributor

@devendrafyle devendrafyle commented Dec 18, 2024

Clickup

https://app.clickup.com/t/86cxbrpvu

Summary by CodeRabbit

  • Tests
    • Added new test cases for the AddEditExpensePage and ViewExpensePage components to verify the functionality of opening a modal for credit card expense merchant information.
    • Enhanced test coverage for the CCExpenseMerchantInfoPopoverComponent with additional assertions and improved mocking practices.
    • Updated naming conventions and structure within the test suites for better clarity and organization.

Copy link

coderabbitai bot commented Dec 18, 2024

Walkthrough

Superstar, listen up! 💥 This pull request is all about leveling up our test game for expense-related components. We've added new test cases for AddEditExpensePage and ViewExpensePage that verify the functionality of opening a credit card expense merchant info modal. The CCExpenseMerchantInfoPopoverComponent is now more robustly tested, with improved naming and additional test scenarios. It's like adding extra punch to our code - style, mass, class! 🔥

Changes

File Change Summary
src/app/fyle/add-edit-expense/add-edit-expense-6.spec.ts Added new test case openCCExpenseMerchantInfoModal()
src/app/fyle/view-expense/view-expense.page.spec.ts Added new test case openCCExpenseMerchantInfoModal() and imported CCExpenseMerchantInfoPopoverComponent
src/app/shared/components/cc-expense-merchant-info-popover/cc-expense-merchant-info-popover.component.spec.ts Renamed component, added PopoverController spy, expanded test suite with new test cases

Sequence Diagram

sequenceDiagram
    participant User
    participant Page
    participant PopoverController
    participant MerchantInfoPopover

    User->>Page: Trigger Merchant Info
    Page->>PopoverController: Create Popover
    PopoverController-->>MerchantInfoPopover: Instantiate
    MerchantInfoPopover->>User: Display Merchant Details
Loading

Possibly related PRs

Suggested labels

size/S

Suggested reviewers

  • Chethan-Fyle
  • arjunaj5
  • Dimple16

Poem

Code flows like a river wild,
Testing modal with style so styled!
Rajini's punch in every line,
Merchant info now looks divine!
Superstar of tests, standing tall! 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the size/M Medium PR label Dec 18, 2024
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.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db1dcc2 and 3969091.

📒 Files selected for processing (3)
  • src/app/fyle/add-edit-expense/add-edit-expense-6.spec.ts (2 hunks)
  • src/app/fyle/view-expense/view-expense.page.spec.ts (2 hunks)
  • src/app/shared/components/cc-expense-merchant-info-popover/cc-expense-merchant-info-popover.component.spec.ts (1 hunks)

Comment on lines +36 to +43
it('should close the popover when clicked on close button', () => {
const closeBtn = getElementBySelector(fixture, '[data-testid="close-btn"') as HTMLButtonElement;
closeBtn.click();

fixture.detectChanges();

expect(popoverController.dismiss).toHaveBeenCalled();
});
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Superstar says: Add more test cases for close button interactions!

The close button test is good, but we need more test cases for:

  • Close button keyboard interactions (Enter/Space key)
  • Close button accessibility attributes
  • Error handling when dismiss fails

Comment on lines +45 to +57
describe('template', () => {
it('should display the correct title', () => {
fixture.detectChanges();
const title = getElementBySelector(fixture, '[data-testid="title"');
expect(title.textContent).toEqual('Merchant');
});

it('should display the correct content', () => {
fixture.detectChanges();
const content = getElementBySelector(fixture, '[data-testid="content"');
expect(content.textContent).toEqual('This merchant name comes from the transaction.');
});
});
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Mind it! Template tests need more power!

The template tests verify basic content, but we should also test:

  • Content formatting/styling
  • Localization if applicable
  • Dynamic content updates

Comment on lines +7 to 11
describe('CCExpenseMerchantInfoComponent', () => {
let component: CCExpenseMerchantInfoPopoverComponent;
let popoverController: jasmine.SpyObj<PopoverController>;
let fixture: ComponentFixture<CCExpenseMerchantInfoPopoverComponent>;

Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Mind it! The test suite name doesn't match the component name.

The test suite is named 'CCExpenseMerchantInfoComponent' but the component being tested is 'CCExpenseMerchantInfoPopoverComponent'. Consistency is the style of the superstar!

-describe('CCExpenseMerchantInfoComponent', () => {
+describe('CCExpenseMerchantInfoPopoverComponent', () => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe('CCExpenseMerchantInfoComponent', () => {
let component: CCExpenseMerchantInfoPopoverComponent;
let popoverController: jasmine.SpyObj<PopoverController>;
let fixture: ComponentFixture<CCExpenseMerchantInfoPopoverComponent>;
describe('CCExpenseMerchantInfoPopoverComponent', () => {
let component: CCExpenseMerchantInfoPopoverComponent;
let popoverController: jasmine.SpyObj<PopoverController>;
let fixture: ComponentFixture<CCExpenseMerchantInfoPopoverComponent>;

Comment on lines +1081 to +1094
it('openCCExpenseMerchantInfoModal(): should open the transaction status info modal', fakeAsync(() => {
const popoverSpy = jasmine.createSpyObj('HTMLIonPopoverElement', ['present']);
popoverController.create.and.resolveTo(popoverSpy);

component.openCCExpenseMerchantInfoModal();

tick();

expect(popoverController.create).toHaveBeenCalledOnceWith({
component: CCExpenseMerchantInfoPopoverComponent,
cssClass: 'fy-dialog-popover',
});
expect(popoverSpy.present).toHaveBeenCalledTimes(1);
}));
Copy link

@coderabbitai coderabbitai bot Dec 18, 2024

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Style! The new test case looks good but needs more power!

The test verifies basic modal creation, but we should add test cases for:

  • Error handling when modal creation fails
  • Modal dismissal
  • Data passing to the modal

Example test cases to add:

it('should handle modal creation failure', fakeAsync(() => {
  const error = new Error('Modal creation failed');
  popoverController.create.and.rejectWith(error);
  
  component.openCCExpenseMerchantInfoModal();
  tick();
  
  expect(console.error).toHaveBeenCalledWith('Failed to open merchant info modal:', error);
}));

it('should handle modal dismissal', fakeAsync(() => {
  const popoverSpy = jasmine.createSpyObj('HTMLIonPopoverElement', ['present', 'onDidDismiss']);
  popoverController.create.and.resolveTo(popoverSpy);
  popoverSpy.onDidDismiss.and.resolveTo({ data: { dismissed: true } });
  
  component.openCCExpenseMerchantInfoModal();
  tick();
  
  expect(popoverSpy.onDidDismiss).toHaveBeenCalled();
}));

Copy link
Contributor

Choose a reason for hiding this comment

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

@devendrafyle, should we add a test case for modal dismiss alone?

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Dimple16 modal dismiss is not used here, it's the CCExpenseMerchantInfoPopoverComponent property and we have added the test case for it there.

Comment on lines +1228 to +1241
it('openCCExpenseMerchantInfoModal(): should open the transaction status info modal', fakeAsync(() => {
const popoverSpy = jasmine.createSpyObj('HTMLIonPopoverElement', ['present']);
popoverController.create.and.resolveTo(popoverSpy);

component.openCCExpenseMerchantInfoModal();

tick();

expect(popoverController.create).toHaveBeenCalledOnceWith({
component: CCExpenseMerchantInfoPopoverComponent,
cssClass: 'fy-dialog-popover',
});
expect(popoverSpy.present).toHaveBeenCalledTimes(1);
}));
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Mind it! This test case needs the same power as its brother!

Similar to ViewExpensePage, this test should include additional scenarios:

  • Error handling
  • Modal dismissal
  • Data passing

Example test cases to add:

it('should handle modal creation failure gracefully', fakeAsync(() => {
  const error = new Error('Modal creation failed');
  popoverController.create.and.rejectWith(error);
  
  component.openCCExpenseMerchantInfoModal();
  tick();
  
  expect(console.error).toHaveBeenCalledWith('Failed to open merchant info modal:', error);
}));

it('should handle modal dismissal properly', fakeAsync(() => {
  const popoverSpy = jasmine.createSpyObj('HTMLIonPopoverElement', ['present', 'onDidDismiss']);
  popoverController.create.and.resolveTo(popoverSpy);
  popoverSpy.onDidDismiss.and.resolveTo({ data: { dismissed: true } });
  
  component.openCCExpenseMerchantInfoModal();
  tick();
  
  expect(popoverSpy.onDidDismiss).toHaveBeenCalled();
}));

Copy link

Unit Test Coverage % values
Statements 96% ( 19252 / 20054 )
Branches 91.11% ( 10654 / 11693 )
Functions 94.33% ( 5746 / 6091 )
Lines 96.03% ( 18382 / 19140 )

Copy link
Contributor

@Dimple16 Dimple16 left a comment

Choose a reason for hiding this comment

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

minor comment

Comment on lines +1081 to +1094
it('openCCExpenseMerchantInfoModal(): should open the transaction status info modal', fakeAsync(() => {
const popoverSpy = jasmine.createSpyObj('HTMLIonPopoverElement', ['present']);
popoverController.create.and.resolveTo(popoverSpy);

component.openCCExpenseMerchantInfoModal();

tick();

expect(popoverController.create).toHaveBeenCalledOnceWith({
component: CCExpenseMerchantInfoPopoverComponent,
cssClass: 'fy-dialog-popover',
});
expect(popoverSpy.present).toHaveBeenCalledTimes(1);
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

@devendrafyle, should we add a test case for modal dismiss alone?

@devendrafyle devendrafyle merged commit 54d686d into FYLE-86cxbrpvr Dec 19, 2024
6 checks passed
devendrafyle added a commit that referenced this pull request Dec 19, 2024
…r CC expenses (#3369)

* feat: Added the merchant name in expense detials card for CC expenses

* added the merchant feature in view expense page

* minor updates

* test: Added unit tests for the cc merchant info (#3372)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants