@@ -5,7 +5,7 @@ import React from 'react';
55import { renderWithTheme } from 'src/utilities/testHelpers' ;
66
77import * as shared from '../../shared' ;
8- import { MultiplePrefixListSelect } from './MutiplePrefixListSelect ' ;
8+ import { MultiplePrefixListSelect } from './MultiplePrefixListSelect ' ;
99
1010const queryMocks = vi . hoisted ( ( ) => ( {
1111 useAllFirewallPrefixListsQuery : vi . fn ( ) . mockReturnValue ( { } ) ,
@@ -31,7 +31,10 @@ describe('MultiplePrefixListSelect', () => {
3131 } ) ;
3232 } ) ;
3333
34- const onChange = vi . fn ( ) ;
34+ const baseProps = {
35+ handleOpenPrefixListDrawer : vi . fn ( ) ,
36+ onChange : vi . fn ( ) ,
37+ } ;
3538
3639 const mockPrefixLists = [
3740 {
@@ -62,7 +65,7 @@ describe('MultiplePrefixListSelect', () => {
6265 it ( 'should render the title only when at least one PL row is added' , ( ) => {
6366 const { getByText } = renderWithTheme (
6467 < MultiplePrefixListSelect
65- onChange = { vi . fn ( ) }
68+ { ... baseProps }
6669 pls = { [ { address : '' , inIPv4Rule : false , inIPv6Rule : false } ] }
6770 />
6871 ) ;
@@ -71,24 +74,23 @@ describe('MultiplePrefixListSelect', () => {
7174
7275 it ( 'should not render the title when no PL row is added' , ( ) => {
7376 const { queryByText } = renderWithTheme (
74- < MultiplePrefixListSelect onChange = { vi . fn ( ) } pls = { [ ] } />
77+ < MultiplePrefixListSelect { ... baseProps } pls = { [ ] } />
7578 ) ;
7679 expect ( queryByText ( 'Prefix List' ) ) . not . toBeInTheDocument ( ) ;
7780 } ) ;
7881
7982 it ( 'should add a new PL row (empty state) when clicking "Add a Prefix List"' , async ( ) => {
8083 const { getByText } = renderWithTheme (
81- < MultiplePrefixListSelect onChange = { onChange } pls = { [ ] } />
84+ < MultiplePrefixListSelect { ... baseProps } pls = { [ ] } />
8285 ) ;
8386
8487 await userEvent . click ( getByText ( 'Add a Prefix List' ) ) ;
85- expect ( onChange ) . toHaveBeenCalledWith ( [
88+ expect ( baseProps . onChange ) . toHaveBeenCalledWith ( [
8689 { address : '' , inIPv4Rule : false , inIPv6Rule : false } ,
8790 ] ) ;
8891 } ) ;
8992
9093 it ( 'should remove a PL row when clicking delete (X)' , async ( ) => {
91- const onChange = vi . fn ( ) ;
9294 const pls = [
9395 {
9496 address : 'pl::supports-both' ,
@@ -97,17 +99,17 @@ describe('MultiplePrefixListSelect', () => {
9799 } ,
98100 ] ;
99101 const { getByTestId } = renderWithTheme (
100- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
102+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
101103 ) ;
102104
103105 await userEvent . click ( getByTestId ( 'delete-pl-0' ) ) ;
104- expect ( onChange ) . toHaveBeenCalledWith ( [ ] ) ;
106+ expect ( baseProps . onChange ) . toHaveBeenCalledWith ( [ ] ) ;
105107 } ) ;
106108
107109 it ( 'filters out unsupported PLs from dropdown' , async ( ) => {
108110 const pls = [ { address : '' , inIPv4Rule : false , inIPv6Rule : false } ] ;
109111 const { getByRole, queryByText } = renderWithTheme (
110- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
112+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
111113 ) ;
112114
113115 const input = getByRole ( 'combobox' ) ;
@@ -131,7 +133,7 @@ describe('MultiplePrefixListSelect', () => {
131133 { address : '' , inIPv4Rule : false , inIPv6Rule : false } ,
132134 ] ;
133135 const { getAllByRole, findByText } = renderWithTheme (
134- < MultiplePrefixListSelect onChange = { onChange } pls = { selectedPLs } />
136+ < MultiplePrefixListSelect { ... baseProps } pls = { selectedPLs } />
135137 ) ;
136138
137139 const inputs = getAllByRole ( 'combobox' ) ;
@@ -166,7 +168,7 @@ describe('MultiplePrefixListSelect', () => {
166168 } ,
167169 ] ;
168170 const { getByDisplayValue, queryAllByTestId } = renderWithTheme (
169- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
171+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
170172 ) ;
171173
172174 expect ( queryAllByTestId ( 'prefixlist-select' ) ) . toHaveLength ( 3 ) ;
@@ -178,7 +180,7 @@ describe('MultiplePrefixListSelect', () => {
178180 it ( 'defaults to IPv4 selected and IPv6 unselected when choosing a PL that supports both' , async ( ) => {
179181 const pls = [ { address : '' , inIPv4Rule : false , inIPv6Rule : false } ] ;
180182 const { findByText, getByRole } = renderWithTheme (
181- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
183+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
182184 ) ;
183185
184186 const input = getByRole ( 'combobox' ) ;
@@ -190,7 +192,7 @@ describe('MultiplePrefixListSelect', () => {
190192 const option = await findByText ( 'pl::supports-both' ) ;
191193 await userEvent . click ( option ) ;
192194
193- expect ( onChange ) . toHaveBeenCalledWith ( [
195+ expect ( baseProps . onChange ) . toHaveBeenCalledWith ( [
194196 {
195197 address : 'pl::supports-both' ,
196198 inIPv4Rule : true ,
@@ -202,7 +204,7 @@ describe('MultiplePrefixListSelect', () => {
202204 it ( 'defaults to IPv4 selected and IPv6 unselected when choosing a PL that supports only IPv4' , async ( ) => {
203205 const pls = [ { address : '' , inIPv4Rule : false , inIPv6Rule : false } ] ;
204206 const { findByText, getByRole } = renderWithTheme (
205- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
207+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
206208 ) ;
207209
208210 const input = getByRole ( 'combobox' ) ;
@@ -214,7 +216,7 @@ describe('MultiplePrefixListSelect', () => {
214216 const option = await findByText ( 'pl:system:supports-only-ipv4' ) ;
215217 await userEvent . click ( option ) ;
216218
217- expect ( onChange ) . toHaveBeenCalledWith ( [
219+ expect ( baseProps . onChange ) . toHaveBeenCalledWith ( [
218220 {
219221 address : 'pl:system:supports-only-ipv4' ,
220222 inIPv4Rule : true ,
@@ -226,7 +228,7 @@ describe('MultiplePrefixListSelect', () => {
226228 it ( 'defaults to IPv4 unselected and IPv6 selected when choosing a PL that supports only IPv6' , async ( ) => {
227229 const pls = [ { address : '' , inIPv4Rule : false , inIPv6Rule : false } ] ;
228230 const { findByText, getByRole } = renderWithTheme (
229- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
231+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
230232 ) ;
231233
232234 const input = getByRole ( 'combobox' ) ;
@@ -238,7 +240,7 @@ describe('MultiplePrefixListSelect', () => {
238240 const option = await findByText ( 'pl::supports-only-ipv6' ) ;
239241 await userEvent . click ( option ) ;
240242
241- expect ( onChange ) . toHaveBeenCalledWith ( [
243+ expect ( baseProps . onChange ) . toHaveBeenCalledWith ( [
242244 {
243245 address : 'pl::supports-only-ipv6' ,
244246 inIPv4Rule : false ,
@@ -252,7 +254,7 @@ describe('MultiplePrefixListSelect', () => {
252254 { address : 'pl::supports-both' , inIPv4Rule : true , inIPv6Rule : false } ,
253255 ] ;
254256 const { findByTestId } = renderWithTheme (
255- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
257+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
256258 ) ;
257259
258260 const ipv4CheckboxWrapper = await findByTestId ( 'ipv4-checkbox-0' ) ;
@@ -275,7 +277,7 @@ describe('MultiplePrefixListSelect', () => {
275277 { address : 'pl::supports-both' , inIPv4Rule : false , inIPv6Rule : true } ,
276278 ] ;
277279 const { findByTestId } = renderWithTheme (
278- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
280+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
279281 ) ;
280282
281283 const ipv4CheckboxWrapper = await findByTestId ( 'ipv4-checkbox-0' ) ;
@@ -298,7 +300,7 @@ describe('MultiplePrefixListSelect', () => {
298300 { address : 'pl::supports-both' , inIPv4Rule : true , inIPv6Rule : true } ,
299301 ] ;
300302 const { findByTestId } = renderWithTheme (
301- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
303+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
302304 ) ;
303305
304306 const ipv4CheckboxWrapper = await findByTestId ( 'ipv4-checkbox-0' ) ;
@@ -325,7 +327,7 @@ describe('MultiplePrefixListSelect', () => {
325327 } ,
326328 ] ;
327329 const { findByTestId } = renderWithTheme (
328- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
330+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
329331 ) ;
330332
331333 const ipv4CheckboxWrapper = await findByTestId ( 'ipv4-checkbox-0' ) ;
@@ -352,7 +354,7 @@ describe('MultiplePrefixListSelect', () => {
352354 } ,
353355 ] ;
354356 const { findByTestId } = renderWithTheme (
355- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
357+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
356358 ) ;
357359
358360 const ipv4CheckboxWrapper = await findByTestId ( 'ipv4-checkbox-0' ) ;
@@ -376,14 +378,31 @@ describe('MultiplePrefixListSelect', () => {
376378 { address : 'pl::supports-both' , inIPv4Rule : true , inIPv6Rule : false } ,
377379 ] ;
378380 const { findByTestId } = renderWithTheme (
379- < MultiplePrefixListSelect onChange = { onChange } pls = { pls } />
381+ < MultiplePrefixListSelect { ... baseProps } pls = { pls } />
380382 ) ;
381383
382384 const ipv6Checkbox = await findByTestId ( 'ipv6-checkbox-0' ) ;
383385 await userEvent . click ( ipv6Checkbox ) ;
384386
385- expect ( onChange ) . toHaveBeenCalledWith ( [
387+ expect ( baseProps . onChange ) . toHaveBeenCalledWith ( [
386388 { address : 'pl::supports-both' , inIPv4Rule : true , inIPv6Rule : true } ,
387389 ] ) ;
388390 } ) ;
391+
392+ it ( 'calls handleOpenPrefixListDrawer with correct arguments when clicking "View Details"' , async ( ) => {
393+ const pls = [
394+ { address : 'pl::supports-both' , inIPv4Rule : true , inIPv6Rule : false } ,
395+ ] ;
396+
397+ const { getByText } = renderWithTheme (
398+ < MultiplePrefixListSelect { ...baseProps } pls = { pls } />
399+ ) ;
400+
401+ await userEvent . click ( getByText ( 'View Details' ) ) ;
402+
403+ expect ( baseProps . handleOpenPrefixListDrawer ) . toHaveBeenCalledWith (
404+ 'pl::supports-both' ,
405+ { inIPv4Rule : true , inIPv6Rule : false }
406+ ) ;
407+ } ) ;
389408} ) ;
0 commit comments