-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add general compare mode #146
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5ce2de0
feat: add general compare mode
ccf d93e3bd
fix: allow team leads to compare against their team
ccf 2f0e52a
fix: tighten compare mode authorization
ccf 3708419
fix: tighten compare mode boundaries
ccf 4b9b5d5
fix: cap engineer workflow compare entries
ccf 5aeda74
fix: harden compare mode validation
ccf 73b0e77
fix: reject ambiguous numeric percent values
ccf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { fireEvent, render, screen } from "@testing-library/react" | ||
| import { beforeEach, describe, expect, it, vi } from "vitest" | ||
|
|
||
| vi.mock("@/hooks/use-api-queries", () => ({ | ||
| useTeams: vi.fn(), | ||
| useEngineers: vi.fn(), | ||
| useProjectAnalytics: vi.fn(), | ||
| useCompareAnalytics: vi.fn(), | ||
| })) | ||
|
|
||
| import { | ||
| useCompareAnalytics, | ||
| useEngineers, | ||
| useProjectAnalytics, | ||
| useTeams, | ||
| } from "@/hooks/use-api-queries" | ||
| import { ComparePage } from "../compare" | ||
|
|
||
| const mockUseTeams = vi.mocked(useTeams) | ||
| const mockUseEngineers = vi.mocked(useEngineers) | ||
| const mockUseProjectAnalytics = vi.mocked(useProjectAnalytics) | ||
| const mockUseCompareAnalytics = vi.mocked(useCompareAnalytics) | ||
|
|
||
| describe("ComparePage", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockUseTeams.mockReturnValue({ | ||
| data: [ | ||
| { id: "team-1", name: "Alpha" }, | ||
| { id: "team-2", name: "Beta" }, | ||
| ], | ||
| isLoading: false, | ||
| } as never) | ||
| mockUseEngineers.mockReturnValue({ | ||
| data: [ | ||
| { id: "eng-1", name: "Alice", display_name: "Alice", team_id: "team-1" }, | ||
| { id: "eng-2", name: "Bob", display_name: "Bob", team_id: "team-2" }, | ||
| ], | ||
| isLoading: false, | ||
| } as never) | ||
| mockUseProjectAnalytics.mockReturnValue({ | ||
| data: { | ||
| total_count: 2, | ||
| projects: [ | ||
| { project_name: "alpha-app" }, | ||
| { project_name: "beta-app" }, | ||
| ], | ||
| }, | ||
| isLoading: false, | ||
| } as never) | ||
| mockUseCompareAnalytics.mockReturnValue({ | ||
| data: { | ||
| mode: "team", | ||
| left: { | ||
| label: "Alpha", | ||
| total_sessions: 12, | ||
| success_rate: 0.75, | ||
| total_cost: 12.4, | ||
| avg_cost_per_session: 1.03, | ||
| cost_per_successful_outcome: 1.4, | ||
| pr_merge_rate: 0.8, | ||
| findings_fix_rate: 0.7, | ||
| effectiveness_score: 82.1, | ||
| leverage_score: 74.6, | ||
| top_workflows: [ | ||
| { label: "debugging", session_count: 5, share_of_sessions: 0.42 }, | ||
| ], | ||
| }, | ||
| right: { | ||
| label: "Beta", | ||
| total_sessions: 8, | ||
| success_rate: 0.5, | ||
| total_cost: 10.4, | ||
| avg_cost_per_session: 1.3, | ||
| cost_per_successful_outcome: 2.1, | ||
| pr_merge_rate: 0.55, | ||
| findings_fix_rate: 0.5, | ||
| effectiveness_score: 61.4, | ||
| leverage_score: 58.2, | ||
| top_workflows: [ | ||
| { label: "implementation", session_count: 3, share_of_sessions: 0.38 }, | ||
| ], | ||
| }, | ||
| delta: { | ||
| total_sessions: 4, | ||
| success_rate: 0.25, | ||
| total_cost: 2.0, | ||
| avg_cost_per_session: -0.27, | ||
| cost_per_successful_outcome: -0.7, | ||
| pr_merge_rate: 0.25, | ||
| findings_fix_rate: 0.2, | ||
| effectiveness_score: 20.7, | ||
| leverage_score: 16.4, | ||
| }, | ||
| }, | ||
| isLoading: false, | ||
| } as never) | ||
| }) | ||
|
|
||
| it("renders compare mode snapshots and supports switching modes", () => { | ||
| render(<ComparePage teamId={null} dateRange={null} />) | ||
|
|
||
| expect(screen.getByText("Compare")).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByText("Selected period vs previous period"), | ||
| ).not.toBeInTheDocument() | ||
| expect(screen.getAllByText("Alpha").length).toBeGreaterThan(0) | ||
| expect(screen.getAllByText("Beta").length).toBeGreaterThan(0) | ||
| expect(screen.getAllByText("Top Workflows").length).toBeGreaterThan(0) | ||
|
|
||
| fireEvent.click(screen.getByRole("button", { name: "Periods" })) | ||
| expect(screen.getByText("Selected period vs previous period")).toBeInTheDocument() | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.