Skip to content

Commit ca99c28

Browse files
luizhf42gustavosbarreto
authored andcommitted
test(ui): add new tests for TerminalDialog
1 parent f9e041f commit ca99c28

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

ui/src/components/Terminal/TerminalDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ onBeforeUnmount(() => {
412412
window.removeEventListener("keyup", handleEscKey);
413413
});
414414
415-
defineExpose({ open, showTerminal, showLoginForm, encodeURLParams, connect, privateKey, xterm, fitAddon, ws, close });
415+
defineExpose({ open, showTerminal, showLoginForm, encodeURLParams, submitForm, connect, privateKey, xterm, fitAddon, ws, close });
416416
</script>
417417

418418
<style lang="scss" scoped>

ui/tests/components/Terminal/TerminalDialog.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,37 @@ describe("Terminal Dialog", async () => {
6868
expect(wrapper.vm.showLoginForm).toBe(true);
6969
});
7070

71+
it("shows X button when terminal is open", async () => {
72+
const dialog = new DOMWrapper(document.body);
73+
const connectBtn = wrapper.find('[data-test="connect-btn"]');
74+
await connectBtn.trigger("click");
75+
76+
wrapper.vm.showLoginForm = false;
77+
78+
await flushPromises();
79+
80+
const closeBtn = dialog.find('[data-test="close-terminal-btn"]');
81+
expect(closeBtn.exists()).toBe(true);
82+
});
83+
84+
it("submits form when Enter is pressed", async () => {
85+
const submitFormSpy = vi.spyOn(wrapper.vm, "submitForm").mockImplementation(vi.fn());
86+
const dialog = new DOMWrapper(document.body);
87+
const connectBtn = wrapper.find('[data-test="connect-btn"]');
88+
89+
await connectBtn.trigger("click");
90+
91+
const usernameField = dialog.find('[data-test="username-field"] input');
92+
const passwordField = dialog.find('[data-test="password-field"] input');
93+
94+
await usernameField.setValue("testuser");
95+
await passwordField.setValue("testpass");
96+
97+
passwordField.trigger("keydown.enter.prevent");
98+
await nextTick();
99+
expect(submitFormSpy).toBeTruthy();
100+
});
101+
71102
it("encodes URL params correctly", () => {
72103
const params = { key1: "value1", key2: "value2" };
73104
const encodedParams = wrapper.vm.encodeURLParams(params);

ui/tests/components/Terminal/__snapshots__/TerminalDialog.spec.ts.snap

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`Terminal Dialog > Renders the component 1`] = `
4-
"<div data-v-abcb598c="">
5-
<!--v-if-->
4+
"<div data-v-abcb598c=""><button data-v-abcb598c="" type="button" class="v-btn v-theme--light text-success v-btn--density-comfortable v-btn--size-default v-btn--variant-outlined" data-test="connect-btn"><span class="v-btn__overlay"></span><span class="v-btn__underlay"></span>
5+
<!----><span class="v-btn__content" data-no-activator="">Connect</span>
6+
<!---->
7+
<!---->
8+
</button>
69
<!---->
710
<!---->
811
</div>"

0 commit comments

Comments
 (0)