-
-
Notifications
You must be signed in to change notification settings - Fork 122
fix: keep repository metrics scoped to their organization #304
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
Open
YashAnand69
wants to merge
2
commits into
AOSSIE-Org:main
Choose a base branch
from
YashAnand69:fix/302-qualified-repository-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−7
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
| import { render, screen, within } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import AnalyticsPage from './AnalyticsPage' | ||
| import GovernancePage from './GovernancePage' | ||
|
|
||
| const { app } = vi.hoisted(() => ({ app: {} })) | ||
|
|
||
| vi.mock('../context/AppContext', () => ({ useApp: () => app })) | ||
|
|
||
| // Chart layout is not needed to exercise repository selection and its metrics. | ||
| vi.mock('recharts', () => { | ||
| const EmptyChart = () => null | ||
| return { | ||
| AreaChart: ({ data }) => <output data-testid="trend-series">{JSON.stringify(data)}</output>, | ||
| ResponsiveContainer: ({ children }) => <div>{children}</div>, | ||
| Area: EmptyChart, XAxis: EmptyChart, YAxis: EmptyChart, | ||
| CartesianGrid: EmptyChart, Tooltip: EmptyChart, Legend: EmptyChart, | ||
| PieChart: EmptyChart, Pie: EmptyChart, Cell: EmptyChart, | ||
| RadialBarChart: EmptyChart, RadialBar: EmptyChart, PolarAngleAxis: EmptyChart, | ||
| } | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| Object.assign(app, { | ||
| model: { | ||
| allRepos: [ | ||
| { id: 1, name: 'docs', orgLogin: 'first-org', license: { key: 'mit' } }, | ||
| { id: 2, name: 'docs', orgLogin: 'second-org', license: { key: 'mit' } }, | ||
| { id: 3, name: 'docs', orgLogin: 'uncached-org', license: { key: 'mit' } }, | ||
| ], | ||
| }, | ||
| issuesData: { | ||
| 'first-org/docs': [{ id: 1, state: 'closed', created_at: '2026-01-01T00:00:00Z' }], | ||
| 'second-org/docs': [{ id: 2, state: 'open', created_at: '2026-02-01T00:00:00Z' }], | ||
| }, | ||
| pullsData: { | ||
| 'first-org/docs': [{ state: 'closed', created_at: '2026-01-01T00:00:00Z', merged_at: '2026-01-03T00:00:00Z' }], | ||
| 'second-org/docs': [{ state: 'closed', created_at: '2026-02-01T00:00:00Z', merged_at: null }], | ||
| }, | ||
| staleRepoStats: [], | ||
| loading: false, | ||
| govLoading: false, | ||
| advanceAnalyticsLoading: false, | ||
| auditComplete: true, | ||
| advanceAnalyticsComplete: true, | ||
| pat: '', | ||
| }) | ||
| }) | ||
|
|
||
| describe('repository metrics across organizations', () => { | ||
| it('selects each same-name repository independently in activity trends', async () => { | ||
| const user = userEvent.setup() | ||
| render(<AnalyticsPage />) | ||
| const selector = screen.getAllByRole('combobox')[0] | ||
|
|
||
| expect(within(selector).getAllByRole('option').map(option => option.value)) | ||
| .toEqual(['All', 'first-org/docs', 'second-org/docs']) | ||
|
|
||
| for (const [repo, month] of [['first-org/docs', '2026-01'], ['second-org/docs', '2026-02']]) { | ||
| await user.selectOptions(selector, repo) | ||
| const series = JSON.parse(screen.getAllByTestId('trend-series')[0].textContent) | ||
| expect(series).toHaveLength(1) | ||
| expect(series[0]).toMatchObject({ date: month, issues_created: 1 }) | ||
| } | ||
|
|
||
| await user.selectOptions(selector, 'All') | ||
| expect(JSON.parse(screen.getAllByTestId('trend-series')[0].textContent)).toHaveLength(2) | ||
| }) | ||
|
|
||
| it('uses the selected organization for advanced pull request metrics', async () => { | ||
| const user = userEvent.setup() | ||
| render(<AnalyticsPage />) | ||
| const selector = screen.getAllByRole('combobox')[1] | ||
|
|
||
| expect(within(selector).getAllByRole('option').map(option => option.value)) | ||
| .toEqual(['All Repositories', 'first-org/docs', 'second-org/docs']) | ||
|
|
||
| await user.selectOptions(selector, 'first-org/docs') | ||
| expect(screen.getByText('Based on', { exact: false })).toHaveTextContent('1 merged pull requests') | ||
| await user.selectOptions(selector, 'second-org/docs') | ||
| expect(screen.getByText('Based on', { exact: false })).toHaveTextContent('0 merged pull requests') | ||
| await user.selectOptions(selector, 'All Repositories') | ||
| expect(screen.getByText('Based on', { exact: false })).toHaveTextContent('1 merged pull requests') | ||
| expect(screen.getByText((_, element) => element?.textContent === '1 merged · 1 rejected')) | ||
| .toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('keeps resolution rates and missing audit data scoped to their organization', () => { | ||
| render(<GovernancePage />) | ||
|
|
||
| for (const [org, rate] of [['first-org', '100%'], ['second-org', '0%'], ['uncached-org', 'No data']]) { | ||
| const row = screen.getByText(org).parentElement.parentElement | ||
| expect(within(row).getByText(rate)).toBeInTheDocument() | ||
| } | ||
| }) | ||
| }) | ||
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.