@@ -91,13 +91,29 @@ const renderComponent = (options = {}) => {
9191 stubs : {
9292 StudioImmersiveModal : {
9393 template : `
94- <div>
95- <button data-test="close" @click="$emit('input', false) ">Close</button>
94+ <div v-if="value" data-testid="modal-wrapper" >
95+ <button data-test="close" @click="handleClose ">Close</button>
9696 <div><slot name="header"></slot></div>
9797 <slot></slot>
9898 </div>
9999 ` ,
100100 props : [ 'value' ] ,
101+ methods : {
102+ handleClose ( ) {
103+ this . $emit ( 'input' , false ) ;
104+ } ,
105+ } ,
106+ mounted ( ) {
107+ const handleKeyDown = event => {
108+ if ( event . key === 'Escape' ) {
109+ this . $emit ( 'input' , false ) ;
110+ }
111+ } ;
112+ document . addEventListener ( 'keydown' , handleKeyDown ) ;
113+ this . $once ( 'hook:beforeDestroy' , ( ) => {
114+ document . removeEventListener ( 'keydown' , handleKeyDown ) ;
115+ } ) ;
116+ } ,
101117 } ,
102118 StudioLargeLoader : {
103119 template : '<div data-testid="loader">Loading...</div>' ,
@@ -110,25 +126,22 @@ const renderComponent = (options = {}) => {
110126 template : `
111127 <button :data-test="$attrs['data-test']">
112128 {{ text }}
113- <div v-if="hasDropdown"><slot name="menu"></slot></div>
114129 </button>
115130 ` ,
116131 props : [ 'text' , 'primary' , 'hasDropdown' ] ,
117132 } ,
118133 KDropdownMenu : {
119- template : `
120- <div data-testid="dropdown-menu">
121- <button
122- v-for="option in options"
123- :key="option.value"
124- @click="$emit('select', option)"
125- >
126- {{ option.label }}
127- </button>
128- </div>
129- ` ,
134+ template : '<div></div>' ,
130135 props : [ 'options' ] ,
131136 } ,
137+ StudioPage : {
138+ template : '<div><slot></slot></div>' ,
139+ props : [ 'offline' , 'marginTop' ] ,
140+ } ,
141+ StudioOfflineAlert : {
142+ template : '<div></div>' ,
143+ props : [ 'offset' ] ,
144+ } ,
132145 } ,
133146 mocks : {
134147 $analytics : {
@@ -157,7 +170,7 @@ describe('ChannelDetailsModal', () => {
157170 } ) ;
158171 } ) ;
159172
160- it ( 'clicking close button should close the modal ' , async ( ) => {
173+ it ( 'should close modal when close button is clicked ' , async ( ) => {
161174 const user = userEvent . setup ( ) ;
162175 renderComponent ( ) ;
163176
@@ -166,65 +179,34 @@ describe('ChannelDetailsModal', () => {
166179 } ) ;
167180
168181 const closeButton = screen . getByRole ( 'button' , { name : / c l o s e / i } ) ;
169- expect ( closeButton ) . toBeInTheDocument ( ) ;
170182 await user . click ( closeButton ) ;
171- } ) ;
172-
173- it ( 'pressing ESC key should close the modal' , async ( ) => {
174- const user = userEvent . setup ( ) ;
175- const { container } = renderComponent ( ) ;
176-
177- await waitFor ( ( ) => {
178- expect ( screen . getByText ( testChannel . name ) ) . toBeInTheDocument ( ) ;
179- } ) ;
180-
181- expect ( container . querySelector ( '.studio-immersive-modal' ) ) . toBeInTheDocument ( ) ;
182-
183- await user . keyboard ( '{Escape}' ) ;
184183
185184 await waitFor ( ( ) => {
186- expect ( container . querySelector ( '.studio-immersive- modal') ) . not . toBeInTheDocument ( ) ;
185+ expect ( screen . queryByTestId ( ' modal-wrapper ') ) . not . toBeInTheDocument ( ) ;
187186 } ) ;
188187 } ) ;
189188
190- it ( 'should display download button after loading' , async ( ) => {
189+ it ( 'should close modal when ESC key is pressed' , async ( ) => {
190+ const user = userEvent . setup ( ) ;
191191 renderComponent ( ) ;
192192
193193 await waitFor ( ( ) => {
194- expect ( screen . getByText ( 'Download channel summary ') ) . toBeInTheDocument ( ) ;
194+ expect ( screen . getByTestId ( 'modal-wrapper ') ) . toBeInTheDocument ( ) ;
195195 } ) ;
196- } ) ;
197196
198- it ( 'should display download button with dropdown functionality' , async ( ) => {
199- const user = userEvent . setup ( ) ;
200- renderComponent ( ) ;
197+ await user . keyboard ( '{Escape}' ) ;
201198
202199 await waitFor ( ( ) => {
203- expect ( screen . getByText ( 'Download channel summary ') ) . toBeInTheDocument ( ) ;
200+ expect ( screen . queryByTestId ( 'modal-wrapper ') ) . not . toBeInTheDocument ( ) ;
204201 } ) ;
205-
206- const downloadButton = screen . getByRole ( 'button' , { name : / d o w n l o a d c h a n n e l s u m m a r y / i } ) ;
207- expect ( downloadButton ) . toBeInTheDocument ( ) ;
208-
209- await user . click ( downloadButton ) ;
210-
211- expect ( await screen . findByText ( 'Download PDF' ) ) . toBeInTheDocument ( ) ;
212- expect ( await screen . findByText ( 'Download CSV' ) ) . toBeInTheDocument ( ) ;
213202 } ) ;
214203
215- it ( 'should call generateChannelsCSV when CSV option is selected' , async ( ) => {
216- const user = userEvent . setup ( ) ;
204+ it ( 'should display download button after loading' , async ( ) => {
217205 renderComponent ( ) ;
218206
219207 await waitFor ( ( ) => {
220- expect ( screen . getByText ( testChannel . name ) ) . toBeInTheDocument ( ) ;
208+ expect ( screen . getByText ( 'Download channel summary' ) ) . toBeInTheDocument ( ) ;
221209 } ) ;
222-
223- const downloadButton = screen . getByRole ( 'button' , { name : / d o w n l o a d c h a n n e l s u m m a r y / i } ) ;
224- await user . click ( downloadButton ) ;
225-
226- const csvOption = await screen . findByText ( 'Download CSV' ) ;
227- await user . click ( csvOption ) ;
228210 } ) ;
229211
230212 it ( 'should display details panel after loading' , async ( ) => {
@@ -250,7 +232,5 @@ describe('ChannelDetailsModal', () => {
250232 await waitFor ( ( ) => {
251233 expect ( screen . getByText ( testChannel . name ) ) . toBeInTheDocument ( ) ;
252234 } ) ;
253-
254- expect ( screen . getByText ( testChannel . name ) ) . toBeInTheDocument ( ) ;
255235 } ) ;
256236} ) ;
0 commit comments