Skip to content

Commit f10376d

Browse files
Fix vitests for FormEventStreamSettings.
Add tests for accountName/enabled. Fix tests to ensure no hidden errors writing to stderr. Signed-off-by: Jason Sherman <[email protected]>
1 parent ed1b9f0 commit f10376d

File tree

2 files changed

+82
-27
lines changed

2 files changed

+82
-27
lines changed

app/frontend/src/components/designer/settings/FormEventStreamSettings.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ defineExpose({
206206
</v-col>
207207
</v-row>
208208
<v-container v-if="form.eventStreamConfig.enabled">
209-
<v-row class="pl-6 m-0">
209+
<v-row class="pl-6 m-0" data-cy="enablePublicStreamRow">
210210
<v-col cols="12" md="6" class="pl-0 pr-0 pb-0">
211211
<v-checkbox
212212
v-model="form.eventStreamConfig.enablePublicStream"
@@ -224,7 +224,7 @@ defineExpose({
224224
</v-checkbox>
225225
</v-col>
226226
</v-row>
227-
<v-row class="pl-6 m-0">
227+
<v-row class="pl-6 m-0" data-cy="enablePrivateStreamRow">
228228
<v-col cols="12" md="6" class="pl-0 pr-0 pb-0">
229229
<v-checkbox
230230
v-model="form.eventStreamConfig.enablePrivateStream"

app/frontend/tests/unit/components/designer/settings/FormEventStreamSettings.spec.js

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
11
import { createTestingPinia } from '@pinia/testing';
22
import { mount } from '@vue/test-utils';
33
import { setActivePinia } from 'pinia';
4-
import { beforeEach, describe, expect, it } from 'vitest';
4+
import { beforeEach, describe, expect, it, vi } from 'vitest';
55
import { ref } from 'vue';
66

77
import { useAppStore } from '~/store/app';
88
import { useFormStore } from '~/store/form';
99
import FormEventStreamSettings from '~/components/designer/settings/FormEventStreamSettings.vue';
10+
import { encryptionKeyService } from '~/services';
11+
12+
const STUBS = {
13+
BasePanel: {
14+
name: 'BasePanel',
15+
template: '<div class="base-panel-stub"><slot /></div>',
16+
},
17+
BaseCopyToClipboard: {
18+
name: 'BaseCopyToClipboard',
19+
template: '<div class="base-copy-to-clipboard-stub"><slot /></div>',
20+
},
21+
};
1022

1123
describe('FormEventStreamSettings.vue', () => {
1224
const pinia = createTestingPinia();
1325
setActivePinia(pinia);
1426

1527
const formStore = useFormStore(pinia);
1628
const appStore = useAppStore(pinia);
29+
const listEncryptionAlgorithmsSpy = vi.spyOn(
30+
encryptionKeyService,
31+
'listEncryptionAlgorithms'
32+
);
1733

1834
beforeEach(() => {
1935
appStore.$reset();
2036
formStore.$reset();
37+
listEncryptionAlgorithmsSpy.mockReset();
38+
listEncryptionAlgorithmsSpy.mockImplementation(() => ({ data: [] }));
39+
});
40+
afterAll(() => {
41+
listEncryptionAlgorithmsSpy.mockRestore();
2142
});
2243

2344
it('renders eventStreamService configuration', async () => {
@@ -32,12 +53,7 @@ describe('FormEventStreamSettings.vue', () => {
3253
const wrapper = mount(FormEventStreamSettings, {
3354
global: {
3455
plugins: [pinia],
35-
stubs: {
36-
BasePanel: {
37-
name: 'BasePanel',
38-
template: '<div class="base-panel-stub"><slot /></div>',
39-
},
40-
},
56+
stubs: STUBS,
4157
},
4258
});
4359
expect(wrapper.find('[data-test="consumerservers"]').text()).toContain(
@@ -61,12 +77,7 @@ describe('FormEventStreamSettings.vue', () => {
6177
const wrapper = mount(FormEventStreamSettings, {
6278
global: {
6379
plugins: [pinia],
64-
stubs: {
65-
BasePanel: {
66-
name: 'BasePanel',
67-
template: '<div class="base-panel-stub"><slot /></div>',
68-
},
69-
},
80+
stubs: STUBS,
7081
},
7182
});
7283

@@ -88,12 +99,7 @@ describe('FormEventStreamSettings.vue', () => {
8899
const wrapper = mount(FormEventStreamSettings, {
89100
global: {
90101
plugins: [pinia],
91-
stubs: {
92-
BasePanel: {
93-
name: 'BasePanel',
94-
template: '<div class="base-panel-stub"><slot /></div>',
95-
},
96-
},
102+
stubs: STUBS,
97103
},
98104
});
99105

@@ -117,12 +123,7 @@ describe('FormEventStreamSettings.vue', () => {
117123
const wrapper = mount(FormEventStreamSettings, {
118124
global: {
119125
plugins: [pinia],
120-
stubs: {
121-
BasePanel: {
122-
name: 'BasePanel',
123-
template: '<div class="base-panel-stub"><slot /></div>',
124-
},
125-
},
126+
stubs: STUBS,
126127
},
127128
});
128129

@@ -152,4 +153,58 @@ describe('FormEventStreamSettings.vue', () => {
152153

153154
expect(wrapper.vm.encryptionKeyRules[0]('aes-256-gcm')).toEqual(true); // some value should pass
154155
});
156+
157+
it('hides stream config when not enabled', async () => {
158+
formStore.form = ref({
159+
eventStreamConfig: {
160+
enablePublicStream: false,
161+
enablePrivateStream: true,
162+
encryptionKey: {
163+
algorithm: null,
164+
key: null,
165+
},
166+
accountName: null,
167+
enabled: false,
168+
},
169+
});
170+
171+
const wrapper = mount(FormEventStreamSettings, {
172+
global: {
173+
plugins: [pinia],
174+
stubs: STUBS,
175+
},
176+
});
177+
178+
const row1 = wrapper.find('[data-cy="enablePublicStreamRow"]');
179+
expect(row1.exists()).toBeFalsy();
180+
const row2 = wrapper.find('[data-cy="enablePrivateStreamRow"]');
181+
expect(row2.exists()).toBeFalsy();
182+
});
183+
184+
it('shows stream config when enabled', async () => {
185+
formStore.form = ref({
186+
eventStreamConfig: {
187+
enablePublicStream: false,
188+
enablePrivateStream: true,
189+
encryptionKey: {
190+
algorithm: null,
191+
key: null,
192+
},
193+
accountName: 'testaccount', //accountName required to become enabled
194+
enabled: true,
195+
},
196+
});
197+
198+
const wrapper = mount(FormEventStreamSettings, {
199+
global: {
200+
plugins: [pinia],
201+
stubs: STUBS,
202+
},
203+
});
204+
205+
const row1 = wrapper.find('[data-cy="enablePublicStreamRow"]');
206+
expect(row1.exists()).toBeTruthy();
207+
const row2 = wrapper.find('[data-cy="enablePrivateStreamRow"]');
208+
expect(row2.exists()).toBeTruthy();
209+
});
155210
});

0 commit comments

Comments
 (0)