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: unit test the intacct export log pages #989

Merged
merged 12 commits into from
Oct 3, 2024

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Sep 30, 2024

image

Clickup

https://app.clickup.com/t/86cwh86cx
https://app.clickup.com/t/86cwh86cu

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced flexibility in method calls with optional parameters for date filters and search queries.
    • Improved handling of pagination and date filters in the export log components.
  • Bug Fixes

    • Adjusted pagination logic to ensure accurate page calculations based on the current limit.
  • Tests

    • Expanded test coverage for IntacctCompletedExportLogComponent and IntacctSkipExportLogComponent, including various functionalities like initialization, pagination, and search handling.
  • Chores

    • Updated mock data structures to improve testing for expense groups and export logs.

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Walkthrough

The pull request introduces modifications to the ExportLogService and several components within the Intacct integration. Key changes include updating method signatures to accept optional parameters, enhancing unit tests for various components, and refining the handling of properties like selectedDateFilter and searchQuery. The updates aim to improve flexibility in method calls and strengthen test coverage across components related to expense logs and pagination.

Changes

File Change Summary
src/app/core/services/common/export-log.service.ts Updated method signatures for getSkippedExpenses and getExpenseGroups to accept optional parameters.
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-completed-export-log/intacct-completed-export-log.component.spec.ts Enhanced unit tests for IntacctCompletedExportLogComponent, adding tests for various functionalities and service interactions.
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-completed-export-log/intacct-completed-export-log.component.ts Modified handling of selectedDateFilter and adjusted pagination logic in pageSizeChanges.
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-export-log.component.spec.ts Updated test suite to include router dependency and added navigation test for IntacctExportLogComponent.
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-skip-export-log/intacct-skip-export-log.component.spec.ts Enhanced unit tests for IntacctSkipExportLogComponent, covering initialization and interactions with services.
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-skip-export-log/intacct-skip-export-log.component.ts Updated properties to be optional and refined pagination handling and form setup logic.
src/app/integrations/intacct/intacct.fixture.ts Added new mock data structures for expense groups and skipped export logs, enhancing data modeling capabilities.

Possibly related PRs

  • test: add unit tests for IntacctComponent #969: The changes in the IntacctComponent involve handling the selectedDateFilter, which is also a focus in the main PR's modifications to the ExportLogService methods that utilize date filters.
  • test: unit test the intacct mapping page #983: The unit tests for the IntacctMappingComponent include scenarios that may involve the handling of expense groups and filters, which aligns with the changes made in the ExportLogService methods in the main PR.

Suggested labels

size/L, deploy

Suggested reviewers

  • DhaaraniCIT
  • ashwin1111

🐰 In the fields where the bunnies play,
New changes hop in, brightening the day!
With filters now optional, oh what a treat,
Testing and logging, all feel so neat!
Let's celebrate this code, so fine and spry,
Hooray for updates, let our spirits fly! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

Copy link
Contributor

@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: 8

🧹 Outside diff range and nitpick comments (7)
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-export-log.component.spec.ts (2)

33-36: Good addition: Test for initial navigation.

The new test case effectively verifies the initial navigation behavior of the component. It checks both the active module setting and the correct URL navigation.

Consider adding a descriptive comment above the test case to explain what specific behavior it's testing. For example:

// Verifies that the component navigates to the completed export log page on initialization
it('should navigate to completed export log', () => {
  // ... existing test code ...
});

This will improve the readability and maintainability of the test suite.


Line range hint 1-36: Consider expanding test coverage.

The current test suite covers component creation and initial navigation, which is a good start. To improve the overall test coverage and robustness of the component, consider adding the following test cases:

  1. Test different navigation scenarios based on different active modules.
  2. Verify the behavior of the component when export data changes.
  3. Test any public methods or properties of the component that are not currently covered.
  4. Add edge case tests, such as handling empty module lists or unexpected data.

These additional tests will help ensure the component behaves correctly under various conditions and increase confidence in its functionality.

src/app/core/services/common/export-log.service.ts (1)

Line range hint 26-55: LGTM! Consider a minor improvement for consistency.

The changes to make selectedDateFilter and query optional parameters improve the method's flexibility without breaking existing functionality. The internal logic handles these optional parameters correctly.

