Skip to content

Commit

Permalink
Fix DocumentSsh.story.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAM committed May 22, 2024
1 parent dbd2377 commit b58cf5d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"tdd": "jest --watch",
"lint": "yarn prettier-check && yarn eslint",
"eslint": "eslint --quiet '+(e|web)/**/*.{ts,tsx,js,jsx,mts}'",
"eslint-fix": "eslint --fix --quiet '+(e|web)/**/*.{ts,tsx,js,jsx,mts}'",
"type-check": "NODE_OPTIONS='--max-old-space-size=4096' tsc",
"prettier-check": "yarn prettier --check '+(e|web)/**/*.{ts,tsx,js,jsx,mts}'",
"prettier-write": "yarn prettier --write --loglevel silent '+(e|web)/**/*.{ts,tsx,js,jsx,mts}'",
Expand Down
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

0 comments on commit b58cf5d

Please sign in to comment.