@@ -4,10 +4,23 @@ import userEvent from '@testing-library/user-event';
44import React from 'react' ;
55import { describe , expect } from 'vitest' ;
66
7+ import { accountFactory } from 'src/factories' ;
78import { renderWithThemeAndHookFormContext } from 'src/utilities/testHelpers' ;
89
910import { StreamFormGeneralInfo } from './StreamFormGeneralInfo' ;
1011
12+ const queryMocks = vi . hoisted ( ( ) => ( {
13+ useAccount : vi . fn ( ) . mockReturnValue ( { } ) ,
14+ } ) ) ;
15+
16+ vi . mock ( '@linode/queries' , async ( ) => {
17+ const actual = await vi . importActual ( '@linode/queries' ) ;
18+ return {
19+ ...actual ,
20+ useAccount : queryMocks . useAccount ,
21+ } ;
22+ } ) ;
23+
1124describe ( 'StreamFormGeneralInfo' , ( ) => {
1225 describe ( 'when in create mode' , ( ) => {
1326 it ( 'should render Name input and allow to type text' , async ( ) => {
@@ -24,35 +37,77 @@ describe('StreamFormGeneralInfo', () => {
2437 } ) ;
2538 } ) ;
2639
27- it ( 'should render Stream type input and allow to select different options' , async ( ) => {
28- renderWithThemeAndHookFormContext ( {
29- component : < StreamFormGeneralInfo mode = "create" /> ,
30- useFormOptions : {
31- defaultValues : {
32- stream : {
33- type : streamType . AuditLogs ,
40+ describe ( 'when user has Akamai Cloud Pulse Logs LKE-E Audit capability' , ( ) => {
41+ it ( 'should render Stream type input and allow to select different options' , async ( ) => {
42+ const account = accountFactory . build ( {
43+ capabilities : [ 'Akamai Cloud Pulse Logs LKE-E Audit' ] ,
44+ } ) ;
45+
46+ queryMocks . useAccount . mockReturnValue ( {
47+ data : account ,
48+ isLoading : false ,
49+ error : null ,
50+ } ) ;
51+
52+ renderWithThemeAndHookFormContext ( {
53+ component : < StreamFormGeneralInfo mode = "create" /> ,
54+ useFormOptions : {
55+ defaultValues : {
56+ stream : {
57+ type : streamType . AuditLogs ,
58+ } ,
3459 } ,
3560 } ,
36- } ,
37- } ) ;
61+ } ) ;
3862
39- const streamTypesAutocomplete = screen . getByRole ( 'combobox' ) ;
63+ const streamTypesAutocomplete = screen . getByRole ( 'combobox' ) ;
4064
41- expect ( streamTypesAutocomplete ) . toHaveValue ( 'Audit Logs' ) ;
42-
43- // Open the dropdown
44- await userEvent . click ( streamTypesAutocomplete ) ;
65+ expect ( streamTypesAutocomplete ) . toHaveValue ( 'Audit Logs' ) ;
4566
46- // Select the "Kubernetes API Audit Logs" option
47- const kubernetesApiAuditLogs = await screen . findByText (
48- 'Kubernetes API Audit Logs'
49- ) ;
50- await userEvent . click ( kubernetesApiAuditLogs ) ;
67+ // Open the dropdown
68+ await userEvent . click ( streamTypesAutocomplete ) ;
5169
52- await waitFor ( ( ) => {
53- expect ( streamTypesAutocomplete ) . toHaveValue (
70+ // Select the "Kubernetes API Audit Logs" option
71+ const kubernetesApiAuditLogs = await screen . findByText (
5472 'Kubernetes API Audit Logs'
5573 ) ;
74+ await userEvent . click ( kubernetesApiAuditLogs ) ;
75+
76+ await waitFor ( ( ) => {
77+ expect ( streamTypesAutocomplete ) . toHaveValue (
78+ 'Kubernetes API Audit Logs'
79+ ) ;
80+ } ) ;
81+ } ) ;
82+ } ) ;
83+
84+ describe ( 'when user does not have Akamai Cloud Pulse Logs LKE-E Audit capability' , ( ) => {
85+ it ( 'should render disabled Stream type input with Audit Logs selected' , async ( ) => {
86+ const account = accountFactory . build ( {
87+ capabilities : [ ] ,
88+ } ) ;
89+
90+ queryMocks . useAccount . mockReturnValue ( {
91+ data : account ,
92+ isLoading : false ,
93+ error : null ,
94+ } ) ;
95+
96+ renderWithThemeAndHookFormContext ( {
97+ component : < StreamFormGeneralInfo mode = "create" /> ,
98+ useFormOptions : {
99+ defaultValues : {
100+ stream : {
101+ type : streamType . AuditLogs ,
102+ } ,
103+ } ,
104+ } ,
105+ } ) ;
106+
107+ const streamTypesAutocomplete = screen . getByRole ( 'combobox' ) ;
108+
109+ expect ( streamTypesAutocomplete ) . toBeDisabled ( ) ;
110+ expect ( streamTypesAutocomplete ) . toHaveValue ( 'Audit Logs' ) ;
56111 } ) ;
57112 } ) ;
58113 } ) ;
0 commit comments