For consistency, consider using the workspaceId class property instead of calling this.workspaceService.getWorkspaceId() again. Apply this small change:

-const workspaceId = this.workspaceService.getWorkspaceId();
+const workspaceId = this.workspaceId;

This change aligns with how workspaceId is used in the rest of the method and the getExpenseGroups method.

src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-skip-export-log/intacct-skip-export-log.component.ts (2)

Line range hint 141-160: LGTM: Improved date range handling with a minor suggestion

The changes to setupForm method significantly improve date range handling and calendar visibility management. The logic for updating the selectedDateFilter and triggering the expense fetch is now more robust.

However, the use of setTimeout to toggle calendar visibility might cause a slight UI flicker. Consider using Angular's ChangeDetectorRef to trigger a manual change detection cycle instead, which could provide a smoother user experience.

Here's a suggested refactor to avoid using setTimeout:

import { ChangeDetectorRef } from '@angular/core';

constructor(
  // ... other dependencies
  private cdr: ChangeDetectorRef
) { }

// In setupForm method
this.hideCalendar = true;
this.selectedDateFilter = {
  startDate: dateRange[0],
  endDate: dateRange[1]
};

this.isDateSelected = true;
this.cdr.detectChanges();
this.hideCalendar = false;

this.getSkippedExpenses(paginator.limit, paginator.offset);

Line range hint 163-171: LGTM: Improved initialization logic

The new getSkippedExpensesAndSetupPage method effectively encapsulates the component's initialization logic, improving code organization and readability. It correctly sets up the form, initializes pagination, and fetches initial data.

To complete this refactoring, ensure that ngOnInit is updated to use this new method:

ngOnInit(): void {
  this.getSkippedExpensesAndSetupPage();
}
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-completed-export-log/intacct-completed-export-log.component.spec.ts (2)

58-66: Consider adding an assertion to verify 'getExpenseGroups' is called during initialization.

While the test verifies the component properties after initialization, adding an expectation to ensure exportLogService.getExpenseGroups is called will confirm that data loading is triggered as expected.

You can add:

expect(exportLogService.getExpenseGroups).toHaveBeenCalled();

128-135: Ensure consistent use of 'undefined' and 'null' in method parameters.

In the call to getExpenseGroups, consider using undefined consistently for optional parameters unless null has a specific meaning. This can help avoid potential confusion and bugs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9aa2b08 and 84edd5b.

📒 Files selected for processing (7)
  • src/app/core/services/common/export-log.service.ts (2 hunks)
  • src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-completed-export-log/intacct-completed-export-log.component.spec.ts (1 hunks)
  • src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-completed-export-log/intacct-completed-export-log.component.ts (2 hunks)
  • src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-export-log.component.spec.ts (2 hunks)
  • src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-skip-export-log/intacct-skip-export-log.component.spec.ts (1 hunks)
  • src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-skip-export-log/intacct-skip-export-log.component.ts (3 hunks)
  • src/app/integrations/intacct/intacct.fixture.ts (2 hunks)
🧰 Additional context used
🪛 Biome
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-skip-export-log/intacct-skip-export-log.component.spec.ts

[error] 46-52: Disallow duplicate setup and teardown hooks.

Disallow beforeEach duplicacy inside the describe function.

(lint/suspicious/noDuplicateTestHooks)

🔇 Additional comments (32)
src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-export-log.component.spec.ts (3)

6-6: LGTM: Router import added correctly.

The import statement for provideRouter and Router from '@angular/router' is correctly added. This is necessary for the new router-related functionality in the tests.


8-8: Great: Test suite activated.

Changing from xdescribe to describe activates the test suite for IntacctExportLogComponent. This is an important change as it ensures that these tests will now be executed as part of the test run.


11-11: Well done: Router setup for testing.

The changes made to set up the router for testing are correct and follow good practices:

  1. Declaring the router variable for use in tests.
  2. Adding provideRouter([]) to the providers array in the TestBed configuration.
  3. Injecting the router and setting up a spy on navigateByUrl.

These changes enable proper testing of navigation-related functionality in the component.

Also applies to: 17-17, 21-23

