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

fix: group & proposal theme and layout #41

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

Conversation

fmorency
Copy link
Contributor

@fmorency fmorency commented Nov 14, 2024

This PR

  • Removes the unused adminOptions component and tests
  • Fixes the Group page dark and light theming to use theme colors
  • Fixes table elements theme and hover
  • Fixes Tally modal theming
  • Fixes Tally modal parent container overflow
  • Fixes theme colors

Fixes #40
Partially fixes #32

2024-11-14_15-59
2024-11-14_15-59_1
2024-11-14_15-59_2
2024-11-14_16-00
2024-11-14_16-00_1
2024-11-15_08-54

Summary by CodeRabbit

  • New Features

    • Removed the AdminOptions component, streamlining the admin interface.
  • Bug Fixes

    • Updated the message displayed when no proposals are found for clarity.
  • UI Improvements

    • Enhanced styling and layout for various components, including CountdownTimer, GroupProposals, myGroups, and VoteDetailsModal.
    • Adjusted color schemes and hover effects for better user interaction.
  • Configuration

    • Updated theme colors in the Tailwind configuration for improved visual consistency across light and dark modes.

@fmorency fmorency self-assigned this Nov 14, 2024
Copy link

coderabbitai bot commented Nov 14, 2024

Walkthrough

This pull request involves the deletion of the AdminOptions component and its associated test file, adminOptions.test.tsx, indicating that this functionality is no longer part of the codebase. Additionally, the export statement for adminOptions has been removed from the index file. Other changes include various updates to the styling and layout of components such as CountdownTimer, GroupProposals, myGroups, and VoteDetailsModal, along with modifications to the tailwind.config.js for theme colors.

Changes

File Change Summary
components/admins/components/__tests__/adminOptions.test.tsx Deleted file containing unit tests for AdminOptions component.
components/admins/components/adminOptions.tsx Deleted file containing the AdminOptions component.
components/admins/components/index.tsx Removed export statement for adminOptions.
components/groups/components/CountdownTimer.tsx Updated styling with new class additions; no logic changes.
components/groups/components/__tests__/groupProposals.test.tsx Modified assertion text for no proposals found.
components/groups/components/groupProposals.tsx Enhanced UI with layout and styling updates; improved error handling.
components/groups/components/myGroups.tsx Updated styling and structure for group display; no logic changes.
components/groups/modals/voteDetailsModal.tsx Adjusted styling and logic for better usability and visual consistency.
tailwind.config.js Updated theme colors for light and dark modes.

Assessment against linked issues

Objective Addressed Explanation
Mislocated proposal search box (40)
Hard to see elements in light theme (32)

Possibly related PRs

  • fix: admin page layout & refactor #38: The changes in this PR involve the isLoading prop and loading state management, which are also relevant to the AdminOptions component's tests that checked for loading states.

Suggested reviewers

  • chalabi2

Poem

🐰 In the meadow, changes bloom,
AdminOptions, now no more room.
Styles refreshed, colors anew,
A vibrant world for us to view.
With each update, we hop and cheer,
For a brighter path, our vision clear! 🌼


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

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 61.19403% with 52 lines in your changes missing coverage. Please review.

Project coverage is 58.92%. Comparing base (dbc6ca0) to head (16c9c64).

Files with missing lines Patch % Lines
components/groups/modals/voteDetailsModal.tsx 37.20% 27 Missing ⚠️
components/groups/components/myGroups.tsx 63.76% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
- Coverage   59.07%   58.92%   -0.15%     
==========================================
  Files         148      147       -1     
  Lines       13860    13824      -36     
==========================================
- Hits         8188     8146      -42     
- Misses       5672     5678       +6     

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

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

🧹 Outside diff range and nitpick comments (14)
components/groups/components/__tests__/groupProposals.test.tsx (1)

Line range hint 1-142: Consider adding theme-related test coverage.

Since this PR focuses on theming improvements, consider adding test cases to verify:

  • Component rendering in both dark and light modes
  • Proper application of theme colors
  • Hover state styling for interactive elements

Example test case:

test('applies correct theme styles', () => {
  const { rerender } = renderWithChainProvider(
    <ProposalsForPolicy {...mockProps} />,
    { theme: 'light' }
  );
  
  // Verify light theme styles
  const element = screen.getByTestId('proposals-container');
  expect(element).toHaveClass('bg-light-theme');
  
  // Verify dark theme styles
  rerender(
    <ProposalsForPolicy {...mockProps} />,
    { theme: 'dark' }
  );
  expect(element).toHaveClass('bg-dark-theme');
});
tailwind.config.js (2)

117-118: Review tooltip color consistency across themes.

