From 34df1fc6fb9132ad48b31a817e2870eeb924a51b Mon Sep 17 00:00:00 2001 From: Gabriel Corado Date: Mon, 16 Dec 2024 13:42:08 -0300 Subject: [PATCH] refactor(web): code review suggestions --- .../Console/DocumentDb/DocumentDb.test.tsx | 88 +++++++++---------- .../Console/DocumentSsh/Terminal/Terminal.tsx | 2 +- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/web/packages/teleport/src/Console/DocumentDb/DocumentDb.test.tsx b/web/packages/teleport/src/Console/DocumentDb/DocumentDb.test.tsx index e9870cc89f3d9..24973bd8e1bd8 100644 --- a/web/packages/teleport/src/Console/DocumentDb/DocumentDb.test.tsx +++ b/web/packages/teleport/src/Console/DocumentDb/DocumentDb.test.tsx @@ -44,59 +44,57 @@ const mockUseDbSession = useDbSession as jest.MockedFunction< typeof useDbSession >; -describe('DocumentDb', () => { - const setup = (status: Status) => { - mockUseDbSession.mockReturnValue({ - tty: { - sendDbConnectData: jest.fn(), - on: jest.fn(), - removeListener: jest.fn(), - connect: jest.fn(), - disconnect: jest.fn(), - removeAllListeners: jest.fn(), - } as unknown as Tty, - status, - closeDocument: jest.fn(), +const setup = (status: Status) => { + mockUseDbSession.mockReturnValue({ + tty: { sendDbConnectData: jest.fn(), - session: baseSession, - }); - - const { ctx, consoleCtx } = getContexts(); - - render( - - - - - - ); - }; - - test('renders loading indicator when status is loading', () => { - jest.useFakeTimers(); - setup('loading'); - - act(() => jest.runAllTimers()); - expect(screen.getByTestId('indicator')).toBeInTheDocument(); + on: jest.fn(), + removeListener: jest.fn(), + connect: jest.fn(), + disconnect: jest.fn(), + removeAllListeners: jest.fn(), + } as unknown as Tty, + status, + closeDocument: jest.fn(), + sendDbConnectData: jest.fn(), + session: baseSession, }); - test('renders terminal window when status is initialized', () => { - setup('initialized'); + const { ctx, consoleCtx } = getContexts(); - expect(screen.getByTestId('terminal')).toBeInTheDocument(); - }); + render( + + + + + + ); +}; - test('renders data dialog when status is waiting', () => { - setup('waiting'); +test('renders loading indicator when status is loading', () => { + jest.useFakeTimers(); + setup('loading'); - expect(screen.getByText('Connect To Database')).toBeInTheDocument(); - }); + act(() => jest.runAllTimers()); + expect(screen.getByTestId('indicator')).toBeInTheDocument(); +}); - test('does not render data dialog when status is initialized', () => { - setup('initialized'); +test('renders terminal window when status is initialized', () => { + setup('initialized'); - expect(screen.queryByText('Connect to Database')).not.toBeInTheDocument(); - }); + expect(screen.getByTestId('terminal')).toBeInTheDocument(); +}); + +test('renders data dialog when status is waiting', () => { + setup('waiting'); + + expect(screen.getByText('Connect To Database')).toBeInTheDocument(); +}); + +test('does not render data dialog when status is initialized', () => { + setup('initialized'); + + expect(screen.queryByText('Connect to Database')).not.toBeInTheDocument(); }); function getContexts() { diff --git a/web/packages/teleport/src/Console/DocumentSsh/Terminal/Terminal.tsx b/web/packages/teleport/src/Console/DocumentSsh/Terminal/Terminal.tsx index f5188c1ba507e..da11d44e8df7f 100644 --- a/web/packages/teleport/src/Console/DocumentSsh/Terminal/Terminal.tsx +++ b/web/packages/teleport/src/Console/DocumentSsh/Terminal/Terminal.tsx @@ -74,7 +74,7 @@ export const Terminal = forwardRef((props, ref) => { termCtrl.open(); const { unregister } = termCtrl.registerCustomKeyEventHandler(event => { - if (props.disableCtrlC && event.ctrlKey && event.key == 'c') { + if (props.disableCtrlC && event.ctrlKey && event.key === 'c') { return false; }