src/app/core/services/common/export-log.service.ts (2)

Line range hint 57-89: LGTM! The changes improve method flexibility.

The modification to make selectedDateFilter an optional parameter enhances the method's flexibility without altering its core functionality. The internal logic correctly handles this optional parameter, and the overall structure of the method remains sound.


Line range hint 1-89: Overall, the changes enhance method flexibility and align with PR objectives.

The modifications to getSkippedExpenses and getExpenseGroups methods improve their flexibility by making certain parameters optional. This change aligns well with the PR objectives of implementing unit tests for the Intacct export log pages, as it allows for more versatile method calls during testing.

The internal logic of both methods remains intact, ensuring that existing functionality is preserved while accommodating the new optional parameters. These changes should facilitate easier and more comprehensive unit testing of the Intacct export log pages.

src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-skip-export-log/intacct-skip-export-log.component.ts (4)

43-43: LGTM: Improved property flexibility

Making selectedDateFilter optional enhances the component's flexibility, allowing for better handling of cases where the date filter might not be set initially or cleared during runtime.


63-63: LGTM: Enhanced property flexibility

Making searchQuery optional improves the component's ability to handle scenarios where a search query might not be present, aligning with best practices for optional properties in TypeScript.


Line range hint 1-185: Overall assessment: Well-structured improvements with minor suggestions

The changes in this file significantly improve the IntacctSkipExportLogComponent. Key improvements include:

  1. Enhanced flexibility with optional properties.
  2. Improved date range handling and calendar visibility management.
  3. Better organization of initialization logic.

The code changes align well with the PR objectives of implementing unit tests for the Intacct export log pages. While the actual test implementations are not visible in this file, these changes lay a solid foundation for testable component behavior.

Consider implementing the suggested minor improvements for an even more robust and maintainable component.


95-95: Verify impact of delayed limit assignment

Moving the limit assignment to the end of the method ensures it's updated after the API call. This change looks good, but please verify that any code depending on the updated limit value isn't affected by this delayed assignment.

src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-completed-export-log/intacct-completed-export-log.component.ts (2)

45-45: LGTM: Improved property signature for selectedDateFilter

The change to make selectedDateFilter optional (?) is a good improvement. It better reflects the property's usage in the component, allowing for cases where it might be undefined. This change enhances type safety without introducing breaking changes.


Line range hint 1-191: Verify alignment with PR objectives

The PR objectives mention implementing unit tests for the Intacct export log pages. However, this file doesn't contain any test-related changes. It only includes minor improvements to the component itself.

Could you please clarify if there are separate test files that implement the unit tests mentioned in the PR objectives? If so, please include them in the review. If not, consider updating the PR description to accurately reflect the changes made.

src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-completed-export-log/intacct-completed-export-log.component.spec.ts (8)

1-47: Setup and dependency injection are correctly implemented.

The test setup and dependency injection for the services are properly configured using spies.


53-55: Component creation test is valid.

The basic creation test ensures that the component instance is created successfully.


68-75: Page size change handling is correctly tested.

The test correctly verifies that changing the page size updates the limit, resets the current page, stores the new page size, and fetches the expense groups.


77-83: Page change handling is correctly tested.

The test verifies that changing the page updates the offset and current page, and triggers data fetching.


85-94: Simple search functionality is correctly tested.

The test ensures that searching updates the search query, resets the offset and current page, and fetches the expense groups after the debounce period.


96-101: Opening expense in Fyle is correctly tested.

The test ensures that window.open is called with the correct expense ID and target.


103-115: Date filter change handling is correctly tested.

The test verifies that setting a date range updates the selectedDateFilter, sets isDateSelected to true, fetches the expense groups, and displays the calendar as expected.


117-124: Clearing date filter is correctly tested.

The test ensures that setting the date filter to null clears the selectedDateFilter, sets isDateSelected to false, and fetches the expense groups.

src/app/integrations/intacct/intacct-main/intacct-export-log/intacct-skip-export-log/intacct-skip-export-log.component.spec.ts (10)

1-12: LGTM on imports and initial setup.

The imports and initial test setup correctly include all necessary modules, services, and mocks required for the unit tests.


58-66: Well-written initialization test.

