Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

added failing tests

TzeYiing19fb675b1e98
diff --git a/studio/tests/components/Home/ProjectUsage.test.js b/studio/tests/components/Home/ProjectUsage.test.js
index 9864a387cd1..1e730775497 100644
--- a/studio/tests/components/Home/ProjectUsage.test.js
+++ b/studio/tests/components/Home/ProjectUsage.test.js
@@ -7,12 +7,13 @@ import { get } from 'lib/common/fetch'
jest.mock('next/router')
import { useRouter } from 'next/router'
import { clickDropdown } from 'tests/helpers'
-useRouter.mockReturnValue({ query: { ref: '123' } })
+const mockPush = jest.fn()
+useRouter.mockReturnValue({ query: { ref: '123' }, push: mockPush })
// need to wrap component with SWRConfig in order to clear cache between tests
// TODO: abstract out to global setup
import { SWRConfig } from 'swr'
-const ProjectUsage = jest.fn()
+const ProjectUsage = jest.fn()
ProjectUsage.mockImplementation((props) => {
const Original = jest.requireActual('components/interfaces/Home/ProjectUsage').default
// wrap with SWR to reset the cache each time
@@ -30,10 +31,9 @@ jest.mock('hooks')
import { useFlag } from 'hooks'
useFlag.mockReturnValue(true)
-
-
beforeEach(() => {
get.mockReset()
+ mockPush.mockReset()
})
const MOCK_CHART_DATA = {
@@ -71,7 +71,6 @@ test('mounts correctly', async () => {
test('dropdown options changes chart query', async () => {
get.mockImplementation((url) => {
- console.log(url)
if (url.includes('usage')) return {}
return { data: MOCK_CHART_DATA }
})
@@ -79,9 +78,8 @@ test('dropdown options changes chart query', async () => {
await waitFor(() => screen.getByText(/Statistics for past 60 minutes/))
await waitFor(() => screen.getAllByRole('button', { name: '60 minutes' }))
console.log(get.mock.calls)
- await waitFor(()=>{
+ await waitFor(() => {
expect(get).toHaveBeenCalledWith(expect.stringContaining('interval=minutely'))
-
})
// find button that has radix id
const [btn] = screen.getAllByRole('button', { name: '60 minutes' }).filter((e) => e.id)
@@ -93,5 +91,20 @@ test('dropdown options changes chart query', async () => {
userEvent.click(screen.getByText(/24 hours/))
await waitFor(() => screen.getByText(/Statistics for past 24 hours/))
expect(get).toHaveBeenCalledWith(expect.stringContaining('interval=hourly'))
+})
+test('chart navigation to logs', async () => {
+ get.mockImplementation((url) => {
+ if (url.includes('usage')) return {}
+ return { data: MOCK_CHART_DATA }
+ })
+ const { container } = render(<ProjectUsage project="12345" />)
+ // click on the log bar chart
+ const panel = (await screen.findByText(/API Requests/)).parentElement
+ const bar = panel.querySelector('path.recharts-rectangle')
-})
\ No newline at end of file
+ userEvent.click(bar)
+ expect(mockPush).toBeCalledTimes(1)
+ const viewLogsButton = getByText(panel, /View logs/)
+ userEvent.click(viewLogsButton)
+ expect(mockPush).toBeCalledTimes(2)
+})