Skip to content

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

chore: fix failing tests

TzeYiing9232ae4dfdac
diff --git a/studio/components/interfaces/Settings/Logs/LogSelection.tsx b/studio/components/interfaces/Settings/Logs/LogSelection.tsx
index 151321c8311..2ca573e4e36 100644
--- a/studio/components/interfaces/Settings/Logs/LogSelection.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogSelection.tsx
@@ -45,10 +45,13 @@ const LogSelection: FC<Props> = ({ projectRef, log: partialLog, onClose, queryTy
return <FunctionLogsSelectionRender log={fullLog} />
default:
- if (fullLog && isDefaultLogPreviewFormat(fullLog)) {
+ if (queryType && fullLog && isDefaultLogPreviewFormat(fullLog)) {
return <DefaultPreviewSelectionRenderer log={fullLog} />
}
-
+ if (queryType && !fullLog) {
+ return null
+ }
+ if (!partialLog) return null
return <DefaultExplorerSelectionRenderer log={partialLog} />
}
}
@@ -128,7 +131,7 @@ const LogSelection: FC<Props> = ({ projectRef, log: partialLog, onClose, queryTy
</div>
{isLoading && <Connecting />}
<div className="bg-scale-300 py-8 flex flex-col space-y-6">
- {!isLoading && fullLog && <Formatter />}
+ {!isLoading && <Formatter />}
</div>
</div>
</div>
diff --git a/studio/hooks/analytics/useLogsPreview.tsx b/studio/hooks/analytics/useLogsPreview.tsx
index 9e135c91906..d22fa934c6c 100644
--- a/studio/hooks/analytics/useLogsPreview.tsx
+++ b/studio/hooks/analytics/useLogsPreview.tsx
@@ -145,7 +145,6 @@ function useLogsPreview(
setFilters((prev) => ({ ...prev, ...newFilters, ...filterOverride }))
}
}
- console.log(logData)
return [
{
newCount,
diff --git a/studio/tests/pages/projects/LogTable.test.js b/studio/tests/pages/projects/LogTable.test.js
index 4b2dd8a53a2..1f921cbc82c 100644
--- a/studio/tests/pages/projects/LogTable.test.js
+++ b/studio/tests/pages/projects/LogTable.test.js
@@ -1,6 +1,7 @@
import LogTable from 'components/interfaces/Settings/Logs/LogTable'
import { render, waitFor, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
+
test('can display log data', async () => {
render(
<LogTable
@@ -19,8 +20,8 @@ test('can display log data', async () => {
const row = await screen.findByText(/some-uuid/)
userEvent.click(row)
- await waitFor(() => screen.getByText(/my_key/))
- await waitFor(() => screen.getByText(/something_value/))
+ await screen.findByText(/my_key/)
+ await screen.findByText(/something_value/)
})
test('dedupes log lines with exact id', async () => {
diff --git a/studio/tests/pages/projects/LogsPreviewer.test.js b/studio/tests/pages/projects/LogsPreviewer.test.js
index ab7bd5b7527..0a782814390 100644
--- a/studio/tests/pages/projects/LogsPreviewer.test.js
+++ b/studio/tests/pages/projects/LogsPreviewer.test.js
@@ -82,57 +82,58 @@ beforeEach(() => {
useRouter.mockReset()
useRouter.mockReturnValue(defaultRouterMock())
})
-test('can display log data and metadata', async () => {
- get.mockResolvedValue({
- result: [
- logDataFixture({
- id: 'some-event-happened-id',
- metadata: {
- my_key: 'something_value',
- },
- }),
- ],
- })
- render(<LogsPreviewer projectRef="123" tableName={LogsTableName.EDGE} />)
-
- await waitFor(() => {
- expect(get).toHaveBeenCalledWith(expect.stringContaining('iso_timestamp_start'))
- expect(get).not.toHaveBeenCalledWith(expect.stringContaining('iso_timestamp_end'))
- })
- fireEvent.click(await screen.findByText(/some-event-happened-id/))
- await screen.findByText(/my_key/)
- await screen.findByText(/something_value/)
-})
-
-test('Refresh page', async () => {
- get.mockImplementation((url) => {
- if (url.includes('count')) return { result: { count: 0 } }
- if (url.includes('where+id')) {
- return {
- result: [
- {
- id: 'some-id',
- metadata: [{ request: [{ method: 'POST' }] }],
- },
- ],
+test.each([
+ {
+ queryType: 'api',
+ tableName: undefined,
+ allLog: logDataFixture({
+ id: 'some-id',
+ request: { path: 'some-path', method: 'POST' },
+ status_code: '400',
+ metadata: undefined,
+ }),
+ singleLog: {
+ id: 'some-id',
+ metadata: [{ request: [{ method: 'POST' }] }],
+ },
+ tableTexts: [/POST/, /some\-path/, /400/],
+ selectionTexts: [/POST/],
+ },
+ // TODO: add more tests for each type of ui
+])(
+ 'selection $queryType $tableName , can display log data and metadata',
+ async ({ queryType, tableName, allLog, singleLog, tableTexts, selectionTexts }) => {
+ get.mockImplementation((url) => {
+ // counts
+ if (url.includes('count')) {
+ return { result: [{ count: 0 }] }
}
+ // single
+ if (url.includes('where+id')) {
+ return { result: [singleLog] }
+ }
+ // all
+ return { result: [allLog] }
+ })
+ render(<LogsPreviewer projectRef="123" queryType={queryType} tableName={tableName} />)
+
+ await waitFor(() => {
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('iso_timestamp_start'))
+ expect(get).not.toHaveBeenCalledWith(expect.stringContaining('iso_timestamp_end'))
+ })
+
+ for (const text of tableTexts) {
+ await screen.findByText(text)
}
- return {
- result: [
- logDataFixture({
- id: 'some-id',
- request: { path: 'some-event' },
- }),
- ],
- }
- })
- render(<LogsPreviewer projectRef="123" queryType="api" tableName={LogsTableName.EDGE} />)
+ const row = await screen.findByText(tableTexts[0])
+ fireEvent.click(row)
- const row = await screen.findByText(/some-event/)
- fireEvent.click(row)
- await screen.findAllByText(/POST/)
-})
+ for (const text of selectionTexts) {
+ await screen.findAllByText(text)
+ }
+ }
+)
test('Search will trigger a log refresh', async () => {
get.mockImplementation((url) => {