Skip to content

test(frontend): add unit tests for RetentionBanner and SuspendedBanner (#115) - #116

Open
rishi919-rgb wants to merge 5 commits into
fossasia:mainfrom
rishi919-rgb:test/workspace-banners
Open

rishi919-rgb wants to merge 5 commits into
fossasia:mainfrom
rishi919-rgb:test/workspace-banners

Conversation

@rishi919-rgb

@rishi919-rgb rishi919-rgb commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Description

Adds comprehensive unit test suites for the workspace banner components:

  • RetentionBanner (frontend/src/components/workspace/RetentionBanner.jsx) under frontend/src/components/workspace/__tests__/RetentionBanner.test.jsx.
  • SuspendedBanner (frontend/src/components/workspace/SuspendedBanner.jsx) under frontend/src/components/workspace/__tests__/SuspendedBanner.test.jsx.

Test Coverage Highlights

  • RetentionBanner:
    • Returns null when workspace or notice is null or undefined.
    • Returns null when isExpiringSoon(notice) is false (forever, not_enforced, or active with empty expiring array).
    • Renders singular environment heading (1 environment in <name> will be removed soon) and clock icon when exactly one environment is expiring.
    • Renders plural environment heading (<N> environments in <name> will be removed soon) when multiple environments are expiring.
    • Tests 5-item boundary condition where count equals display limit without truncation.
    • Formats retention summary policy and expiration warning days heading.
    • Formats scheduled date retention summary and scheduled expiration heading for scheduled notices.
    • Truncates list and appends and <N> more when expiring environments exceed the display threshold of 5.
  • SuspendedBanner:
    • Returns null when workspace is null, undefined, or is_active !== false (active workspace or omitted status).
    • Renders alert icon and <name> is suspended banner header when is_active === false.
    • Displays descriptive body message explaining that plots and members are intact and advising contacting an administrator.

Motivation and Context

Fixes #115.
Part of the console frontend test coverage initiative (#73).

How Has This Been Tested?

Ran all frontend verification tooling locally:

  1. npx vitest run src/components/workspace/__tests__/RetentionBanner.test.jsx src/components/workspace/__tests__/SuspendedBanner.test.jsx: 14 passed (14)
  2. npm test: All 218 unit tests passed across all 28 test files
  3. npm run lint: ESLint checked all files with 0 errors / 0 warnings
  4. npm run build: Vite production build passed in 537ms

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature / Tests (non-breaking change which adds tests/functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation (N/A).
  • I have updated the documentation accordingly (N/A).
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Summary by Sourcery

Add frontend unit tests covering retention and suspension workspace banners.

Tests:

  • Add unit test coverage for RetentionBanner visibility, retention messaging, environment list truncation, and scheduled notices.
  • Add unit test coverage for SuspendedBanner visibility, warning content, and suspended workspace status.

Summary by CodeRabbit

  • Tests
    • Expanded coverage for retention and suspension banners across missing, active, and scheduled states.
    • Added checks for retention summaries, singular and plural headings, environment lists around the display limit, and suspension details such as the workspace name and warning icon.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e78ddc3d-ce1c-4c4f-aa18-421b08bf16a6
Commits

Reviewing files that changed from the base of the PR and between 8f46349 and 7931948.

Files selected for processing: 2

  • frontend/src/components/workspace/__tests__/RetentionBanner.test.jsx
  • frontend/src/components/workspace/__tests__/SuspendedBanner.test.jsx

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds unit tests for RetentionBanner and SuspendedBanner. The tests cover rendering conditions, banner text, warning icons, retention summaries, and environment-list limits.

Changes: Workspace banner tests

Layer / File(s) Summary
Banner rendering and content
frontend/src/components/workspace/__tests__/RetentionBanner.test.jsx, frontend/src/components/workspace/__tests__/SuspendedBanner.test.jsx
Tests check when each banner renders. Retention banner tests also check environment headings, retention summaries, and the five-name display limit. Suspended banner tests check the suspended message and warning icon.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: vedansh-5

Merge Risk: Minimal · previous review 8f463

This change adds unit tests for the workspace retention and suspension banners and does not alter product behavior. It has no production impact and is ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title follows the conventional commit style and names the main change: adding unit tests for the RetentionBanner and SuspendedBanner components. The changeset contains only test files for those tw…
Linked Issues check Passed Issue #115 requires unit tests for RetentionBanner and SuspendedBanner. Both test files exist at head: frontend/src/components/workspace/tests/RetentionBanner.test.jsx and SuspendedBanner.test.jsx…
Out of Scope Changes check Passed The whole-PR diff against the merge base (bec3099) adds only two test files: RetentionBanner.test.jsx (+153) and SuspendedBanner.test.jsx (+61), per the change summary. No component implementation, c…
Full details: Title check

Explanation

The title follows the conventional commit style and names the main change: adding unit tests for the RetentionBanner and SuspendedBanner components. The changeset contains only test files for those two components, and the linked issue #115 requests exactly this coverage. The title does not describe any unrelated change.

Full details: Linked Issues check

Explanation

Issue #115 requires unit tests for RetentionBanner and SuspendedBanner. Both test files exist at head: frontend/src/components/workspace/tests/RetentionBanner.test.jsx and SuspendedBanner.test.jsx. Each requirement maps to a test:

  • Null rendering for null, undefined, or omitted workspace: RetentionBanner and SuspendedBanner tests cover this. The RetentionBanner component returns null when !workspace, and SuspendedBanner returns null when !workspace.
  • Null rendering for isExpiringSoon false, including null notice, forever, not_enforced, and empty expiring list: covered. The component guards on !isExpiringSoon(notice).
  • Singular heading ('1 environment in <name> will be removed soon') with clock icon: covered, including the lucide-clock class check.
  • Plural heading ('<N> environments in <name> ...'): covered for 2 and 5 environments.
  • Retention summary and expiring heading based on policy, active and scheduled: covered with exact text for active and scheduled states.
  • List up to 5 without truncation, and truncation above 5 with 'and N more': covered at the boundary (5) and above (8, showing 'and 3 more').
  • SuspendedBanner is_active === false: covered for the name header ('<name> is suspended'), the alert icon (lucide-triangle-alert), and the body text about preserved plots and members and contacting an administrator.
    No coding requirement is unmet. The test assertions match the component code I read at head. I did not run the test suite. The pass counts in the PR description are author-reported and were not independently verified.
Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base (bec3099) adds only two test files: RetentionBanner.test.jsx (+153) and SuspendedBanner.test.jsx (+61), per the change summary. No component implementation, configuration, or unrelated files change. Every added test case targets behavior named in #115 or the current PR description. The scope is within the issue.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6ef6f757-e7ab-4cb8-83f2-890111089626
Commits

Reviewing files that changed from the base of the PR and between bec3099 and 8f46349.

Files selected for processing: 2

  • frontend/src/components/workspace/__tests__/RetentionBanner.test.jsx
  • frontend/src/components/workspace/__tests__/SuspendedBanner.test.jsx

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Tests

Test RetentionBanner visibility, retention messaging, environment counts and truncation, scheduled notices, and clock-icon rendering.

  • frontend/src/components/workspace/__tests__/RetentionBanner.test.jsx L1-153

Test SuspendedBanner visibility conditions, suspension messaging, and warning-icon rendering.

  • frontend/src/components/workspace/__tests__/SuspendedBanner.test.jsx L1-61

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 7931948

#115 [Feature]: Add unit tests for RetentionBanner and SuspendedBanner components · 10 of 10 met

# Requirement Status Notes
1 RetentionBanner returns null when workspace is null, undefined, or missing ✅ Met Tests all three workspace cases.
2 RetentionBanner returns null when isExpiringSoon(notice) is false ✅ Met Tests null and undefined notices, inactive states, and an active notice with an empty expiring list.
3 Render the singular heading when exactly one environment is expiring ✅ Met Also checks the environment name and clock icon.
4 Render the plural heading when multiple environments are expiring ✅ Met Checks the heading and displayed environment list.
5 Display retention summary and expiring heading text based on notice policy ✅ Met Asserts summary and heading text for active and scheduled notices.
6 Format the environment list properly when the count is within the display limit (5 or fewer) ✅ Met Covers counts of one, two, and exactly five without truncation.
7 Truncate the environment list and append “and more” when the count exceeds 5 ✅ Met Checks that eight environments display the first five and “and 3 more.”
8 SuspendedBanner returns null when workspace is null, undefined, or is_active is not false ✅ Met Tests null, undefined, omitted workspace, active workspace, and omitted is_active.
9 Render the warning icon and suspended heading when is_active is false ✅ Met Checks the workspace name and alert icon class.
10 Display the suspension description explaining data is preserved and advising contact with an administrator ✅ Met Asserts the full description text.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="frontend/src/components/workspace/__tests__/RetentionBanner.test.jsx" line_range="38-47" />
<code_context>
+      expect(containerUndef.firstChild).toBeNull();
+    });
+
+    it('returns null when notice state is not expiring soon (forever or not_enforced)', () => {
+      const foreverNotice = { state: 'forever', expiring: [] };
+      const { container: containerForever } = render(<RetentionBanner workspace={sampleWorkspace} notice={foreverNotice} />);
+      expect(containerForever.firstChild).toBeNull();
+
+      const notEnforcedNotice = { state: 'not_enforced', expiring: [] };
+      const { container: containerNotEnforced } = render(
+        <RetentionBanner workspace={sampleWorkspace} notice={notEnforcedNotice} />
+      );
+      expect(containerNotEnforced.firstChild).toBeNull();
+    });
+
</code_context>
<issue_to_address>
**Non-expiring states escape coverage**

When a `forever` or `not_enforced` notice contains expiring entries, the `returns null when notice state is not expiring soon` test still passes because both fixtures set `expiring: []`; removing the state check from `isExpiringSoon` would go undetected, and notices in those states with entries could render banners.

Give both non-expiring-state fixtures nonempty `expiring` arrays so the assertions exercise the state check.
</issue_to_address>

### Comment 2
<location path="frontend/src/components/workspace/__tests__/SuspendedBanner.test.jsx" line_range="47" />
<code_context>
+
+      render(<SuspendedBanner workspace={suspendedWorkspace} />);
+
+      expect(screen.getByText(/Bioinformatics Lab is suspended/)).toBeInTheDocument();
+      expect(
+        screen.getByText(
</code_context>
<issue_to_address>
**Suspended workspaces lose warning icon**

When the warning icon is removed from the component, the heading and body-text assertions in `SuspendedBanner.test.jsx` still pass, so the suite misses the lost warning icon.

Add an assertion that the warning icon is present.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: frontend/src/components/workspace/__tests__/RetentionBanner.test.jsx:47, frontend/src/components/workspace/__tests__/SuspendedBanner.test.jsx:47


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +38 to +47
it('returns null when notice state is not expiring soon (forever or not_enforced)', () => {
const foreverNotice = { state: 'forever', expiring: [] };
const { container: containerForever } = render(<RetentionBanner workspace={sampleWorkspace} notice={foreverNotice} />);
expect(containerForever.firstChild).toBeNull();

const notEnforcedNotice = { state: 'not_enforced', expiring: [] };
const { container: containerNotEnforced } = render(
<RetentionBanner workspace={sampleWorkspace} notice={notEnforcedNotice} />
);
expect(containerNotEnforced.firstChild).toBeNull();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Non-expiring states escape coverage

When a forever or not_enforced notice contains expiring entries, the returns null when notice state is not expiring soon test still passes because both fixtures set expiring: []; removing the state check from isExpiringSoon would go undetected, and notices in those states with entries could render banners.

Give both non-expiring-state fixtures nonempty expiring arrays so the assertions exercise the state check.

Prompt for AI agents
In `frontend/src/components/workspace/__tests__/RetentionBanner.test.jsx` at lines 38-47:

**Non-expiring states escape coverage**

When a `forever` or `not_enforced` notice contains expiring entries, the `returns null when notice state is not expiring soon` test still passes because both fixtures set `expiring: []`; removing the state check from `isExpiringSoon` would go undetected, and notices in those states with entries could render banners.

Give both non-expiring-state fixtures nonempty `expiring` arrays so the assertions exercise the state check.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New gaps against the linked issues

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New gaps against the linked issues

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New gaps against the linked issues

@rishi919-rgb
rishi919-rgb force-pushed the test/workspace-banners branch from 8f46349 to 7931948 Compare December 4, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add unit tests for RetentionBanner and SuspendedBanner components

1 participant