Skip to content

Commit 139b2c2

Browse files
add: synth ui unit tests
1 parent 61671c1 commit 139b2c2

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

packages/cdktf-cli/src/bin/cmds/ui/synth.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ interface SynthConfig extends CommonSynthConfig {
2222
type SynthOutputConfig = {
2323
stacks: SynthesizedStack[];
2424
};
25-
const SynthOutput = ({ stacks }: SynthOutputConfig): React.ReactElement => {
25+
export const SynthOutput = ({
26+
stacks,
27+
}: SynthOutputConfig): React.ReactElement => {
2628
return (
2729
<Text>
28-
{stacks?.length ? (
29-
`Generated Terraform code for the stacks: ${stacks.map((s) => s.name).join(", ")}`
30-
) : (
31-
"No stacks found in configuration."
32-
)}
30+
{stacks?.length
31+
? `Generated Terraform code for the stacks: ${stacks
32+
.map((s) => s.name)
33+
.join(", ")}`
34+
: "No stacks found in configuration."}
3335
</Text>
3436
);
3537
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
import React from "react";
7+
import { render } from "ink-testing-library";
8+
import { stripAnsi } from "../test-helper";
9+
import { SynthOutput } from "../../bin/cmds/ui/synth";
10+
import { SynthesizedStack } from "@cdktf/cli-core";
11+
12+
test("SynthOutput", () => {
13+
const { lastFrame } = render(
14+
<React.Fragment>
15+
<SynthOutput stacks={[]} />
16+
</React.Fragment>
17+
);
18+
expect(stripAnsi(lastFrame())).toBe("No stacks found in configuration.");
19+
{
20+
const multipleStacks = [
21+
{ name: "stack1" },
22+
{ name: "stack2" },
23+
] as SynthesizedStack[];
24+
25+
const { lastFrame } = render(
26+
<React.Fragment>
27+
<SynthOutput stacks={multipleStacks} />
28+
</React.Fragment>
29+
);
30+
expect(stripAnsi(lastFrame())).toBe(
31+
"Generated Terraform code for the stacks: stack1, stack2"
32+
);
33+
}
34+
});

0 commit comments

Comments
 (0)