-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: MANAGER-15918 Signed-off-by: Romain Jamet <[email protected]>
- Loading branch information
Romain Jamet
committed
Dec 18, 2024
1 parent
a77538a
commit 9e4bd09
Showing
36 changed files
with
1,086 additions
and
56 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
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
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
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
54 changes: 54 additions & 0 deletions
54
packages/manager/modules/logs-to-customer/src/components/logTail/LogTail.component.tsx
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useContext } from 'react'; | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { OsdsSpinner } from '@ovhcloud/ods-components/react'; | ||
import { LogsContext } from '../../LogsToCustomer.context'; | ||
import ApiError from '../apiError/ApiError.component'; | ||
import { | ||
getLogTailUrlQueryKey, | ||
useLogTailUrl, | ||
} from '../../data/hooks/useLogTailUrl'; | ||
import { LogMessages } from './logMessages/LogMessages.component'; | ||
import './logTail.css'; | ||
|
||
export default function LogTail() { | ||
const { currentLogKind, logApiUrls, logApiVersion } = useContext(LogsContext); | ||
const queryClient = useQueryClient(); | ||
|
||
const { data, error, isPending } = useLogTailUrl({ | ||
logTailUrl: logApiUrls.logUrl, | ||
logKind: currentLogKind?.name, | ||
apiVersion: logApiVersion, | ||
}); | ||
|
||
if (isPending || error) { | ||
return ( | ||
<div | ||
className={`h-[--tail-height] bg-slate-800 text-gray-200 flex items-center justify-center`} | ||
> | ||
{isPending && ( | ||
<OsdsSpinner inline contrasted data-testid="logTail-spinner" /> | ||
)} | ||
{error && ( | ||
<ApiError | ||
testId="logTail-error" | ||
error={error} | ||
onRetry={() => | ||
queryClient.refetchQueries({ | ||
queryKey: getLogTailUrlQueryKey({ | ||
logKind: currentLogKind.name, | ||
logTailUrl: logApiUrls.logUrl, | ||
}), | ||
}) | ||
} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className={`h-[--tail-height] bg-slate-800 text-slate-300`}> | ||
{<LogMessages logTailMessageUrl={data.url} />} | ||
</div> | ||
); | ||
} |
151 changes: 151 additions & 0 deletions
151
packages/manager/modules/logs-to-customer/src/components/logTail/LogTail.spec.tsx
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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { renderTest } from '../../test-utils'; | ||
import { logMessagesMock } from '../../data/mocks/logMessage.mock'; | ||
|
||
const IntersectionObserverMock = vi.fn(() => ({ | ||
disconnect: vi.fn(), | ||
observe: vi.fn(), | ||
takeRecords: vi.fn(), | ||
unobserve: vi.fn(), | ||
})); | ||
|
||
vi.stubGlobal('IntersectionObserver', IntersectionObserverMock); | ||
|
||
const getDOMRect = (width: number, height: number) => ({ | ||
width, | ||
height, | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
x: 0, | ||
y: 0, | ||
toJSON: () => {}, | ||
}); | ||
|
||
beforeEach(() => { | ||
Element.prototype.getBoundingClientRect = vi.fn(function test() { | ||
if (this.getAttribute('data-testid') === 'logTail-listContainer') { | ||
return getDOMRect(1000, 800); | ||
} | ||
return getDOMRect(500, 20); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
Element.prototype.getBoundingClientRect = vi.fn(function test() { | ||
return getDOMRect(0, 0); | ||
}); | ||
}); | ||
|
||
describe('LogTail test suite', () => { | ||
it('should display an error if /log/url api is KO', async () => { | ||
await renderTest({ isLogTailUrlKO: true }); | ||
|
||
await waitFor( | ||
() => expect(screen.getByTestId('logTail-error')).toBeVisible(), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
}); | ||
|
||
it('should render a loading state when the api request is pending', async () => { | ||
await renderTest(); | ||
|
||
await waitFor( | ||
() => expect(screen.getByTestId('logTail-spinner')).toBeVisible(), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
|
||
await waitFor( | ||
() => expect(screen.getByTestId('logTail-searchInput')).toBeVisible(), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
}); | ||
|
||
it('should render LogMessage component', async () => { | ||
await renderTest(); | ||
|
||
await waitFor( | ||
() => expect(screen.getByTestId('logTail-searchInput')).toBeVisible(), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
expect(screen.getByTestId('logTail-togglePolling')).toBeVisible(); | ||
expect(screen.getByTestId('logTail-clearSession')).toBeVisible(); | ||
}); | ||
|
||
it('should display messages', async () => { | ||
await renderTest(); | ||
|
||
await waitFor( | ||
() => expect(screen.getByText(logMessagesMock[0].message)).toBeVisible(), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
|
||
expect(screen.queryAllByTestId('logTail-item')).toHaveLength( | ||
logMessagesMock.length, | ||
); | ||
}); | ||
|
||
it('should display waiting message on polling', async () => { | ||
const user = userEvent.setup(); | ||
await renderTest(); | ||
|
||
await waitFor( | ||
() => expect(screen.getByText(logMessagesMock[0].message)).toBeVisible(), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
|
||
expect(screen.getByTestId('logTail-polling')).toBeVisible(); | ||
|
||
await user.click(screen.getByTestId('logTail-togglePolling')); | ||
|
||
expect(screen.queryAllByTestId('logTail-polling')).toHaveLength(0); | ||
}); | ||
|
||
it('should display error message on API error', async () => { | ||
await renderTest({ isLogMessagesKO: true }); | ||
|
||
await waitFor( | ||
() => expect(screen.getByTestId('logTail-message-error')).toBeVisible(), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
}); | ||
|
||
it('should clear the list on click on clear session', async () => { | ||
const user = userEvent.setup(); | ||
await renderTest(); | ||
|
||
await waitFor( | ||
() => expect(screen.getByText(logMessagesMock[0].message)).toBeVisible(), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
|
||
await user.click(screen.getByTestId('logTail-togglePolling')); | ||
await user.click(screen.getByTestId('logTail-clearSession')); | ||
|
||
await waitFor( | ||
() => expect(screen.queryAllByTestId('logTail-item')).toHaveLength(0), | ||
{ | ||
timeout: 10_000, | ||
}, | ||
); | ||
}); | ||
}); |
20 changes: 0 additions & 20 deletions
20
packages/manager/modules/logs-to-customer/src/components/logTail/LogTail.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.