@@ -11,6 +11,8 @@ import {
1111 PLACEMENT_METRIC_LABELS ,
1212 PLACEMENT_PREVIEW_WIDTHS ,
1313 PLACEMENT_SLOTS ,
14+ TRACKED_LINK_PLACEMENT_ID ,
15+ placementSlotLabel ,
1416 PLACEMENT_STATUS_LABELS ,
1517 PRIMARY_METRICS ,
1618 UNDERSPEND_COPY ,
@@ -246,3 +248,48 @@ describe('copy and configuration', () => {
246248 expect ( PLACEMENT_METRIC_LABELS . ecpm ) . toBe ( 'Effective CPM' )
247249 } )
248250} )
251+
252+ /**
253+ * The reporting grain is wider than the slot catalog, and the labeller has to
254+ * know it.
255+ *
256+ * `PLACEMENT_SLOTS` lists what an advertiser can buy a position in. A tracked
257+ * link is not one of those — nothing auctions it and nothing serves an
258+ * impression into it — but the delivery rollup groups by `placement_id`, so
259+ * every surface that labels a placement will meet it.
260+ */
261+ describe ( 'placementSlotLabel' , ( ) => {
262+ it ( 'renders every real slot exactly as the breakdown table already did' , ( ) => {
263+ // This is a behaviour-preservation assertion, not a new format: these
264+ // strings are what the table showed before the labeller moved here.
265+ expect ( placementSlotLabel ( 'waiting-room-1' ) ) . toBe ( 'Waiting room 1' )
266+ expect ( placementSlotLabel ( 'CLI-Chat-Inline' ) ) . toBe ( 'CLI Chat Inline' )
267+ expect ( placementSlotLabel ( 'Web-Chat-After-User-Message' ) ) . toBe (
268+ 'Web Chat After User Message' ,
269+ )
270+ for ( const slot of PLACEMENT_SLOTS ) {
271+ expect ( placementSlotLabel ( slot . id ) . length ) . toBeGreaterThan ( 0 )
272+ }
273+ } )
274+
275+ it ( 'names the tracked-link grain, which no slot describes' , ( ) => {
276+ expect ( placementSlotLabel ( TRACKED_LINK_PLACEMENT_ID ) ) . toBe ( 'Tracked links' )
277+ // That it is not a slot is proved by the compiler rather than asserted
278+ // here: `PLACEMENT_SLOTS` is `as const`, so comparing a slot id against
279+ // this constant is a type error ("no overlap"). Adding it to the catalog
280+ // would put a tracked link in front of an advertiser choosing where their
281+ // ad appears, which is not what it is.
282+ expect (
283+ ( PLACEMENT_SLOTS as readonly { id : string } [ ] ) . some (
284+ ( slot ) => slot . id === TRACKED_LINK_PLACEMENT_ID ,
285+ ) ,
286+ ) . toBe ( false )
287+ } )
288+
289+ it ( 'degrades an unknown grain to something readable, never undefined' , ( ) => {
290+ // The next grain after tracked links must render as a string a human can
291+ // read, not as a gap that looks like a bug in the numbers beside it.
292+ expect ( placementSlotLabel ( 'some-future-grain' ) ) . toBe ( 'Some future grain' )
293+ expect ( placementSlotLabel ( '' ) ) . toBe ( '' )
294+ } )
295+ } )
0 commit comments