@@ -8,6 +8,7 @@ import { renderWithTheme } from 'src/utilities/testHelpers';
88
99import * as shared from '../../shared' ;
1010import { FirewallPrefixListDrawer } from './FirewallPrefixListDrawer' ;
11+ import * as rulesShared from './shared' ;
1112import { PREFIXLIST_MARKED_FOR_DELETION_TEXT } from './shared' ;
1213
1314import type { FirewallPrefixListDrawerProps } from './FirewallPrefixListDrawer' ;
@@ -34,6 +35,7 @@ vi.mock('@linode/utilities', async () => {
3435} ) ;
3536
3637const spy = vi . spyOn ( shared , 'useIsFirewallRulesetsPrefixlistsEnabled' ) ;
38+ const combineSpy = vi . spyOn ( rulesShared , 'combinePrefixLists' ) ;
3739
3840//
3941// Helper to compute expected UI values/text
@@ -76,7 +78,7 @@ const computeExpectedElements = (
7678 return { title, button, label } ;
7779} ;
7880
79- describe ( 'PrefixListDrawer ' , ( ) => {
81+ describe ( 'FirewallPrefixListDrawer ' , ( ) => {
8082 beforeEach ( ( ) => {
8183 spy . mockReturnValue ( {
8284 isFirewallRulesetsPrefixlistsFeatureEnabled : true ,
@@ -143,18 +145,26 @@ describe('PrefixListDrawer', () => {
143145
144146 it . each ( drawerProps ) (
145147 'renders correct UI for category:$category, contextType:$context.type and modeViewedFrom:$context.modeViewedFrom' ,
146- ( { category, context } ) => {
148+ ( { category, context, selectedPrefixListLabel } ) => {
149+ const mockData = firewallPrefixListFactory . build ( {
150+ name : selectedPrefixListLabel ,
151+ } ) ;
147152 queryMocks . useAllFirewallPrefixListsQuery . mockReturnValue ( {
148- data : [ firewallPrefixListFactory . build ( ) ] ,
153+ data : [ mockData ] ,
149154 } ) ;
150155
156+ combineSpy . mockReturnValue ( [
157+ ...rulesShared . SPECIAL_PREFIX_LISTS ,
158+ mockData ,
159+ ] ) ;
160+
151161 const { getByText, getByRole } = renderWithTheme (
152162 < FirewallPrefixListDrawer
153163 category = { category }
154164 context = { context }
155165 isOpen = { true }
156166 onClose = { vi . fn ( ) }
157- selectedPrefixListLabel = "pl-test"
167+ selectedPrefixListLabel = { selectedPrefixListLabel }
158168 />
159169 ) ;
160170
@@ -200,12 +210,17 @@ describe('PrefixListDrawer', () => {
200210
201211 it . each ( deletionTestCases ) ( '%s' , async ( _ , deletedTimeStamp ) => {
202212 const mockPrefixList = firewallPrefixListFactory . build ( {
213+ name : 'pl-test' ,
203214 deleted : deletedTimeStamp ,
204215 } ) ;
205216
206217 queryMocks . useAllFirewallPrefixListsQuery . mockReturnValue ( {
207218 data : [ mockPrefixList ] ,
208219 } ) ;
220+ combineSpy . mockReturnValue ( [
221+ ...rulesShared . SPECIAL_PREFIX_LISTS ,
222+ mockPrefixList ,
223+ ] ) ;
209224
210225 const { getByText, getByTestId, findByText, queryByText } = renderWithTheme (
211226 < FirewallPrefixListDrawer
@@ -340,6 +355,10 @@ describe('PrefixListDrawer', () => {
340355 queryMocks . useAllFirewallPrefixListsQuery . mockReturnValue ( {
341356 data : [ mockPrefixList ] ,
342357 } ) ;
358+ combineSpy . mockReturnValue ( [
359+ ...rulesShared . SPECIAL_PREFIX_LISTS ,
360+ mockPrefixList ,
361+ ] ) ;
343362
344363 const { getByTestId } = renderWithTheme (
345364 < FirewallPrefixListDrawer
@@ -379,3 +398,96 @@ describe('PrefixListDrawer', () => {
379398 }
380399 ) ;
381400} ) ;
401+
402+ describe ( 'FirewallPrefixListDrawer - Special "<current>" Prefix Lists' , ( ) => {
403+ beforeEach ( ( ) => {
404+ spy . mockReturnValue ( {
405+ isFirewallRulesetsPrefixlistsFeatureEnabled : true ,
406+ isFirewallRulesetsPrefixListsBetaEnabled : false ,
407+ isFirewallRulesetsPrefixListsLAEnabled : false ,
408+ isFirewallRulesetsPrefixListsGAEnabled : false ,
409+ } ) ;
410+ } ) ;
411+ const specialPrefixListDescription =
412+ 'System-defined PrefixLists, such as pl::vpcs:<current> and pl::subnets:<current>, for VPC interface firewalls are dynamic and update automatically. They manage access to and from the interface for addresses within the interface’s VPC or VPC subnet.' ;
413+ const plRuleRef = { inIPv4Rule : true , inIPv6Rule : true } ;
414+ const context : FirewallPrefixListDrawerProps [ 'context' ] [ ] = [
415+ {
416+ type : 'rule' ,
417+ plRuleRef,
418+ } ,
419+ {
420+ modeViewedFrom : 'create' ,
421+ type : 'ruleset' ,
422+ plRuleRef,
423+ } ,
424+ { modeViewedFrom : 'edit' , type : 'rule' , plRuleRef } ,
425+ { modeViewedFrom : 'view' , type : 'ruleset' , plRuleRef } ,
426+ ] ;
427+ const specialPLsTestCases = [
428+ {
429+ name : 'pl::vpcs:<current>' ,
430+ description : specialPrefixListDescription ,
431+ context : context [ 0 ] ,
432+ } ,
433+ {
434+ name : 'pl::subnets:<current>' ,
435+ description : specialPrefixListDescription ,
436+ context : context [ 1 ] ,
437+ } ,
438+ {
439+ name : 'pl::vpcs:<current>' ,
440+ description : specialPrefixListDescription ,
441+ context : context [ 2 ] ,
442+ } ,
443+ {
444+ name : 'pl::subnets:<current>' ,
445+ description : specialPrefixListDescription ,
446+ context : context [ 3 ] ,
447+ } ,
448+ ] ;
449+
450+ it . each ( specialPLsTestCases ) (
451+ 'renders only Name and Description for special PL: $name, contextType: $context.type and modeViewedFrom: $context.modeViewedFrom' ,
452+ ( { name, description, context } ) => {
453+ // API returns no matches, special PL logic must handle it
454+ queryMocks . useAllFirewallPrefixListsQuery . mockReturnValue ( {
455+ data : [ ] ,
456+ } ) ;
457+ combineSpy . mockReturnValue ( [ ...rulesShared . SPECIAL_PREFIX_LISTS ] ) ;
458+
459+ const { getByText, queryByText } = renderWithTheme (
460+ < FirewallPrefixListDrawer
461+ category = "inbound"
462+ context = { context }
463+ isOpen = { true }
464+ onClose = { vi . fn ( ) }
465+ selectedPrefixListLabel = { name }
466+ />
467+ ) ;
468+
469+ const { label } = computeExpectedElements ( 'inbound' , context ) ;
470+
471+ // Name and Description should be visible
472+ expect ( getByText ( label ) ) . toBeVisible ( ) ; // First label (Prefix List Name: OR Name:)
473+ expect ( getByText ( name ) ) . toBeVisible ( ) ;
474+
475+ expect ( getByText ( 'Description:' ) ) . toBeVisible ( ) ;
476+ expect ( getByText ( description ) ) . toBeVisible ( ) ;
477+
478+ // All other fields must be hidden
479+ const hiddenFields = [
480+ 'ID:' ,
481+ 'Type:' ,
482+ 'Visibility:' ,
483+ 'Version:' ,
484+ 'Created:' ,
485+ 'Updated:' ,
486+ ] ;
487+
488+ hiddenFields . forEach ( ( label ) => {
489+ expect ( queryByText ( label ) ) . not . toBeInTheDocument ( ) ;
490+ } ) ;
491+ }
492+ ) ;
493+ } ) ;
0 commit comments