The test for component initialization effectively verifies that the component's properties are set correctly based on the mocked service responses, ensuring the component loads data as expected.


68-76: Effective test for page size changes.

The test correctly checks that updating the page size adjusts the component's limit and currentPage properties, stores the new page size, and triggers a data reload.


77-85: Proper handling of page navigation in tests.

The test ensures that changing pages updates the offset and currentPage, and that the component fetches the new data accordingly.


86-96: Comprehensive test for simple search functionality.

The use of fakeAsync and tick accurately simulates asynchronous behavior, ensuring the search functionality updates the component state and triggers the expected service call.


97-109: Accurate testing of date filter changes.

The test verifies that setting a date range updates the selectedDateFilter and isDateSelected properties, and that the component correctly reloads the filtered data.


110-118: Effective test for clearing date filters.

The test confirms that clearing the date filter resets the relevant properties and fetches the data without any date constraints.


119-128: Verification of service method calls with correct parameters.

The test ensures that getSkippedExpenses is called with the correct arguments, validating the integration with the export log service.


129-134: Proper tracking of date filter usage.

The test confirms that the trackDateFilter method of the tracking service is called with the appropriate parameters, ensuring analytics are correctly recorded.


135-143: Correct handling of asynchronous UI updates.

Using fakeAsync and tick accurately tests that hideCalendar is updated after a timeout, ensuring the UI behaves as expected when interacting with the date picker.

src/app/integrations/intacct/intacct.fixture.ts (3)

8-10: New imports are appropriate and necessary

The added imports for ExpenseGroup, ExpenseGroupDescription, ExpenseGroupResponse, Paginator, and SkipExportLogResponse are correctly included to support the newly added mock data structures.


469-472: mockPaginator is correctly defined

The mockPaginator object is properly set with limit and offset values, which will be useful for testing pagination functionality.


374-374: Confirm the use of negative amounts in amount field

The amount field in the expenses has negative values (-460.0, -550.0). Verify whether negative amounts are appropriate in this context, as they might represent refunds or credits.

To ensure consistency, run the following script to check how amount values are used across expense groups:

Also applies to: 402-402


fixture = TestBed.createComponent(IntacctCompletedExportLogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this line removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just because all tests dont require a full re-render, for example should handle page size changes. The tests that require a component render calls fixture.detectChanges() within the test case. For example: should handle page changes

@@ -42,7 +42,7 @@ export class IntacctCompletedExportLogComponent implements OnInit {

dateOptions: DateFilter[] = AccountingExportModel.getDateOptionsV2();

selectedDateFilter: SelectedDateFilter | null;
selectedDateFilter?: SelectedDateFilter | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we add '?' here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the default value saved of selectedDate is undefined, this test case was not passing the ts type check. In it, we are testing the case where we call the exportLogService.getExpenseGroups with this.selectedDateFilter set to undefined (this line):

this.exportLogService.getExpenseGroups(TaskLogState.COMPLETE, limit, offset, this.selectedDateFilter, null, this.searchQuery)

@@ -40,7 +40,7 @@ export class IntacctSkipExportLogComponent implements OnInit {

dateOptions: DateFilter[] = AccountingExportModel.getDateOptionsV2();

selectedDateFilter: SelectedDateFilter | null;
selectedDateFilter?: SelectedDateFilter | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same reason

@@ -60,7 +60,7 @@ export class IntacctSkipExportLogComponent implements OnInit {

readonly brandingConfig = brandingConfig;

searchQuery: string | null;
searchQuery?: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same reason

this.currentPage = 1;
this.selectedDateFilter = this.selectedDateFilter ? this.selectedDateFilter : null;
this.getSkippedExpenses(limit, this.offset);
this.limit = limit;
Copy link
Contributor

Choose a reason for hiding this comment

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

why we change the position of the limit, any reason

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, since calling this.getSkippedExpenses with limit and this.limit set to the same value prevents it from updating the localstorage with the new value because of this check. Essentially that leaves the localstorage functionality unused in this page. Calling this.getSkippedExpenses before updating this.limit updates the localStorage value as intended.

I've also raised a separate PR (#990) for this

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername merged commit 79bede5 into master Oct 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Large PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants