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

feat: implement policy summary for app policy #14888

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nkylstad
Copy link
Member

@nkylstad nkylstad commented Mar 5, 2025

Description

Implement new PolicySummary component to show a summary of the policy for apps:

  • Implemented StudioTabs component in policy editor for apps, where 1 tab shows the summary and the other tab shows the rules editor.
  • Refactored and moved some code into new components
  • Increased the max width for the settings modal

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • Style

    • Expanded the settings modal width for a broader, more flexible display.
  • New Features

    • Revamped the policy editor with a tabbed interface that clearly separates policy summaries from rule editing, streamlining navigation and management.
    • Introduced a new component for editing policy rules, enhancing the user experience.
  • Bug Fixes

    • Corrected textual errors in policy details for improved clarity.
  • Tests

    • Enhanced test coverage for the PolicyEditor and PolicyRulesEditor components, ensuring accurate rendering and functionality.

Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

📝 Walkthrough

Walkthrough

This pull request updates several aspects of the policy editor and related UI elements. It increases the maximum width for the settings modal, corrects a typographical error in localization text, and refactors the policy editor by removing deprecated components and tests while introducing new components for a tabbed interface. Additionally, it adjusts key generation in a summary component and modifies the behavior of a utility function, with corresponding changes to its tests.

Changes

File(s) Change Summary
frontend/app-development/.../SettingsModal.module.css, frontend/packages/policy-editor/.../PolicyEditor.module.css, frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.module.css Updated CSS: changed the modal width variable (--settings-modal-width), removed an unused .addCardButtonWrapper class, and added a new .addCardButtonWrapper for PolicyRulesEditor styling.
frontend/language/src/nb.json Corrected a typographical error in the policy editor summary text by splitting “oghvilke” into “og hvilke”.
frontend/packages/policy-editor/.../PolicyEditor.tsx, frontend/packages/policy-editor/.../PolicyEditor.test.tsx Refactored PolicyEditor: removed AddPolicyRuleButton and PolicyCardRules, added PolicyRulesEditor and PolicyEditorTabs, updated tests for different usage types, and removed a redundant add rule test.
frontend/packages/policy-editor/src/components/PolicyEditorTabs/... Introduced a new PolicyEditorTabs component using a tabbed interface for summary and rules views, along with tests verifying default selection and tab switching.
frontend/packages/policy-editor/src/components/PolicyRulesEditor/... Added a new PolicyRulesEditor component for managing policy rules and accompanying tests that validate rule count and the add rule functionality.
frontend/packages/policy-editor/src/components/PolicySummary/PolicyRuleSummary/PolicyRuleSubjectSummary.tsx Modified the StudioTag key generation by incorporating the subject variable to improve key uniqueness.
frontend/packages/policy-editor/src/utils/AppPolicyUtils/... Revised the filterDefaultAppLimitations function to return the input array when no default limitations are found, with corresponding test expectations updated.

Possibly related PRs

Suggested labels

area/ui-editor, skip-manual-testing, team/studio-domain1

Suggested reviewers

  • Jondyr
  • mlqn

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between efa06eb and b35c5c0.

📒 Files selected for processing (1)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/PolicyTab/PolicyTab.test.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
  • GitHub Check: CodeQL
🔇 Additional comments (1)
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/PolicyTab/PolicyTab.test.tsx (1)

119-121: Test updated to accommodate new tabbed interface

The test has been properly updated to work with the new tabbed interface. These additions ensure the test scenario correctly navigates to the rules tab before attempting to interact with the add button, which matches the real user flow in the refactored UI.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

@nkylstad nkylstad changed the title implement policy summary for app policy feat: implement policy summary for app policy Mar 5, 2025
@github-actions github-actions bot added solution/studio/designer Issues related to the Altinn Studio Designer solution. area/authorization Area: Issues related to roles and rights on apps, such as who can instantiate, sign etc. frontend labels Mar 5, 2025
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: 0

