Skip to content

Commit

Permalink
refactor(web): code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcorado committed Dec 16, 2024
1 parent e6db769 commit 34df1fc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
88 changes: 43 additions & 45 deletions web/packages/teleport/src/Console/DocumentDb/DocumentDb.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<ContextProvider ctx={ctx}>
<TestLayout ctx={consoleCtx}>
<DocumentDb doc={baseDoc} visible={true} />
</TestLayout>
</ContextProvider>
);
};

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(
<ContextProvider ctx={ctx}>
<TestLayout ctx={consoleCtx}>
<DocumentDb doc={baseDoc} visible={true} />
</TestLayout>
</ContextProvider>
);
};

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const Terminal = forwardRef<TerminalRef, TerminalProps>((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;
}

Expand Down

0 comments on commit 34df1fc

Please sign in to comment.