11import { createTestingPinia } from '@pinia/testing' ;
22import { mount } from '@vue/test-utils' ;
33import { setActivePinia } from 'pinia' ;
4- import { beforeEach , describe , expect , it } from 'vitest' ;
4+ import { beforeEach , describe , expect , it , vi } from 'vitest' ;
55import { ref } from 'vue' ;
66
77import { useAppStore } from '~/store/app' ;
88import { useFormStore } from '~/store/form' ;
99import 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
1123describe ( '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