The tooltip color is set to white (#ffffff) in both themes, which might not be optimal for the light theme. Consider using theme-specific colors for better visibility.

 light: {
   // ...
-  'tooltip-color': '#ffffff',
+  'tooltip-color': '#161616',
   // ...
 }

96-99: Consider theme-specific status colors.

The status colors (info, success, warning, error) are identical in both themes. While this maintains consistency, consider adjusting their brightness or saturation for better visibility in dark mode.

For dark theme, consider slightly brighter variants:

 dark: {
   // ...
-  info: '#3F51B5',
-  success: '#4CAF50',
-  warning: '#FFB300',
-  error: '#E53935',
+  info: '#5C6BC0',
+  success: '#66BB6A',
+  warning: '#FFCA28',
+  error: '#EF5350',
 }

Also applies to: 119-122

components/groups/components/myGroups.tsx (3)

Line range hint 86-95: Consider using Tailwind classes for font styles

Instead of using inline styles for font properties, consider using Tailwind's utility classes for better maintainability and consistency.

-                style={{ fontSize: '20px', fontWeight: 700, lineHeight: '24px' }}
+                className="text-secondary-content text-xl font-bold leading-6"

124-152: Add tests for skeleton loading UI

The skeleton loading UI is not covered by tests. Consider adding tests to verify proper rendering of the loading state.

Would you like me to help generate test cases for the skeleton loading UI? Here's what we should test:

  1. Verify skeleton renders when isLoading is true
  2. Verify correct number of skeleton rows (12)
  3. Verify skeleton doesn't render when isLoading is false
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 126-150: components/groups/components/myGroups.tsx#L126-L150
Added lines #L126 - L150 were not covered by tests


Line range hint 227-269: Improve accessibility for clickable rows

While the styling is consistent, consider these accessibility improvements:

  1. Add role="button" to the row
  2. Add keyboard navigation support
  3. Add aria-label for better screen reader support
     <tr
-      className="group text-black dark:text-white rounded-lg cursor-pointer transition-colors"
+      className="group text-black dark:text-white rounded-lg cursor-pointer transition-colors focus:outline-none focus:ring-2 focus:ring-primary"
+      role="button"
+      tabIndex={0}
+      aria-label={`Select group ${groupName}`}
       onClick={e => {
         e.stopPropagation();
         onSelectGroup(policyAddress, groupName, ...);
       }}
+      onKeyDown={e => {
+        if (e.key === 'Enter' || e.key === ' ') {
+          e.preventDefault();
+          onSelectGroup(policyAddress, groupName, ...);
+        }
+      }}
     >
components/groups/components/groupProposals.tsx (3)

Line range hint 244-268: Add ARIA labels for better accessibility

The header buttons lack proper accessibility attributes which could make navigation difficult for screen reader users.

Apply these changes to improve accessibility:

-          <button onClick={onBack} className="btn btn-circle rounded-[16px] bg-secondary btn-md">
+          <button 
+            onClick={onBack} 
+            className="btn btn-circle rounded-[16px] bg-secondary btn-md"
+            aria-label="Go back"
+          >
            <ArrowRightIcon className="text-primary" />
          </button>

           <button
             className="btn w-[140px] h-[52px] rounded-[12px] focus:outline-none dark:bg-[#FFFFFF0F] bg-[#0000000A]"
             onClick={openInfoModal}
+            aria-label="Open group information"
           >
             Info
           </button>
           <button
             className="btn w-[140px] h-[52px] rounded-[12px] focus:outline-none dark:bg-[#FFFFFF0F] bg-[#0000000A]"
             onClick={openMemberModal}
+            aria-label="Open member management"
           >
             Members
           </button>

269-287: Enhance search input with debouncing

The search functionality directly updates on every keystroke, which could cause performance issues with large datasets.

Consider implementing debouncing:

+import { useCallback } from 'react';
+import debounce from 'lodash/debounce';

 const [searchTerm, setSearchTerm] = useState('');
+const debouncedSearch = useCallback(
+  debounce((value: string) => {
+    setSearchTerm(value);
+  }, 300),
+  []
+);

 <input
   type="text"
   placeholder="Search for a proposal..."
   className="input input-bordered w-[224px] h-[40px] rounded-[12px] border-none bg-secondary text-secondary-content pl-10"
-  value={searchTerm}
-  onChange={e => setSearchTerm(e.target.value)}
+  defaultValue={searchTerm}
+  onChange={e => debouncedSearch(e.target.value)}
+  aria-label="Search proposals"
 />

Line range hint 357-388: Improve table accessibility and keyboard navigation

The table rows are clickable but lack proper keyboard navigation support and ARIA attributes.

Apply these changes to improve accessibility:

 <tr
   key={proposal.id.toString()}
   onClick={() => handleRowClick(proposal)}
-  className="group text-black dark:text-white rounded-lg cursor-pointer"
+  className="group text-black dark:text-white rounded-lg cursor-pointer focus-within:ring-2 focus-within:ring-primary"
+  role="button"
+  tabIndex={0}
+  onKeyPress={(e) => {
+    if (e.key === 'Enter' || e.key === ' ') {
+      handleRowClick(proposal);
+    }
+  }}
+  aria-label={`Proposal ${proposal.id}: ${proposal.title}`}
 >

Also, consider adding a role="status" to the loading spinner and empty state message for better screen reader support.

components/groups/modals/voteDetailsModal.tsx (5)

69-69: Theme colors should be defined in the theme configuration

The hardcoded color values (#FFFFFF, #161616) and chart colors should be moved to the theme configuration for better maintainability and consistency.

Consider moving these values to your theme configuration:

- const textColor = theme === 'dark' ? '#FFFFFF' : '#161616';
+ const textColor = theme === 'dark' ? colors.dark.text : colors.light.text;

- colors: ['#4CAF50', '#E53935', '#FFB300', '#3F51B5'],
+ colors: theme === 'dark' 
+   ? colors.dark.chart 
+   : colors.light.chart,

Also applies to: 188-188


515-516: Improve table accessibility and responsiveness

The table implementation could be enhanced for better accessibility and mobile responsiveness.

  1. Add role="table" for better screen reader support
  2. Consider using CSS Grid for better mobile layout
  3. Add proper ARIA labels for the table cells
- <div className="bg-base-300 rounded-[12px] p-4 w-full">
-   <div className="overflow-x-auto w-full min-h-64 max-h-[22.5rem] overflow-y-auto">
-     <table className="table-auto w-full text-sm">
+ <div className="bg-base-300 rounded-[12px] p-4 w-full">
+   <div className="overflow-x-auto w-full min-h-64 max-h-[22.5rem] overflow-y-auto">
+     <table role="table" className="table-auto w-full text-sm" aria-label="Group Members">

Also applies to: 541-541, 545-547

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 515-516: components/groups/modals/voteDetailsModal.tsx#L515-L516
Added lines #L515 - L516 were not covered by tests


509-511: Consider adding loading states for the chart

The chart rendering doesn't handle loading states, which could lead to a poor user experience during data fetching.

+ const [isChartLoading, setIsChartLoading] = useState(true);
  <div className="bg-base-300 rounded-[12px] w-full">
+   {isChartLoading && <div className="loading loading-lg" />}
    <Chart options={options} series={[{ data: chartData }]} type="bar" height={200} />
  </div>
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 509-509: components/groups/modals/voteDetailsModal.tsx#L509
Added line #L509 was not covered by tests


518-532: Improve table header accessibility

The table headers could be enhanced for better accessibility and semantic meaning.

- <thead className="text-xs uppercase bg-neutral">
+ <thead className="text-xs uppercase bg-neutral" role="rowgroup">
    <tr>
      <th
        scope="col"
+       role="columnheader"
+       aria-sort="none"
        className="px-6 py-3 first:rounded-tl-[12px] text-primary-content"
      >
        Address
      </th>
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 518-518: components/groups/modals/voteDetailsModal.tsx#L518
Added line #L518 was not covered by tests


[warning] 520-522: components/groups/modals/voteDetailsModal.tsx#L520-L522
Added lines #L520 - L522 were not covered by tests


[warning] 526-526: components/groups/modals/voteDetailsModal.tsx#L526
Added line #L526 was not covered by tests


[warning] 529-531: components/groups/modals/voteDetailsModal.tsx#L529-L531
Added lines #L529 - L531 were not covered by tests


133-135: Chart legend markers configuration could be simplified

The current chart legend marker configuration can be simplified using the theme's color palette.

- markers: {
-   strokeWidth: 0,
- },
+ markers: {
+   strokeWidth: 0,
+   fillColors: theme === 'dark' ? colors.dark.chart : colors.light.chart,
+ },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dbc6ca0 and 1c22999.

📒 Files selected for processing (9)
  • components/admins/components/__tests__/adminOptions.test.tsx (0 hunks)
  • components/admins/components/adminOptions.tsx (0 hunks)
  • components/admins/components/index.tsx (0 hunks)
  • components/groups/components/CountdownTimer.tsx (1 hunks)
  • components/groups/components/__tests__/groupProposals.test.tsx (1 hunks)
  • components/groups/components/groupProposals.tsx (4 hunks)
  • components/groups/components/myGroups.tsx (5 hunks)
  • components/groups/modals/voteDetailsModal.tsx (10 hunks)
  • tailwind.config.js (1 hunks)
💤 Files with no reviewable changes (3)
  • components/admins/components/tests/adminOptions.test.tsx
  • components/admins/components/adminOptions.tsx
  • components/admins/components/index.tsx
✅ Files skipped from review due to trivial changes (1)
  • components/groups/components/CountdownTimer.tsx
🧰 Additional context used
🪛 GitHub Check: codecov/patch
components/groups/components/myGroups.tsx

[warning] 126-150: components/groups/components/myGroups.tsx#L126-L150
Added lines #L126 - L150 were not covered by tests

components/groups/modals/voteDetailsModal.tsx

[warning] 355-355: components/groups/modals/voteDetailsModal.tsx#L355
Added line #L355 was not covered by tests


[warning] 357-357: components/groups/modals/voteDetailsModal.tsx#L357
Added line #L357 was not covered by tests


[warning] 366-366: components/groups/modals/voteDetailsModal.tsx#L366
Added line #L366 was not covered by tests


[warning] 376-376: components/groups/modals/voteDetailsModal.tsx#L376
Added line #L376 was not covered by tests


[warning] 380-382: components/groups/modals/voteDetailsModal.tsx#L380-L382
Added lines #L380 - L382 were not covered by tests


[warning] 461-463: components/groups/modals/voteDetailsModal.tsx#L461-L463
Added lines #L461 - L463 were not covered by tests


[warning] 467-467: components/groups/modals/voteDetailsModal.tsx#L467
Added line #L467 was not covered by tests


[warning] 474-475: components/groups/modals/voteDetailsModal.tsx#L474-L475
Added lines #L474 - L475 were not covered by tests


[warning] 479-480: components/groups/modals/voteDetailsModal.tsx#L479-L480
Added lines #L479 - L480 were not covered by tests


[warning] 487-487: components/groups/modals/voteDetailsModal.tsx#L487
Added line #L487 was not covered by tests


[warning] 509-509: components/groups/modals/voteDetailsModal.tsx#L509
Added line #L509 was not covered by tests


[warning] 515-516: components/groups/modals/voteDetailsModal.tsx#L515-L516
Added lines #L515 - L516 were not covered by tests


[warning] 518-518: components/groups/modals/voteDetailsModal.tsx#L518
Added line #L518 was not covered by tests


[warning] 520-522: components/groups/modals/voteDetailsModal.tsx#L520-L522
Added lines #L520 - L522 were not covered by tests


[warning] 526-526: components/groups/modals/voteDetailsModal.tsx#L526
Added line #L526 was not covered by tests


[warning] 529-531: components/groups/modals/voteDetailsModal.tsx#L529-L531
Added lines #L529 - L531 were not covered by tests

🔇 Additional comments (4)
components/groups/components/__tests__/groupProposals.test.tsx (1)

111-111: LGTM! Text update matches UI changes.

The updated assertion correctly reflects the new message displayed when no proposals are found.

tailwind.config.js (2)

81-122: Theme configuration looks good overall!

The updated color scheme provides a consistent visual hierarchy and maintains the purple-based theme identity across both light and dark modes. The changes align well with the PR objectives of fixing theme-related issues.


81-83: Consider accessibility implications of the primary color.

The primary color #A087FF might not provide sufficient contrast against white backgrounds for smaller text elements. Consider using a darker shade for better accessibility or ensuring it's not used for critical text elements.

components/groups/modals/voteDetailsModal.tsx (1)

Line range hint 355-382: Add test coverage for new UI elements

Several new UI elements and text formatting changes lack test coverage. This includes message rendering, title display, and various text elements.

Would you like me to help create test cases for these new UI elements? I can generate comprehensive tests that cover:

  1. Theme-based text color rendering
  2. Message field formatting
  3. Modal layout responsiveness

Also applies to: 461-463, 467-467, 474-475, 479-480, 487-487

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 376-376: components/groups/modals/voteDetailsModal.tsx#L376
Added line #L376 was not covered by tests


[warning] 380-382: components/groups/modals/voteDetailsModal.tsx#L380-L382
Added lines #L380 - L382 were not covered by tests

components/groups/components/myGroups.tsx Outdated Show resolved Hide resolved
@@ -416,21 +421,23 @@

return (
<dialog id={modalId} className="modal">
<div className="modal-box relative max-w-4xl min-h-96 flex flex-col md:flex-row md:ml-20 -mt-12 rounded-[24px] shadow-lg dark:bg-[#1D192D] bg-[#FFFFFF] transition-all duration-300 z-[1000]">
<div className="modal-box relative max-w-4xl min-h-96 max-h-[80vh] overflow-y-hidden flex flex-col md:flex-row md:ml-20 -mt-12 rounded-[24px] shadow-lg bg-secondary transition-all duration-300 z-[1000]">
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve modal positioning and layout

The modal's positioning uses negative margin (-mt-12) which is a fragile solution. Consider using proper positioning techniques.

- <div className="modal-box relative max-w-4xl min-h-96 max-h-[80vh] overflow-y-hidden flex flex-col md:flex-row md:ml-20 -mt-12 rounded-[24px] shadow-lg bg-secondary transition-all duration-300 z-[1000]">
+ <div className="modal-box relative max-w-4xl min-h-96 max-h-[80vh] overflow-y-hidden flex flex-col md:flex-row rounded-[24px] shadow-lg bg-secondary transition-all duration-300">

Also applies to: 424-424

@fmorency fmorency mentioned this pull request Nov 15, 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: 2

🧹 Outside diff range and nitpick comments (1)
components/groups/modals/voteDetailsModal.tsx (1)

Based on the initial search results, I can generate the final response since we found enough context showing:

  1. The existence of ProposalMessages.test.tsx with commented-out message-related tests
  2. The renderMessageField function implementation in voteDetailsModal.tsx
  3. No existing test file for voteDetailsModal.tsx

Add test coverage for message field rendering

The renderMessageField function handles complex rendering logic for different types of message fields (arrays, objects, strings) but lacks test coverage. Consider:

  • Creating a new test file voteDetailsModal.test.tsx
  • Adding test cases for:
    • Array type message fields
    • Object type message fields
    • String fields with address-like content
    • Regular string fields with truncation
🔗 Analysis chain

Line range hint 355-382: Add test coverage for message rendering

The renderMessageField function and its text styling changes lack test coverage. Consider adding unit tests for different message types and their rendering outcomes.


Let me gather more information about the test coverage and related components.


Let me try one more search with corrected file type flags:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find existing test files for this component
fd "voteDetailsModal.test" --type f

# Check for any existing message rendering tests
rg -A 5 "renderMessageField|test\(.*message" 

Length of output: 9395


Script:

#!/bin/bash
# Look for test files related to vote details or message rendering
fd "test.(tsx|ts)" --type f | rg -i "vote|message"

# Check for any existing test setup or utilities for modal testing
rg -A 5 "render.*Modal|Modal.*test" --type ts --type tsx

# Look for any existing snapshot tests
rg "toMatchSnapshot|snapshot" --type ts --type tsx

Length of output: 290


Script:

#!/bin/bash
# Look for modal test patterns and snapshots
rg -t typescript -t typescriptreact -A 5 "render.*Modal|Modal.*test"

# Check for any existing test utilities or helpers
fd "test-utils|testing" --type f

# Look for similar components with tests
rg -t typescript -t typescriptreact "describe.*Modal.*|test.*Modal.*" -A 5

Length of output: 252

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 376-376: components/groups/modals/voteDetailsModal.tsx#L376
Added line #L376 was not covered by tests


[warning] 380-382: components/groups/modals/voteDetailsModal.tsx#L380-L382
Added lines #L380 - L382 were not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1c22999 and 8901001.

📒 Files selected for processing (1)
  • components/groups/modals/voteDetailsModal.tsx (10 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
components/groups/modals/voteDetailsModal.tsx

[warning] 355-355: components/groups/modals/voteDetailsModal.tsx#L355
Added line #L355 was not covered by tests


[warning] 357-357: components/groups/modals/voteDetailsModal.tsx#L357
Added line #L357 was not covered by tests


[warning] 366-366: components/groups/modals/voteDetailsModal.tsx#L366
Added line #L366 was not covered by tests


[warning] 376-376: components/groups/modals/voteDetailsModal.tsx#L376
Added line #L376 was not covered by tests


[warning] 380-382: components/groups/modals/voteDetailsModal.tsx#L380-L382
Added lines #L380 - L382 were not covered by tests


[warning] 463-465: components/groups/modals/voteDetailsModal.tsx#L463-L465
Added lines #L463 - L465 were not covered by tests


[warning] 469-469: components/groups/modals/voteDetailsModal.tsx#L469
Added line #L469 was not covered by tests


[warning] 476-477: components/groups/modals/voteDetailsModal.tsx#L476-L477
Added lines #L476 - L477 were not covered by tests


[warning] 481-482: components/groups/modals/voteDetailsModal.tsx#L481-L482
Added lines #L481 - L482 were not covered by tests


[warning] 489-489: components/groups/modals/voteDetailsModal.tsx#L489
Added line #L489 was not covered by tests


[warning] 511-511: components/groups/modals/voteDetailsModal.tsx#L511
Added line #L511 was not covered by tests


[warning] 517-518: components/groups/modals/voteDetailsModal.tsx#L517-L518
Added lines #L517 - L518 were not covered by tests


[warning] 520-520: components/groups/modals/voteDetailsModal.tsx#L520
Added line #L520 was not covered by tests


[warning] 522-524: components/groups/modals/voteDetailsModal.tsx#L522-L524
Added lines #L522 - L524 were not covered by tests


[warning] 528-528: components/groups/modals/voteDetailsModal.tsx#L528
Added line #L528 was not covered by tests


[warning] 531-533: components/groups/modals/voteDetailsModal.tsx#L531-L533
Added lines #L531 - L533 were not covered by tests

🔇 Additional comments (2)
components/groups/modals/voteDetailsModal.tsx (2)

424-428: Previous review comment about modal positioning is still applicable


520-534: LGTM: Table styling follows theme guidelines

The table header styling properly uses theme-aware classes for text colors and maintains consistency.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 520-520: components/groups/modals/voteDetailsModal.tsx#L520
Added line #L520 was not covered by tests


[warning] 522-524: components/groups/modals/voteDetailsModal.tsx#L522-L524
Added lines #L522 - L524 were not covered by tests


[warning] 528-528: components/groups/modals/voteDetailsModal.tsx#L528
Added line #L528 was not covered by tests


[warning] 531-533: components/groups/modals/voteDetailsModal.tsx#L531-L533
Added lines #L531 - L533 were not covered by tests

@@ -66,7 +66,7 @@

const { theme } = useTheme();

const textColor = theme === 'dark' ? '#E0D1D4' : '#2e2e2e';
const textColor = theme === 'dark' ? '#FFFFFF' : '#161616';
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use theme variables instead of hardcoded colors

The hardcoded colors bypass the theme system. Consider using Tailwind's theme variables for better maintainability and consistency.

- const textColor = theme === 'dark' ? '#FFFFFF' : '#161616';
+ const textColor = theme === 'dark' ? 'rgb(var(--color-neutral-content))' : 'rgb(var(--color-base-content))';

// ...

- colors: ['#4CAF50', '#E53935', '#FFB300', '#3F51B5'],
+ colors: ['rgb(var(--color-success))', 'rgb(var(--color-error))', 'rgb(var(--color-warning))', 'rgb(var(--color-info))'],

Also applies to: 188-188

Comment on lines +463 to +489
<h1 className="text-2xl font-bold max-w-[20ch] truncate text-primary-content">
{proposal?.title}
</h1>
<span className="text-sm font-light text-gray-500 dark:text-gray-400 mt-2">
SUBMITTED
</span>
<span className="text-sm">
<span className="text-sm text-primary-content">
{new Date(proposal?.submit_time).toDateString().toLocaleString()}
</span>
</div>
<div className="divider my-"></div>
<div className="w-full">
<p className="text-sm font-light text-gray-500 dark:text-gray-400 mb-2 ">SUMMARY</p>
<div className="dark:bg-[#FFFFFF0F] bg-[#0000000A] rounded-[12px] p-4">
<p className="text-sm">{proposal?.summary}</p>
<div className="bg-base-300 rounded-[12px] p-4">
<p className="text-sm text-primary-content">{proposal?.summary}</p>
</div>
</div>
<div className="w-full">
<p className="text-sm font-light text-gray-500 dark:text-gray-400 mb-2 ">MESSAGES</p>
<div className="dark:bg-[#FFFFFF0F] bg-[#0000000A] rounded-[12px] p-4 overflow-y-auto max-h-[20rem]">
<p className="text-sm font-light text-gray-500 dark:text-gray-400 mb-2">MESSAGES</p>
<div className="bg-base-300 rounded-[12px] p-4 overflow-y-auto max-h-[20rem]">
{proposal?.messages?.map((message: any, index: number) => {
const messageType = message['@type'];
const fieldsToShow = importantFields[messageType] || defaultFields;

return (
<div key={index} className="mb-4">
<h3 className="text-lg font-semibold mb-2">
<h3 className="text-lg font-semibold mb-2 text-primary-content">
Copy link

@coderabbitai coderabbitai bot Nov 15, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Implement comprehensive UI test coverage

Multiple UI elements lack test coverage. Consider implementing:

  1. Snapshot tests for theme variations
  2. Unit tests for conditional rendering
  3. Integration tests for user interactions

This will help ensure theme and layout changes don't introduce regressions.

Would you like me to help create a test suite template that covers these scenarios?

Also applies to: 511-534

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 463-465: components/groups/modals/voteDetailsModal.tsx#L463-L465
Added lines #L463 - L465 were not covered by tests


[warning] 469-469: components/groups/modals/voteDetailsModal.tsx#L469
Added line #L469 was not covered by tests


[warning] 476-477: components/groups/modals/voteDetailsModal.tsx#L476-L477
Added lines #L476 - L477 were not covered by tests


[warning] 481-482: components/groups/modals/voteDetailsModal.tsx#L481-L482
Added lines #L481 - L482 were not covered by tests


[warning] 489-489: components/groups/modals/voteDetailsModal.tsx#L489
Added line #L489 was not covered by tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, write some tests.

Copy link

Choose a reason for hiding this comment

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

@fmorency, sure! Here's a test suite for the VoteDetailsModal component that covers snapshot tests for theme variations, unit tests for conditional rendering, and placeholders for integration tests of user interactions:

// File: components/groups/modals/__tests__/voteDetailsModal.test.tsx

import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import VoteDetailsModal from '../voteDetailsModal';
import { ChainProvider } from '@/contexts/chain';
import { ProposalSDKType, MemberSDKType, VoteSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/group/v1/types';
import { QueryTallyResultResponseSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/group/v1/query';

describe('VoteDetailsModal Component Tests', () => {
  const mockProposal: ProposalSDKType = {
    id: BigInt(1),
    address: 'cosmos1address',
    proposers: ['cosmos1proposer'],
    submit_time: '2023-11-10T00:00:00Z',
    voting_period_end: '2023-11-11T00:00:00Z',
    status: 'PROPOSAL_STATUS_SUBMITTED',
    executor_result: 'PROPOSAL_EXECUTOR_RESULT_NOT_RUN',
    title: 'Test Proposal Title',
    summary: 'This is a test summary for the proposal.',
    messages: [
      {
        '@type': '/cosmos.bank.v1beta1.MsgSend',
        from_address: 'cosmos1from',
        to_address: 'cosmos1to',
        amount: [{ denom: 'uatom', amount: '1000' }],
      },
    ],
  };

  const mockTally: QueryTallyResultResponseSDKType = {
    tally: {
      yes_count: '10',
      abstain_count: '2',
      no_count: '3',
      no_with_veto_count: '1',
    },
  };

  const mockVotes: VoteSDKType[] = [
    {
      proposal_id: BigInt(1),
      voter: 'cosmos1voter1',
      option: 'VOTE_OPTION_YES',
      metadata: '',
      submit_time: '',
    },
    // Add more mock votes as needed
  ];

  const mockMembers: MemberSDKType[] = [
    {
      address: 'cosmos1member1',
      weight: '1',
      metadata: '',
    },
    // Add more mock members as needed
  ];

  const defaultProps = {
    tallies: mockTally,
    votes: mockVotes,
    members: mockMembers,
    proposal: mockProposal,
    onClose: jest.fn(),
    modalId: 'voteDetailsModal',
    refetchVotes: jest.fn(),
    refetchTally: jest.fn(),
    refetchProposals: jest.fn(),
  };

  const renderComponent = (props = {}) => {
    return render(
      <ChainProvider>
        <VoteDetailsModal {...defaultProps} {...props} />
      </ChainProvider>
    );
  };

  test('renders the component with provided props', () => {
    renderComponent();
    expect(screen.getByText(`#${mockProposal.id.toString()}`)).toBeInTheDocument();
    expect(screen.getByText(mockProposal.title)).toBeInTheDocument();
    expect(screen.getByText('SUMMARY')).toBeInTheDocument();
    expect(screen.getByText(mockProposal.summary)).toBeInTheDocument();
  });

  test('renders the tally chart', () => {
    renderComponent();
    expect(screen.getByText('TALLY')).toBeInTheDocument();
    // Additional checks can be implemented based on how the chart renders
  });

  test('renders voting countdown timer', () => {
    renderComponent();
    expect(screen.getByText('VOTING COUNTDOWN')).toBeInTheDocument();
  });

  test('renders messages section with correct data', () => {
    renderComponent();
    expect(screen.getByText('MESSAGES')).toBeInTheDocument();
    expect(screen.getByText('MsgSend')).toBeInTheDocument();
    expect(screen.getByText('from_address:')).toBeInTheDocument();
    expect(screen.getByText('to_address:')).toBeInTheDocument();
  });

  test('conditionally renders execute button when proposal is accepted', () => {
    renderComponent({
      proposal: { ...mockProposal, status: 'PROPOSAL_STATUS_ACCEPTED' },
    });
    expect(screen.getByText('Execute')).toBeInTheDocument();
  });

  test('conditionally renders vote button when proposal is open and user has not voted', () => {
    renderComponent();
    expect(screen.getByText('Vote')).toBeInTheDocument();
  });

  test('does not render vote button when user has already voted', () => {
    renderComponent({
      votes: [{ ...mockVotes[0], voter: 'cosmos1address' }], // Assuming cosmos1address is the current user
    });
    expect(screen.queryByText('Vote')).not.toBeInTheDocument();
  });

  test('handles vote button click and opens voting modal', () => {
    renderComponent();
    const voteButton = screen.getByText('Vote');
    fireEvent.click(voteButton);
    expect(document.getElementById('vote_modal')).toBeVisible();
  });

  test('handles execute button click', () => {
    // Implement test logic for execute action
  });

  test('matches snapshot for light theme', () => {
    renderComponent();
    expect(screen.baseElement).toMatchSnapshot();
  });

  test('matches snapshot for dark theme', () => {
    // Assuming a ThemeProvider or context to change the theme
    renderComponent();
    expect(screen.baseElement).toMatchSnapshot();
  });
});

This test suite includes:

  • Snapshot Tests: Ensuring the component's render output matches the expected snapshots for both light and dark themes.
  • Unit Tests for Conditional Rendering: Testing the visibility of buttons and sections based on different proposal statuses and user actions.
  • Integration Tests Placeholders: Places where you can implement tests for user interactions like executing a proposal or voting.

These tests will help ensure that theme and layout changes don't introduce regressions.

Let me know if you need any further assistance or additional tests!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will integrate those in a future PR.

Copy link

Choose a reason for hiding this comment

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

@fmorency, understood. Would you like me to open a GitHub issue to track adding the tests in a future PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

Copy link

Choose a reason for hiding this comment

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

@fmorency, I've opened a GitHub issue to track adding tests for the VoteDetailsModal component as discussed:

Issue #47

This will help ensure that theme and layout changes don't introduce regressions in the future.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Create a GitHub issue to track adding tests for VoteDetailsModal component
gh issue create \
  --title "Add tests for VoteDetailsModal component" \
  --body "As per the discussion in [PR #41](https://github.com/liftedinit/manifest-app/pull/41), we should add a test suite for the `VoteDetailsModal` component to cover snapshot tests for theme variations, unit tests for conditional rendering, and integration tests for user interactions.

Refer to the code review comment: https://github.com/liftedinit/manifest-app/pull/41#discussion_r1843838029

Requested by: @fmorency" \
  --assignee "fmorency"

Length of output: 650

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Félix C. Morency <[email protected]>
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: 0

🧹 Outside diff range and nitpick comments (2)
components/groups/components/myGroups.tsx (2)

124-152: Add test coverage for skeleton loading state

The skeleton loading implementation looks good, but test coverage is missing for this section.

Would you like me to help generate test cases for the skeleton loading state? This should include:

  • Verifying skeleton renders when isLoading is true
  • Checking correct number of skeleton rows
  • Validating skeleton styling classes
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 126-150: components/groups/components/myGroups.tsx#L126-L150
Added lines #L126 - L150 were not covered by tests


Line range hint 227-238: Enhance keyboard accessibility

While the styling improvements look good, consider adding keyboard accessibility for better user experience.

    <tr
      className="group text-black dark:text-white rounded-lg cursor-pointer transition-colors"
+     role="button"
+     tabIndex={0}
+     onKeyDown={(e) => {
+       if (e.key === 'Enter' || e.key === ' ') {
+         e.preventDefault();
+         onSelectGroup(
+           policyAddress,
+           groupName,
+           (group.policies &&
+             (group.policies[0]?.decision_policy as ThresholdDecisionPolicySDKType)?.threshold) ??
+             '0'
+         );
+       }
+     }}
      onClick={e => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8901001 and 16c9c64.

📒 Files selected for processing (1)
  • components/groups/components/myGroups.tsx (5 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
components/groups/components/myGroups.tsx

[warning] 126-150: components/groups/components/myGroups.tsx#L126-L150
Added lines #L126 - L150 were not covered by tests

🔇 Additional comments (3)
components/groups/components/myGroups.tsx (3)

Line range hint 86-95: LGTM: Theme-consistent styling applied

The updated styling for the title and search input properly utilizes theme colors, ensuring visibility in both dark and light modes.


112-122: Skip comment about column width inconsistency


247-249: LGTM: Improved badge visibility

The badge styling now properly uses theme colors for better visibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mislocated proposal search box Hard to see elements in light theme
1 participant