@@ -16,7 +16,6 @@ import { registerLineCardCommand } from "./card-command.js";
1616import {
1717 createActionCard ,
1818 createAppleTvRemoteCard ,
19- createCarousel ,
2019 createDeviceControlCard ,
2120 createEventCard ,
2221 createImageCard ,
@@ -30,9 +29,6 @@ import {
3029 createButtonTemplate ,
3130 createTemplateCarousel ,
3231 createCarouselColumn ,
33- createImageCarousel ,
34- createImageCarouselColumn ,
35- createProductCarousel ,
3632} from "./template-messages.js" ;
3733
3834const loneHighSurrogate = / [ \uD800 - \uDBFF ] (? ! [ \uDC00 - \uDFFF ] ) / ;
@@ -86,14 +82,6 @@ const lineTemplateMessageScenarios = [
8682 ) ,
8783 bodyLimit : 120 ,
8884 } ,
89- {
90- kind : "image carousel" ,
91- create : ( altText : string ) =>
92- createImageCarousel (
93- [ createImageCarouselColumn ( "https://example.test/image.png" , messageAction ( "Open" ) ) ] ,
94- altText ,
95- ) ,
96- } ,
9785] as const ;
9886
9987async function runLineFlexCardCommand (
@@ -340,97 +328,13 @@ describe("createCarouselColumn", () => {
340328} ) ;
341329
342330describe ( "carousel column limits" , ( ) => {
343- it . each ( [
344- {
345- createTemplate : ( ) =>
346- createTemplateCarousel (
347- Array . from ( { length : 15 } , ( ) =>
348- createCarouselColumn ( { text : "Text" , actions : [ messageAction ( "OK" ) ] } ) ,
349- ) ,
350- ) ,
351- } ,
352- {
353- createTemplate : ( ) =>
354- createImageCarousel (
355- Array . from ( { length : 15 } , ( _ , i ) =>
356- createImageCarouselColumn ( `https://example.com/${ i } .jpg` , messageAction ( "View" ) ) ,
357- ) ,
358- ) ,
359- } ,
360- ] ) ( "limits columns to 10" , ( { createTemplate } ) => {
361- const template = createTemplate ( ) ;
362- expect ( ( template . template as { columns : unknown [ ] } ) . columns . length ) . toBe ( 10 ) ;
363- } ) ;
364-
365- it ( "drops a surrogate-pair emoji from image-carousel altText instead of splitting it" , ( ) => {
366- const template = createImageCarousel (
367- [ createImageCarouselColumn ( "https://example.com/0.jpg" , messageAction ( "View" ) ) ] ,
368- `${ "x" . repeat ( 1499 ) } 😀` ,
369- ) ;
370-
371- expect ( template . altText ) . toBe ( "x" . repeat ( 1499 ) ) ;
372- expect ( loneHighSurrogate . test ( template . altText ) ) . toBe ( false ) ;
373- } ) ;
374-
375- it ( "keeps unavailable action labels within the image-carousel cap" , ( ) => {
376- const template = createImageCarousel ( [
377- createImageCarouselColumn (
378- "https://example.com/0.jpg" ,
379- uriAction ( "Open" , `https://example.com/?q=${ "x" . repeat ( 1200 ) } ` ) ,
331+ it ( "limits columns to 10" , ( ) => {
332+ const template = createTemplateCarousel (
333+ Array . from ( { length : 15 } , ( ) =>
334+ createCarouselColumn ( { text : "Text" , actions : [ messageAction ( "OK" ) ] } ) ,
380335 ) ,
381- ] ) ;
382- const column = (
383- template . template as {
384- columns : Array < { action : { label ?: string ; text ?: string ; type : string } } > ;
385- }
386- ) . columns [ 0 ] ;
387-
388- expect ( column ?. action ) . toEqual ( {
389- type : "message" ,
390- label : "Unavailable" ,
391- text : "Link unavailable: URL exceeds LINE's limit." ,
392- } ) ;
393- expect ( column ?. action . label ) . toHaveLength ( 11 ) ;
394- } ) ;
395- } ) ;
396-
397- describe ( "createProductCarousel" , ( ) => {
398- it . each ( [
399- {
400- title : "Product" ,
401- description : "Desc" ,
402- actionLabel : "Buy" ,
403- actionUrl : "https://shop.com/buy" ,
404- expectedType : "uri" ,
405- } ,
406- {
407- title : "Product" ,
408- description : "Desc" ,
409- actionLabel : "Select" ,
410- actionData : "product_id=123" ,
411- expectedType : "postback" ,
412- } ,
413- ] ) ( "uses expected action type for product action" , ( { expectedType, ...item } ) => {
414- const template = createProductCarousel ( [ item ] ) ;
415- const columns = ( template . template as { columns : Array < { actions : Array < { type : string } > } > } )
416- . columns ;
417- const column = expectDefined ( columns [ 0 ] , "product carousel column" ) ;
418- expect ( expectDefined ( column . actions [ 0 ] , "product carousel action" ) . type ) . toBe ( expectedType ) ;
419- } ) ;
420-
421- it ( "preserves the complete price when truncating a long description" , ( ) => {
422- const template = createProductCarousel ( [
423- {
424- title : "Product" ,
425- description : "x" . repeat ( 59 ) ,
426- price : "$12.99" ,
427- } ,
428- ] ) ;
429- const columns = ( template . template as { columns : Array < { text : string } > } ) . columns ;
430-
431- const column = expectDefined ( columns [ 0 ] , "priced product carousel column" ) ;
432- expect ( column . text ) . toBe ( `${ "x" . repeat ( 53 ) } \n$12.99` ) ;
433- expect ( column . text . length ) . toBe ( 60 ) ;
336+ ) ;
337+ expect ( ( template . template as { columns : unknown [ ] } ) . columns . length ) . toBe ( 10 ) ;
434338 } ) ;
435339} ) ;
436340
@@ -470,13 +374,6 @@ describe("flex cards", () => {
470374 expect ( footer . contents . length ) . toBe ( 4 ) ;
471375 } ) ;
472376
473- it ( "limits carousels to 12 bubbles" , ( ) => {
474- const bubbles = Array . from ( { length : 15 } , ( _ , i ) => createInfoCard ( `Card ${ i } ` , `Body ${ i } ` ) ) ;
475- const carousel = createCarousel ( bubbles ) ;
476-
477- expect ( carousel . contents . length ) . toBe ( 12 ) ;
478- } ) ;
479-
480377 it ( "limits device controls to 6" , ( ) => {
481378 const card = createDeviceControlCard ( {
482379 deviceName : "Device" ,
@@ -700,8 +597,12 @@ describe("action label/data surrogate-safe truncation", () => {
700597 expect ( received . every ( ( request ) => request . authenticated ) ) . toBe ( true ) ;
701598 expect ( received . every ( ( request ) => request . type === "template" ) ) . toBe ( true ) ;
702599 expect ( received . every ( ( request ) => request . altText === altText ) ) . toBe ( true ) ;
703- expect ( received . filter ( ( request ) => request . path . endsWith ( "/push" ) ) ) . toHaveLength ( 4 ) ;
704- expect ( received . filter ( ( request ) => request . path . endsWith ( "/reply" ) ) ) . toHaveLength ( 4 ) ;
600+ expect ( received . filter ( ( request ) => request . path . endsWith ( "/push" ) ) ) . toHaveLength (
601+ lineTemplateMessageScenarios . length ,
602+ ) ;
603+ expect ( received . filter ( ( request ) => request . path . endsWith ( "/reply" ) ) ) . toHaveLength (
604+ lineTemplateMessageScenarios . length ,
605+ ) ;
705606 } ) ;
706607 } ) ;
707608
@@ -841,11 +742,6 @@ describe("action label/data surrogate-safe truncation", () => {
841742 } ;
842743 expect ( carousel . columns [ 0 ] ?. actions ) . toEqual ( [ unavailableAction ] ) ;
843744 expect ( carousel . columns [ 0 ] ?. defaultAction ) . toEqual ( unavailableLink ) ;
844-
845- const imageCarousel = createImageCarousel ( [
846- { imageUrl : "https://e.example/image.jpg" , action : oversizedPostback } ,
847- ] ) . template as { columns : Array < { action : Action } > } ;
848- expect ( imageCarousel . columns [ 0 ] ?. action ) . toEqual ( unavailableAction ) ;
849745 } ) ;
850746
851747 it ( "normalizes every length-constrained raw action field" , ( ) => {
0 commit comments