🔭 Outside diff range comments (1)
frontend/packages/policy-editor/src/PolicyEditor.tsx (1)

59-59: 💡 Verification agent

🧩 Analysis chain

Address TODO comment regarding rule ID generation.

There's an unresolved TODO comment about whether the rule ID should be hardcoded. This should be addressed to ensure proper implementation.


🏁 Script executed:

#!/bin/bash
# Search for related issues to understand context of the TODO
gh issue view 10893 || echo "Issue #10893 not found or not accessible"

# Check if there are any recent updates or discussions on this issue
gh issue list --search "10893 in:comments" --limit 5

Length of output: 773


Update Rule ID Generation Based on Closed Issue #10893

The current implementation still hardcodes part of the rule ID:

`${resourceType}:${usageType === 'app' ? 'example' : resourceId}:ruleid:${pr.ruleId}` // TODO - find out if ID should be hardcoded. Issue: #10893

Since Issue #10893 ("Find out what the ruleId for a rule in a policy should look like") is now closed, please update the implementation to follow the finalized decision. If the current behavior is confirmed as correct, remove the TODO comment; otherwise, revise the rule ID generation logic accordingly.

  • File: frontend/packages/policy-editor/src/PolicyEditor.tsx (line 59)
🧹 Nitpick comments (4)
frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.test.tsx (1)

1-49: Well-structured tests for PolicyRulesEditor component

The test file provides good coverage for the basic functionality of the PolicyRulesEditor component, including:

  • Verifying correct display of policy rules
  • Testing the add rule button functionality

