@@ -28,8 +28,8 @@ const base: ApiWorldHeritageDto = {
2828} ;
2929
3030describe ( "toWorldHeritageVm" , ( ) => {
31- it ( "maps core fields + derived values correctly (DTO shape: thumbnail string) " , ( ) => {
32- const vm = toWorldHeritageVm ( base ) ;
31+ it ( "ja: maps core fields + derived values using Japanese labels " , ( ) => {
32+ const vm = toWorldHeritageVm ( base , "ja" ) ;
3333
3434 expect ( vm ) . toMatchObject ( {
3535 id : 663 ,
@@ -54,6 +54,7 @@ describe("toWorldHeritageVm", () => {
5454 criteriaText : "ix, x" ,
5555 title : "白神山地" ,
5656 subtitle : "日本 · Asia" ,
57+ displayDescription : "ダミー" ,
5758 areaText : "442 ha" ,
5859 bufferText : "320 ha" ,
5960 statePartyCodes : [ "日本" ] ,
@@ -63,48 +64,68 @@ describe("toWorldHeritageVm", () => {
6364 } ) ;
6465
6566 expect ( vm . criteria ) . toStrictEqual ( [ "ix" , "x" ] ) ;
67+ // 英名 (Shirakami-Sanchi) は日本語タイトル (白神山地) と異なるので併記対象
68+ expect ( vm . displaySubName ) . toBe ( "Shirakami-Sanchi" ) ;
6669 } ) ;
6770
68- it ( "if official_name is empty, uses name as title" , ( ) => {
69- const vm = toWorldHeritageVm ( { ...base , official_name : "" } ) ;
71+ it ( "en: title/country/description fall back to English fields" , ( ) => {
72+ const vm = toWorldHeritageVm ( base , "en" ) ;
73+
74+ expect ( vm . title ) . toBe ( "Shirakami-Sanchi" ) ;
75+ expect ( vm . country ) . toBe ( "Japan" ) ;
76+ expect ( vm . subtitle ) . toBe ( "Japan · Asia" ) ;
77+ expect ( vm . displayDescription ) . toBe ( "desc" ) ;
78+ expect ( vm . displaySubName ) . toBeNull ( ) ;
79+ } ) ;
80+
81+ it ( "ja: if official_name is empty, falls back to heritage_name_jp for title" , ( ) => {
82+ const vm = toWorldHeritageVm ( { ...base , official_name : "" } , "ja" ) ;
7083 expect ( vm . title ) . toBe ( "白神山地" ) ;
7184 } ) ;
7285
86+ it ( "ja: if Japanese description is missing, falls back to English short_description" , ( ) => {
87+ const vm = toWorldHeritageVm ( { ...base , short_description_jp : null } , "ja" ) ;
88+ expect ( vm . displayDescription ) . toBe ( "desc" ) ;
89+ } ) ;
90+
7391 it ( "when area/buffer are null, text becomes —" , ( ) => {
74- const vm = toWorldHeritageVm ( {
75- ...base ,
76- area_hectares : null ,
77- buffer_zone_hectares : null ,
78- } ) ;
92+ const vm = toWorldHeritageVm (
93+ {
94+ ...base ,
95+ area_hectares : null ,
96+ buffer_zone_hectares : null ,
97+ } ,
98+ "ja" ,
99+ ) ;
79100
80101 expect ( vm . areaText ) . toBe ( "—" ) ;
81102 expect ( vm . bufferText ) . toBe ( "—" ) ;
82103 } ) ;
83104
84105 it ( "when thumbnail is null, thumbnailUrl is null" , ( ) => {
85- const vm = toWorldHeritageVm ( { ...base , thumbnail : null } ) ;
106+ const vm = toWorldHeritageVm ( { ...base , thumbnail : null } , "ja" ) ;
86107 expect ( vm . thumbnailUrl ) . toBeNull ( ) ;
87108 } ) ;
88109
89110 it ( "input dto is immutable (criteria not mutated)" , ( ) => {
90111 const dto : ApiWorldHeritageDto = { ...base , criteria : [ "x" , "ix" , "ix" ] } ;
91112 const snapshot = [ ...dto . criteria ] ;
92113
93- const vm = toWorldHeritageVm ( dto ) ;
114+ const vm = toWorldHeritageVm ( dto , "ja" ) ;
94115
95116 expect ( dto . criteria ) . toStrictEqual ( snapshot ) ;
96117 expect ( vm . criteria ) . toStrictEqual ( [ "ix" , "x" ] ) ;
97118 } ) ;
98119
99120 it ( "unesco_site_url can be null (mapper should not crash)" , ( ) => {
100- const vm = toWorldHeritageVm ( { ...base , unesco_site_url : null } ) ;
121+ const vm = toWorldHeritageVm ( { ...base , unesco_site_url : null } , "ja" ) ;
101122 expect ( vm . unescoSiteUrl ) . toBeNull ( ) ;
102123 } ) ;
103124} ) ;
104125
105126describe ( "toWorldHeritageListVm" , ( ) => {
106127 it ( "maps dto array into view model array" , ( ) => {
107- const vms = toWorldHeritageListVm ( [ base , { ...base , id : 661 } ] ) ;
128+ const vms = toWorldHeritageListVm ( [ base , { ...base , id : 661 } ] , "ja" ) ;
108129 expect ( vms ) . toHaveLength ( 2 ) ;
109130 expect ( vms [ 0 ] . id ) . toBe ( 663 ) ;
110131 expect ( vms [ 1 ] . id ) . toBe ( 661 ) ;
0 commit comments