1- import { translate } from "$lib/text/nbt_or_json" ;
1+ import { addTypeSpecificValues , translate } from "$lib/text/nbt_or_json" ;
2+ import type { MinecraftText , TranslateOptions } from "$lib/types" ;
3+ import type { JSONContent } from "@tiptap/core" ;
24import { describe , expect , it } from "vitest" ;
35import { readTestDataFile , readTestJSONFile } from "./test_utils" ;
4- import type { TranslateOptions } from "$lib/types" ;
5- import type { JSONContent } from "@tiptap/core" ;
66
77describe ( "translate" , ( ) => {
88 it ( "should return a basic string" , ( ) => {
@@ -193,3 +193,72 @@ describe("translate", () => {
193193 expect ( result ) . toBe ( "[]" ) ;
194194 } ) ;
195195} ) ;
196+
197+ describe ( "adding type props" , ( ) => {
198+ it ( "should add text property for type 'text'" , ( ) => {
199+ const current : MinecraftText = { } ;
200+ const c : JSONContent = { type : "text" , text : "hello" } ;
201+ const result = addTypeSpecificValues ( current , c , false ) ;
202+ expect ( result . text ) . toBe ( "hello" ) ;
203+ } ) ;
204+
205+ it ( "should add score property for type 'score'" , ( ) => {
206+ const current : MinecraftText = { } ;
207+ const c : JSONContent = {
208+ type : "score" ,
209+ attrs : { name : "player" , objective : "obj" } ,
210+ } ;
211+ const result = addTypeSpecificValues ( current , c , false ) ;
212+ expect ( result . score ) . toEqual ( { name : "player" , objective : "obj" } ) ;
213+ } ) ;
214+
215+ it ( "should add translate, with, and fallback for type 'translate'" , ( ) => {
216+ const current : MinecraftText = { } ;
217+ const c : JSONContent = {
218+ type : "translate" ,
219+ attrs : {
220+ key : "translation.key" ,
221+ params : [ "param1" , "param2" ] ,
222+ fallback : "fallback text" ,
223+ } ,
224+ } ;
225+ const result = addTypeSpecificValues ( current , c , false ) ;
226+ expect ( result . translate ) . toBe ( "translation.key" ) ;
227+ expect ( result . with ) . toEqual ( [ "param1" , "param2" ] ) ;
228+ expect ( result . fallback ) . toBe ( "fallback text" ) ;
229+ } ) ;
230+
231+ it ( "should add nbt, storage, block, entity, interpret for nbt types" , ( ) => {
232+ const current : MinecraftText = { } ;
233+ const c : JSONContent = {
234+ type : "storage_nbt" ,
235+ attrs : {
236+ nbt : "someNbt" ,
237+ storage : "someStorage" ,
238+ block : "someBlock" ,
239+ entity : "someEntity" ,
240+ interpret : true ,
241+ } ,
242+ } ;
243+ const result = addTypeSpecificValues ( current , c , false ) ;
244+ expect ( result . nbt ) . toBe ( "someNbt" ) ;
245+ expect ( result . storage ) . toBe ( "someStorage" ) ;
246+ expect ( result . block ) . toBe ( "someBlock" ) ;
247+ expect ( result . entity ) . toBe ( "someEntity" ) ;
248+ expect ( result . interpret ) . toBe ( true ) ;
249+ } ) ;
250+
251+ it ( "should add keybind property for type 'keybind'" , ( ) => {
252+ const current : MinecraftText = { } ;
253+ const c : JSONContent = { type : "keybind" , attrs : { key : "key.jump" } } ;
254+ const result = addTypeSpecificValues ( current , c , false ) ;
255+ expect ( result . keybind ) . toBe ( "key.jump" ) ;
256+ } ) ;
257+
258+ it ( "should add selector property for type 'selector'" , ( ) => {
259+ const current : MinecraftText = { } ;
260+ const c : JSONContent = { type : "selector" , attrs : { selector : "@a" } } ;
261+ const result = addTypeSpecificValues ( current , c , false ) ;
262+ expect ( result . selector ) . toBe ( "@a" ) ;
263+ } ) ;
264+ } ) ;
0 commit comments