Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DocumentSsh.story.tsx #41877

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 46 additions & 24 deletions web/packages/teleport/src/Console/DocumentSsh/DocumentSsh.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,82 @@

import React from 'react';

import { ContextProvider } from 'teleport';

import { createTeleportContext } from 'teleport/mocks/contexts';

import TeleportContext from 'teleport/teleportContext';

import * as stores from 'teleport/Console/stores/types';

import DocumentSsh from './DocumentSsh';

import { TestLayout } from './../Console.story';
import ConsoleCtx from './../consoleContext';

import type { Session } from 'teleport/services/session';

export const Connected = () => {
const ctx = new ConsoleCtx();
const tty = ctx.createTty(session);
tty.connect = () => null;
ctx.createTty = () => tty;
const { ctx, consoleCtx } = getContexts();

return (
<TestLayout ctx={ctx}>
<DocumentSsh doc={doc} visible={true} />
</TestLayout>
);
return <DocumentSshWrapper ctx={ctx} consoleCtx={consoleCtx} doc={doc} />;
};

export const NotFound = () => {
const ctx = new ConsoleCtx();
const tty = ctx.createTty(session);
tty.connect = () => null;
ctx.createTty = () => tty;

const disconnectedDoc = {
...doc,
status: 'disconnected' as const,
};
const { ctx, consoleCtx } = getContexts();

return (
<TestLayout ctx={ctx}>
<DocumentSsh doc={disconnectedDoc} visible={true} />
</TestLayout>
<DocumentSshWrapper
ctx={ctx}
consoleCtx={consoleCtx}
doc={disconnectedDoc}
/>
);
};

export const ServerError = () => {
const ctx = new ConsoleCtx();
const tty = ctx.createTty(session);
tty.connect = () => null;
ctx.createTty = () => tty;
const noSidDoc = {
...doc,
sid: '',
};
const { ctx, consoleCtx } = getContexts();

return (
<DocumentSshWrapper ctx={ctx} consoleCtx={consoleCtx} doc={noSidDoc} />
);
};

type Props = {
ctx: TeleportContext;
consoleCtx: ConsoleCtx;
doc: stores.DocumentSsh;
};

const DocumentSshWrapper = ({ ctx, consoleCtx, doc }: Props) => {
return (
<TestLayout ctx={ctx}>
<DocumentSsh doc={noSidDoc} visible={true} />
</TestLayout>
<ContextProvider ctx={ctx}>
<TestLayout ctx={consoleCtx}>
<DocumentSsh doc={doc} visible={true} />
</TestLayout>
</ContextProvider>
);
};

function getContexts() {
const ctx = createTeleportContext();
const consoleCtx = new ConsoleCtx();
const tty = consoleCtx.createTty(session);
tty.connect = () => null;
consoleCtx.createTty = () => tty;
consoleCtx.storeUser = ctx.storeUser;

return { ctx, consoleCtx };
}

export default {
title: 'Teleport/Console/DocumentSsh',
};
Expand Down
Loading