1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Switch technical tests to inline matchers

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-06-17 09:19:37 -04:00
parent db2664a82e
commit 1e739ba7db
4 changed files with 32 additions and 170 deletions

View File

@ -10,15 +10,15 @@ import { Icon } from "../icon";
export interface SecretKeyProps {
secret: Secret;
key: string;
field: string;
}
export const SecretKey = ({ secret, key }: SecretKeyProps) => {
export const SecretKey = ({ secret, field }: SecretKeyProps) => {
const [showValue, setShowValue] = useState(false);
const showKey = () => setShowValue(true);
const value = secret?.data?.[key];
const value = secret?.data?.[field];
if (showValue && value) {
return <>{base64.decode(value)}</>;
@ -26,7 +26,7 @@ export const SecretKey = ({ secret, key }: SecretKeyProps) => {
return (
<>
{`secretKeyRef(${name}.${key})`}
{`secretKeyRef(${secret.getName()}.${field})`}
&nbsp;
<Icon
className="secret-button"

View File

@ -18,157 +18,3 @@ exports[`<ContainerEnv /> renders 1`] = `
</div>
</body>
`;
exports[`<ContainerEnv /> renders both env and configMapRef envFrom 1`] = `
<body>
<div>
<div
class="DrawerItem ContainerEnvironment"
>
<span
class="name"
>
Environment
</span>
<span
class="value"
>
<div
class="variable"
>
<span
class="var-name"
>
foobar
</span>
=
https://localhost:12345
</div>
<div
class="variable"
>
<span
class="var-name"
>
configFoo
</span>
=
configBar
</div>
</span>
</div>
</div>
</body>
`;
exports[`<ContainerEnv /> renders env 1`] = `
<body>
<div>
<div
class="DrawerItem ContainerEnvironment"
>
<span
class="name"
>
Environment
</span>
<span
class="value"
>
<div
class="variable"
>
<span
class="var-name"
>
foobar
</span>
=
https://localhost:12345
</div>
</span>
</div>
</div>
</body>
`;
exports[`<ContainerEnv /> renders env 2`] = `
<body>
<div>
<div
class="DrawerItem ContainerEnvironment"
>
<span
class="name"
>
Environment
</span>
<span
class="value"
>
<div
class="variable"
>
<span
class="var-name"
>
foobar
</span>
=
https://localhost:12345
</div>
</span>
</div>
</div>
</body>
`;
exports[`<ContainerEnv /> renders envFrom when given a configMapRef 1`] = `
<body>
<div>
<div
class="DrawerItem ContainerEnvironment"
>
<span
class="name"
>
Environment
</span>
<span
class="value"
>
<div
class="variable"
>
<span
class="var-name"
>
configFoo
</span>
=
configBar
</div>
</span>
</div>
</div>
</body>
`;
exports[`<ContainerEnv /> renders envFrom when given a secretRef 1`] = `
<body>
<div>
<div
class="DrawerItem ContainerEnvironment"
>
<span
class="name"
>
Environment
</span>
<span
class="value"
/>
</div>
</div>
</body>
`;

View File

@ -87,7 +87,7 @@ describe("<ContainerEnv />", () => {
});
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
expect(result.baseElement).toMatchSnapshot();
expect(result.getByTestId("env-foobar").innerHTML).toBe(`<span class="var-name">foobar</span>= https://localhost:12345`);
});
it("renders envFrom when given a configMapRef", () => {
@ -136,7 +136,7 @@ describe("<ContainerEnv />", () => {
});
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
expect(result.baseElement).toMatchSnapshot();
expect(result.getByTestId("envFrom-configmap-my-config-map").innerHTML).toBe(`<span class="var-name">configFoo</span>= configBar`);
});
it("renders envFrom when given a secretRef", () => {
@ -155,6 +155,9 @@ describe("<ContainerEnv />", () => {
uid: "237",
},
type: SecretType.BasicAuth,
data: {
bar: "bat",
},
});
});
@ -183,7 +186,7 @@ describe("<ContainerEnv />", () => {
});
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
expect(result.baseElement).toMatchSnapshot();
expect(result.getByTestId("envFrom-secret-my-secret-bar").innerHTML).toMatch(`<span class="var-name">bar</span>= secretKeyRef(my-secret.bar)`);
});
it("renders env", () => {
@ -211,7 +214,7 @@ describe("<ContainerEnv />", () => {
});
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
expect(result.baseElement).toMatchSnapshot();
expect(result.getByTestId("env-foobar").innerHTML).toBe(`<span class="var-name">foobar</span>= https://localhost:12345`);
});
it("renders both env and configMapRef envFrom", () => {
@ -264,6 +267,7 @@ describe("<ContainerEnv />", () => {
});
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
expect(result.baseElement).toMatchSnapshot();
expect(result.getByTestId("env-foobar").innerHTML).toBe(`<span class="var-name">foobar</span>= https://localhost:12345`);
expect(result.getByTestId("envFrom-configmap-my-config-map").innerHTML).toBe(`<span class="var-name">configFoo</span>= configBar`);
});
});

View File

@ -82,7 +82,7 @@ const NonInjectedContainerEnvironment = observer((props: ContainerEnvironmentPro
secretValue = (
<SecretKey
secret={secret}
key={secretKeyRef.key}
field={secretKeyRef.key}
/>
);
}
@ -99,7 +99,11 @@ const NonInjectedContainerEnvironment = observer((props: ContainerEnvironmentPro
}
return (
<div className="variable" key={name}>
<div
className="variable"
key={name}
data-testid={`env-${name}`}
>
<span className="var-name">{name}</span>
{`= `}
{secretValue}
@ -128,7 +132,11 @@ const NonInjectedContainerEnvironment = observer((props: ContainerEnvironmentPro
if (!configMap) return null;
return Object.entries(configMap.data).map(([name, value]) => (
<div className="variable" key={name}>
<div
className="variable"
key={name}
data-testid={`envFrom-configmap-${configMap.getName()}`}
>
<span className="var-name">{name}</span>
{`= `}
{value}
@ -142,13 +150,17 @@ const NonInjectedContainerEnvironment = observer((props: ContainerEnvironmentPro
if (!secret) return null;
return Object.keys(secret.data)
.map(key => (
<div className="variable" key={key}>
<span className="var-name">{key}</span>
.map(name => (
<div
className="variable"
key={name}
data-testid={`envFrom-secret-${secretName}-${name}`}
>
<span className="var-name">{name}</span>
{`= `}
<SecretKey
secret={secret}
key={key}
field={name}
/>
</div>
));