Skip to content

Commit 9563025

Browse files
add: synth ui unit tests
fix tests
1 parent 996afd4 commit 9563025

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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(<SynthOutput stacks={[]} />);
14+
expect(stripAnsi(lastFrame())).toBe("No stacks found in configuration.");
15+
{
16+
const multipleStacks = [
17+
{ name: "stack1" },
18+
{ name: "stack2" },
19+
] as SynthesizedStack[];
20+
21+
const { lastFrame } = render(<SynthOutput stacks={multipleStacks} />);
22+
expect(stripAnsi(lastFrame())).toBe(
23+
"Generated Terraform code for the stacks: stack1, stack2",
24+
);
25+
}
26+
});

0 commit comments

Comments
 (0)