-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d00f4a
commit 587af52
Showing
2 changed files
with
47 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ import React from 'react'; | |
import { Billing, BillingContract } from 'src/libs/ajax/billing/Billing'; | ||
import { AggregatedWorkspaceSpendData, SpendReport } from 'src/libs/ajax/billing/billing-models'; | ||
import { reportError } from 'src/libs/error'; | ||
import { spendReportStore } from 'src/libs/state'; | ||
import { getTerraUser, spendReportStore } from 'src/libs/state'; | ||
import { renderWithAppContexts } from 'src/testing/test-utils'; | ||
import { WorkspaceWrapper } from 'src/workspaces/utils'; | ||
|
||
|
@@ -31,6 +31,19 @@ jest.mock( | |
}) | ||
); | ||
|
||
type StateExports = typeof import('src/libs/state'); | ||
jest.mock( | ||
'src/libs/state', | ||
(): StateExports => ({ | ||
...jest.requireActual('src/libs/state'), | ||
getTerraUser: jest.fn(), | ||
}) | ||
); | ||
|
||
asMockedFn(getTerraUser).mockReturnValue({ | ||
email: '[email protected]', | ||
}); | ||
|
||
const spendReport: SpendReport = { | ||
spendSummary: { | ||
cost: '1.20', | ||
|
@@ -208,7 +221,7 @@ const workspaces = [ | |
billingAccount: 'billingAccounts/00102A-34B56C-78DEFB', | ||
bucketName: 'fc-01111a11-20b2-3033-4044-77c0c7c77777', | ||
cloudPlatform: 'Gcp', | ||
createdBy: 'user1@gmail.com', | ||
createdBy: 'user2@gmail.com', | ||
createdDate: '2024-08-10T13:50:36.984Z', | ||
googleProject: 'terra-dev-fe98dcb8', | ||
googleProjectNumber: '123045678090', | ||
|
@@ -312,6 +325,20 @@ describe('ConsolidatedSpendReport', () => { | |
expect(screen.getAllByText('N/A')).not.toBeNull(); | ||
}); | ||
|
||
it('filters to user-created workspaces', async () => { | ||
// Arrange | ||
const user = userEvent.setup(); | ||
getCrossBillingSpendReport.mockResolvedValue(spendReport); | ||
|
||
// Act | ||
await act(async () => renderWithAppContexts(<ConsolidatedSpendReport workspaces={workspaces} />)); | ||
await user.click(screen.getByLabelText('Only show workspaces created by me')); | ||
|
||
// Assert | ||
expect(screen.getByText('workspace2')).not.toBeNull(); | ||
expect(screen.queryByText('workspace3')).toBeNull(); | ||
}); | ||
|
||
it('displays a helpful error if the query fails', async () => { | ||
// Arrange | ||
const getCrossBillingSpendReport = jest.fn().mockRejectedValue(new Error('MyTestError')); | ||
|
This file contains 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