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:
parent
db2664a82e
commit
1e739ba7db
@ -10,15 +10,15 @@ import { Icon } from "../icon";
|
|||||||
|
|
||||||
export interface SecretKeyProps {
|
export interface SecretKeyProps {
|
||||||
secret: Secret;
|
secret: Secret;
|
||||||
key: string;
|
field: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SecretKey = ({ secret, key }: SecretKeyProps) => {
|
export const SecretKey = ({ secret, field }: SecretKeyProps) => {
|
||||||
const [showValue, setShowValue] = useState(false);
|
const [showValue, setShowValue] = useState(false);
|
||||||
|
|
||||||
const showKey = () => setShowValue(true);
|
const showKey = () => setShowValue(true);
|
||||||
|
|
||||||
const value = secret?.data?.[key];
|
const value = secret?.data?.[field];
|
||||||
|
|
||||||
if (showValue && value) {
|
if (showValue && value) {
|
||||||
return <>{base64.decode(value)}</>;
|
return <>{base64.decode(value)}</>;
|
||||||
@ -26,7 +26,7 @@ export const SecretKey = ({ secret, key }: SecretKeyProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{`secretKeyRef(${name}.${key})`}
|
{`secretKeyRef(${secret.getName()}.${field})`}
|
||||||
|
|
||||||
<Icon
|
<Icon
|
||||||
className="secret-button"
|
className="secret-button"
|
||||||
|
|||||||
@ -18,157 +18,3 @@ exports[`<ContainerEnv /> renders 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</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>
|
|
||||||
`;
|
|
||||||
|
|||||||
@ -87,7 +87,7 @@ describe("<ContainerEnv />", () => {
|
|||||||
});
|
});
|
||||||
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
|
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", () => {
|
it("renders envFrom when given a configMapRef", () => {
|
||||||
@ -136,7 +136,7 @@ describe("<ContainerEnv />", () => {
|
|||||||
});
|
});
|
||||||
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
|
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", () => {
|
it("renders envFrom when given a secretRef", () => {
|
||||||
@ -155,6 +155,9 @@ describe("<ContainerEnv />", () => {
|
|||||||
uid: "237",
|
uid: "237",
|
||||||
},
|
},
|
||||||
type: SecretType.BasicAuth,
|
type: SecretType.BasicAuth,
|
||||||
|
data: {
|
||||||
|
bar: "bat",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -183,7 +186,7 @@ describe("<ContainerEnv />", () => {
|
|||||||
});
|
});
|
||||||
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
|
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", () => {
|
it("renders env", () => {
|
||||||
@ -211,7 +214,7 @@ describe("<ContainerEnv />", () => {
|
|||||||
});
|
});
|
||||||
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
|
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", () => {
|
it("renders both env and configMapRef envFrom", () => {
|
||||||
@ -264,6 +267,7 @@ describe("<ContainerEnv />", () => {
|
|||||||
});
|
});
|
||||||
const result = render(<ContainerEnvironment container={container} namespace={pod.getNs()} />);
|
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`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -82,7 +82,7 @@ const NonInjectedContainerEnvironment = observer((props: ContainerEnvironmentPro
|
|||||||
secretValue = (
|
secretValue = (
|
||||||
<SecretKey
|
<SecretKey
|
||||||
secret={secret}
|
secret={secret}
|
||||||
key={secretKeyRef.key}
|
field={secretKeyRef.key}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -99,7 +99,11 @@ const NonInjectedContainerEnvironment = observer((props: ContainerEnvironmentPro
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="variable" key={name}>
|
<div
|
||||||
|
className="variable"
|
||||||
|
key={name}
|
||||||
|
data-testid={`env-${name}`}
|
||||||
|
>
|
||||||
<span className="var-name">{name}</span>
|
<span className="var-name">{name}</span>
|
||||||
{`= `}
|
{`= `}
|
||||||
{secretValue}
|
{secretValue}
|
||||||
@ -128,7 +132,11 @@ const NonInjectedContainerEnvironment = observer((props: ContainerEnvironmentPro
|
|||||||
if (!configMap) return null;
|
if (!configMap) return null;
|
||||||
|
|
||||||
return Object.entries(configMap.data).map(([name, value]) => (
|
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>
|
<span className="var-name">{name}</span>
|
||||||
{`= `}
|
{`= `}
|
||||||
{value}
|
{value}
|
||||||
@ -142,13 +150,17 @@ const NonInjectedContainerEnvironment = observer((props: ContainerEnvironmentPro
|
|||||||
if (!secret) return null;
|
if (!secret) return null;
|
||||||
|
|
||||||
return Object.keys(secret.data)
|
return Object.keys(secret.data)
|
||||||
.map(key => (
|
.map(name => (
|
||||||
<div className="variable" key={key}>
|
<div
|
||||||
<span className="var-name">{key}</span>
|
className="variable"
|
||||||
|
key={name}
|
||||||
|
data-testid={`envFrom-secret-${secretName}-${name}`}
|
||||||
|
>
|
||||||
|
<span className="var-name">{name}</span>
|
||||||
{`= `}
|
{`= `}
|
||||||
<SecretKey
|
<SecretKey
|
||||||
secret={secret}
|
secret={secret}
|
||||||
key={key}
|
field={name}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
));
|
));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user