@@ -8,11 +8,6 @@ import type {
88} from '../types/puzzlesPage' ;
99import { getPuzzleUrl , PuzzlesDirectory } from './PuzzlesDirectory' ;
1010
11- jest . mock ( './AdSlot.web' , ( ) => ( {
12- AdSlot : ( { index } : { index : number } ) => (
13- < div data-testid = { `ad-${ index } ` } />
14- ) ,
15- } ) ) ;
1611jest . mock ( './Island' , ( ) => ( {
1712 Island : ( { children } : { children : ReactNode } ) => children ,
1813} ) ) ;
@@ -38,6 +33,36 @@ const section = (
3833} ) ;
3934
4035describe ( 'PuzzlesDirectory' , ( ) => {
36+ it ( 'renders unique desktop and mobile IDs for multiple blueprint slots' , ( ) => {
37+ const layout : PuzzlesLayoutType = {
38+ containers : [ 'inline1' , 'inline2' ] . map ( ( adSlot ) =>
39+ section ( {
40+ id : adSlot ,
41+ title : '' ,
42+ variant : 'ad' ,
43+ adSlot,
44+ content : { items : [ ] , nestedContainers : [ ] } ,
45+ } ) ,
46+ ) ,
47+ } ;
48+ const { rerender } = render (
49+ < PuzzlesDirectory layout = { layout } renderAds = { true } /> ,
50+ ) ;
51+ const ids = Array . from (
52+ document . querySelectorAll ( '.js-ad-slot' ) ,
53+ ( { id } ) => id ,
54+ ) ;
55+ expect ( ids ) . toEqual ( [
56+ 'dfp-ad--fronts-banner-1' ,
57+ 'dfp-ad--inline1--mobile' ,
58+ 'dfp-ad--fronts-banner-2' ,
59+ 'dfp-ad--inline2--mobile' ,
60+ ] ) ;
61+ expect ( new Set ( ids ) . size ) . toBe ( ids . length ) ;
62+ rerender ( < PuzzlesDirectory layout = { layout } renderAds = { false } /> ) ;
63+ expect ( document . querySelector ( '.js-ad-slot' ) ) . not . toBeInTheDocument ( ) ;
64+ } ) ;
65+
4166 it ( 'does not render a disabled featured container' , ( ) => {
4267 render (
4368 < PuzzlesDirectory
@@ -176,9 +201,14 @@ describe('PuzzlesDirectory', () => {
176201 screen . queryByRole ( 'heading' , { name : 'Empty' } ) ,
177202 ) . not . toBeInTheDocument ( ) ;
178203 expect ( document . querySelector ( 'img' ) ) . not . toBeInTheDocument ( ) ;
179- expect ( screen . queryByTestId ( ' ad-2 ') ) . not . toBeInTheDocument ( ) ;
204+ expect ( document . querySelector ( '.js- ad-slot ') ) . not . toBeInTheDocument ( ) ;
180205 rerender ( < PuzzlesDirectory layout = { layout } renderAds = { true } /> ) ;
181- expect ( screen . getByTestId ( 'ad-2' ) ) . toBeInTheDocument ( ) ;
206+ expect (
207+ document . getElementById ( 'dfp-ad--fronts-banner-2' ) ,
208+ ) . toHaveAttribute ( 'data-name' , 'fronts-banner-2' ) ;
209+ expect (
210+ document . getElementById ( 'dfp-ad--inline2--mobile' ) ,
211+ ) . toHaveAttribute ( 'data-name' , 'inline2' ) ;
182212 } ) ;
183213
184214 it ( 'renders the archive dropdown and closes it with Escape or an outside click' , async ( ) => {
0 commit comments