Suggestions for improvement:

  1. Consider adding tests for error handling scenarios (since there's a state variable for error display mentioned in the summary)
  2. Add a test case for empty policy rules state
  3. Test any filtering or sorting capabilities if present in the component
// Add additional test cases for more comprehensive coverage:

+ it('displays error state correctly when an error occurs', () => {
+   // Mock implementation with error state
+   mockPolicyEditorContextValue.hasErrors = true;
+   renderPolicyRulesEditor();
+   
+   // Assert error state display
+   expect(screen.getByText(/error/i)).toBeInTheDocument();
+ });
+
+ it('handles empty policy rules gracefully', () => {
+   // Setup empty rules
+   const emptyPolicy = {...mockPolicy, rules: []};
+   mockPolicyEditorContextValue.policy = emptyPolicy;
+   renderPolicyRulesEditor();
+   
+   // Assert empty state message is shown
+   expect(screen.getByText(/no policy rules/i)).toBeInTheDocument();
+ });
frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.tsx (1)

13-21: Consider adding error boundary or error handling for child components.

While the component structure is clean, there's no explicit error handling for the child components. If either PolicyCardRules or AddPolicyRuleButton throws an error, it could affect the entire component.

Consider adding error boundaries around child components:

 return (
   <div>
+    <ErrorBoundary fallback={<div>Something went wrong with policy rules</div>}>
       <PolicyCardRules showErrorsOnAllRulesAboveNew={showErrorsOnAllRulesAboveNew} />
       <div className={classes.addCardButtonWrapper}>
         <AddPolicyRuleButton onClick={handleClickAddButton} />
       </div>
+    </ErrorBoundary>
   </div>
 );

Note: You'll need to import ErrorBoundary from a suitable source or create your own.

frontend/packages/policy-editor/src/components/PolicyEditorTabs/PolicyEditorTabs.test.tsx (1)

9-30: Consider adding additional test cases for edge conditions.

While the current tests cover the basic functionality, consider adding tests for potential edge cases, such as:

  • Testing accessibility features (keyboard navigation between tabs)
  • Testing that content updates correctly when switching between tabs multiple times
  • Testing behavior when context values change
frontend/packages/policy-editor/src/PolicyEditor.test.tsx (1)

35-49: Consider adding interaction tests for tab functionality.

While these tests verify the presence/absence of UI elements based on different usage types, they don't test the actual interaction with tabs (clicking between tabs, correct content display on tab switch).

+ it('switches between tabs correctly when clicked', async () => {
+   const user = userEvent.setup();
+   renderPolicyEditor();
+   
+   // Verify initial tab content is visible
+   const summaryTab = screen.getByText(textMock('policy_editor.rules_summary'));
+   const editTab = screen.getByText(textMock('policy_editor.rules_edit'));
+   
+   // Initially summary tab should be selected
+   expect(screen.getByText(textMock('policy_editor.summary_heading'))).toBeInTheDocument();
+   
+   // Click on the edit tab
+   await user.click(editTab);
+   
+   // Verify edit tab content is now visible
+   expect(screen.getByText(textMock('policy_editor.card_button_text'))).toBeInTheDocument();
+   
+   // Switch back to summary tab
+   await user.click(summaryTab);
+   
+   // Verify summary content is visible again
+   expect(screen.getByText(textMock('policy_editor.summary_heading'))).toBeInTheDocument();
+ });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 24921ad and 8170cd0.

📒 Files selected for processing (13)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.module.css (1 hunks)
  • frontend/language/src/nb.json (1 hunks)
  • frontend/packages/policy-editor/src/PolicyEditor.module.css (0 hunks)
  • frontend/packages/policy-editor/src/PolicyEditor.test.tsx (1 hunks)
  • frontend/packages/policy-editor/src/PolicyEditor.tsx (2 hunks)
  • frontend/packages/policy-editor/src/components/PolicyEditorTabs/PolicyEditorTabs.test.tsx (1 hunks)
  • frontend/packages/policy-editor/src/components/PolicyEditorTabs/PolicyEditorTabs.tsx (1 hunks)
  • frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.module.css (1 hunks)
  • frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.test.tsx (1 hunks)
  • frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.tsx (1 hunks)
  • frontend/packages/policy-editor/src/components/PolicySummary/PolicyRuleSummary/PolicyRuleSubjectSummary.tsx (1 hunks)
  • frontend/packages/policy-editor/src/utils/AppPolicyUtils/AppPolicyUtils.test.ts (1 hunks)
  • frontend/packages/policy-editor/src/utils/AppPolicyUtils/AppPolicyUtils.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • frontend/packages/policy-editor/src/PolicyEditor.module.css
✅ Files skipped from review due to trivial changes (2)
  • frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.module.css
  • frontend/language/src/nb.json
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
🔇 Additional comments (22)
frontend/packages/policy-editor/src/components/PolicySummary/PolicyRuleSummary/PolicyRuleSubjectSummary.tsx (1)

39-42: Improved key uniqueness for StudioTag components

The addition of subject to the key prop (${subject}-${action}-${subResource}) is a good improvement that ensures better uniqueness for React's reconciliation process, especially in scenarios where the same action-subResource combination might appear across different subjects.

frontend/packages/policy-editor/src/utils/AppPolicyUtils/AppPolicyUtils.ts (1)

56-57:

✅ Verification successful

Behavior change in filterDefaultAppLimitations function

This is a significant change in behavior. Previously, the function would return an empty array when no default limitations were found, but now it returns the original resources array. This change seems more logically correct since if there are no default limitations to filter out, the original data should be preserved.

Verify that this behavior change doesn't break any existing functionality that might expect an empty array when no default limitations are found.


🏁 Script executed:

#!/bin/bash
# Find all usages of filterDefaultAppLimitations to check impact of behavior change

# Look for files that call this function
rg --type=typescript "filterDefaultAppLimitations" -A 2 -B 2 --no-filename

Length of output: 109


I'll run a revised search that doesn't rely on the built‐in "typescript" file type. Please run the following new shell script to check for any usages of the filterDefaultAppLimitations function:

If this search returns results, review the contexts to ensure that returning the original appResources array (instead of an empty array) when no default limitations are found does not break any dependent functionalities. If no usages are found, it's less likely that this behavior change will negatively impact the codebase, but please manually verify the tests and any edge-case scenarios.


🏁 Script executed:

#!/bin/bash
# Search for usages of filterDefaultAppLimitations in TypeScript files using a glob pattern
rg "filterDefaultAppLimitations" --glob="*.ts" -A 2 -B 2 --no-filename

Length of output: 1258


Action Required: Confirm Test Coverage for Updated Filtering Behavior

The current tests confirm that:

  • When no default limitations are present in the resource list, the function returns the original appResources array.
  • In scenarios where default limitations exist, the filtering correctly produces an empty array (or removes them accordingly).

While the implemented change is logically sound and well-covered by the tests, please take an extra moment to manually verify edge cases or any integrations that might implicitly expect an empty array. Based on our review, there’s no immediate concern, and the changes seem safe.

frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.module.css (1)

2-2: Significant increase in modal width

The maximum width of the settings modal has been increased from 64rem to 150rem (more than doubling the previous size), while maintaining the responsive behavior with the 80vw constraint. This change likely accommodates the new PolicySummary component mentioned in the PR objectives.

Verify that:

  1. The increased width doesn't cause any layout issues on standard displays
  2. The content properly fills the expanded space without appearing too sparse
frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.test.tsx (1)

42-48: Helper function enhances test readability

The renderPolicyRulesEditor helper function is a good practice that encapsulates the rendering logic with the context provider, making the test cases more readable and maintainable.

frontend/packages/policy-editor/src/components/PolicyEditorTabs/PolicyEditorTabs.tsx (2)

1-5: Well-structured imports with clear dependencies.

The imports are organized logically, with React core imports first, followed by component library imports, and then project-specific components.


7-23: Clean implementation of tabbed interface with proper internationalization.

The component is well-structured with:

  • Proper use of the useTranslation hook for internationalization
  • Clear tab structure with descriptive values ('summary' and 'rules')
  • Appropriate setting of 'summary' as the default tab
  • Clean component composition using the imported tab components

This implementation follows React best practices for functional components and provides good separation of concerns between the tab structure and the content components.

frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.tsx (2)

1-5: Appropriate imports with clear dependencies.

The imports are well-organized, including React's useState hook, component imports, and CSS module import.


6-12: Well-implemented state management for error handling.

The component correctly uses the useState hook to track whether errors should be shown on rules above a newly added rule. The handler function is concise and follows best practices.

frontend/packages/policy-editor/src/components/PolicyEditorTabs/PolicyEditorTabs.test.tsx (4)

1-8: Comprehensive test setup with appropriate imports.

The imports are well-organized, including testing libraries, the component under test, context provider, and necessary mocks.


9-13: Basic test coverage for default tab selection.

The test correctly verifies that the summary tab is selected by default, which is an important behavior to validate.


15-21: Good user interaction testing for tab switching.

The test appropriately uses userEvent to simulate user interaction with the tabs and verifies the expected content is displayed after switching tabs.


24-30: Good use of helper function for consistent component rendering.

The helper function encapsulates the rendering logic with the necessary context provider, making the tests more maintainable and reducing code duplication.

frontend/packages/policy-editor/src/utils/AppPolicyUtils/AppPolicyUtils.test.ts (3)

113-113: Test description correctly updated to reflect new function behavior.

The test description has been appropriately updated to reflect the changed behavior of the filterDefaultAppLimitations function.


121-121: Updated test assertion aligns with function behavior change.

The assertion has been correctly modified to check that the function returns the input array instead of an empty array when no default app limitations are present.


113-122:

❓ Verification inconclusive

Verify impact of behavior change across the application.

The change in the filterDefaultAppLimitations function behavior from returning an empty array to returning the input array could impact other parts of the application that depend on this function.


🏁 Script executed:

#!/bin/bash
# Description: Find all usages of filterDefaultAppLimitations to assess impact of behavior change

echo "Looking for usages of filterDefaultAppLimitations function..."
rg -A 3 -B 3 "filterDefaultAppLimitations" --type ts --type tsx

echo "Checking for potential affected components..."
rg -A 5 "appResources.*filter" --type ts --type tsx

Length of output: 407


Manual Verification Required: Confirm Impact of filterDefaultAppLimitations Change

The behavior of filterDefaultAppLimitations now returns the input array instead of an empty array when no default limitations are present. An initial automated search for its usages failed due to file type filtering issues (unrecognized file type: tsx).

  • Please re-run the search across both .ts and .tsx files. For example, you might use:
    # Search in both TypeScript file types
    fd -e ts -e tsx -x rg -A 3 -B 3 "filterDefaultAppLimitations"
    
    fd -e ts -e tsx -x rg -A 5 "appResources.*filter"
  • Verify manually that no other parts of the application rely on the previous behavior (i.e., an empty array being returned).
frontend/packages/policy-editor/src/PolicyEditor.test.tsx (2)

38-43: Good test implementation for the app usage type.

This test correctly verifies that the component renders a tabbed interface when the usageType is set to 'app', checking for the presence of key elements in the UI.


45-49: Good test implementation for the resource usage type.

This test appropriately verifies the alternate rendering path when usageType is 'resource', ensuring the tab interface is not present and the rules view is properly displayed.

frontend/packages/policy-editor/src/PolicyEditor.tsx (5)

22-23: Good modularization of components.

The addition of dedicated components for policy rules editing and tab navigation improves the code's modularity and separation of concerns.


93-93: Clean conditional rendering implementation.

The conditional rendering based on usageType is concise and readable, providing different experiences for app and resource contexts.


99-102:

❓ Verification inconclusive

Address TODO comment about resource type determination.

There's another TODO comment about how the resource type should be determined. This should be addressed to ensure the implementation is as intended.


🏁 Script executed:

#!/bin/bash
# Search for related issues to understand context of the TODO
gh issue view 10880 || echo "Issue #10880 not found or not accessible"

# Check if there are any recent updates or discussions on this issue
gh issue list --search "10880 in:comments" --limit 5

Length of output: 728


Confirm Resource Type Determination Approach

The issue (#10880) is closed, but the acceptance criteria indicate that the correct resource type hasn’t been finalized. Please verify whether the current hardcoded values meet the intended design. If these values (i.e. 'urn:altinn' for apps and 'urn:altinn:resource' for resources) are still acceptable, remove the TODO; otherwise, update the implementation based on any final decision or documented requirements.


54-67:

❓ Verification inconclusive

Verify policy saving logic with new component structure.

The policy saving logic appears unchanged, but ensure it still properly integrates with the new PolicyRulesEditor and PolicyEditorTabs components. Make sure these components can properly trigger the handleSavePolicy function with the correct data.


🏁 Script executed:

#!/bin/bash
# Check how the new components interact with the save functionality
echo "Checking PolicyRulesEditor for save functionality:"
rg -n "savePolicy|handleSave" frontend/packages/policy-editor/src/components/PolicyRulesEditor/

echo "Checking PolicyEditorTabs for save functionality:"
rg -n "savePolicy|handleSave" frontend/packages/policy-editor/src/components/PolicyEditorTabs/

Length of output: 587


Action Required: Verify Integration of Save Functionality in PolicyEditorTabs

The current tests confirm that PolicyRulesEditor calls the save function (as seen in its test file), which is great. However, we detected no direct references to savePolicy or handleSave in PolicyEditorTabs. Please ensure that:

  • PolicyEditorTabs is correctly wired to trigger the handleSavePolicy function or otherwise integrate with the save logic.
  • The absence of direct references in PolicyEditorTabs is intentional (e.g., if it delegates the save operation in a non-obvious way) and is covered by existing tests.

It’s recommended to manually verify or add tests for PolicyEditorTabs to confirm it dispatches the save correctly when needed.


1-102:

✅ Verification successful

Include unit tests for refactored components.

With the introduction of PolicyRulesEditor and PolicyEditorTabs components, ensure these new components have adequate test coverage to maintain the overall test coverage of the application.


🏁 Script executed:

#!/bin/bash
# Check if test files exist for the new components
echo "Checking for PolicyRulesEditor tests:"
ls -la frontend/packages/policy-editor/src/components/PolicyRulesEditor/*.test.tsx || echo "Test file not found"

echo "Checking for PolicyEditorTabs tests:"
ls -la frontend/packages/policy-editor/src/components/PolicyEditorTabs/*.test.tsx || echo "Test file not found"

Length of output: 647


Unit Test Coverage Verified for New Components

The new components already include unit tests:

  • frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.test.tsx
  • frontend/packages/policy-editor/src/components/PolicyEditorTabs/PolicyEditorTabs.test.tsx

No further action is needed regarding unit tests at this time. Please ensure that these tests continue to cover all relevant scenarios as changes are made.

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: 0

🧹 Nitpick comments (3)
frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.test.tsx (3)

28-39: Test name doesn't match assertion.

The test name suggests that it checks if the rule list length increases, but it only verifies that the savePolicy function was called, without confirming the actual list length change.

Consider adding an assertion that actually verifies the list length increases, or rename the test to better reflect what it's actually testing:

- it('increases the rule list length when add rule button is clicked', async () => {
+ it('calls savePolicy when add rule button is clicked', async () => {

Alternatively, if you want to verify the rule list length increases, you should update the mock to reflect the change and add an assertion:

// After the click
await user.click(addButton);

// Update the mock to simulate what would happen in the real component
mockPolicyEditorContextValue.policy.rules = [...mockPolicy.rules, newMockRule];

// Re-render to reflect changes
rerender();

// Now check that an additional rule appears
const updatedLabelCount = screen.queryAllByText(
  textMock('policy_editor.rule_card_sub_resource_title')
).length;
expect(updatedLabelCount).toEqual(mockPolicy.rules.length + 1);

42-48: Consider placing the helper function before tests.

While JavaScript allows function declarations to be hoisted, it's a good practice to define helper functions before using them for better readability.

Consider moving the renderPolicyRulesEditor function above the test suite.


1-49: Consider adding more test cases.

The test file currently only tests basic functionality. Consider adding more test cases for error handling, edge cases, or specific interactions with policy rules.

Additional test cases to consider:

  • Testing error states
  • Testing editing existing rules
  • Testing deletion of rules
  • Testing validation of rules
  • Testing the behavior when there are no rules
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8170cd0 and efa06eb.

📒 Files selected for processing (1)
  • frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.test.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
  • GitHub Check: CodeQL
🔇 Additional comments (3)
frontend/packages/policy-editor/src/components/PolicyRulesEditor/PolicyRulesEditor.test.tsx (3)

1-9: Good imports and setup.

The file correctly imports the necessary components, mocks, and testing utilities needed for the test suite.


11-17: Mock data is well structured.

The mock policy object provides all required properties for testing purposes.


19-26: Test verifies correct rendering of policy rules.

The test effectively verifies that the component renders the correct number of policy rules based on the mock data.

Copy link

codecov bot commented Mar 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.80%. Comparing base (38052e5) to head (b35c5c0).
Report is 20 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14888   +/-   ##
=======================================
  Coverage   95.80%   95.80%           
=======================================
  Files        1928     1930    +2     
  Lines       25201    25216   +15     
  Branches     2878     2879    +1     
=======================================
+ Hits        24143    24158   +15     
  Misses        797      797           
  Partials      261      261           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/authorization Area: Issues related to roles and rights on apps, such as who can instantiate, sign etc. frontend solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-core
Projects
Status: 👷 In Progress
Development

Successfully merging this pull request may close these issues.

1 participant