diff --git a/public/locales/de/status-effect.json b/public/locales/de/status-effect.json index c30d432fe79..bec1bf14b3f 100644 --- a/public/locales/de/status-effect.json +++ b/public/locales/de/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "None", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "None" }, "poison": { "name": "Gift", diff --git a/public/locales/en/status-effect.json b/public/locales/en/status-effect.json index fdbacfdb9be..64468047761 100644 --- a/public/locales/en/status-effect.json +++ b/public/locales/en/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "None", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "None" }, "poison": { "name": "Poison", diff --git a/public/locales/es/status-effect.json b/public/locales/es/status-effect.json index 66534d11983..9673a6a495b 100644 --- a/public/locales/es/status-effect.json +++ b/public/locales/es/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "Ninguno", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "Ninguno" }, "poison": { "name": "Envenenamiento", diff --git a/public/locales/fr/status-effect.json b/public/locales/fr/status-effect.json index bfb7121f522..13bcf59ef00 100644 --- a/public/locales/fr/status-effect.json +++ b/public/locales/fr/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "Aucun", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "Aucun" }, "poison": { "name": "Empoisonnement", diff --git a/public/locales/it/status-effect.json b/public/locales/it/status-effect.json index 6270bbb10a5..bbf96f2ec82 100644 --- a/public/locales/it/status-effect.json +++ b/public/locales/it/status-effect.json @@ -1,11 +1,5 @@ { "none": { - "name": "None", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "None" } } \ No newline at end of file diff --git a/public/locales/ja/status-effect.json b/public/locales/ja/status-effect.json index 8dafbbdcba7..14e8932a400 100644 --- a/public/locales/ja/status-effect.json +++ b/public/locales/ja/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "なし", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "なし" }, "poison": { "name": "どく", diff --git a/public/locales/ko/status-effect.json b/public/locales/ko/status-effect.json index d65243a8a24..489e67caaac 100644 --- a/public/locales/ko/status-effect.json +++ b/public/locales/ko/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "없음", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "없음" }, "poison": { "name": "독", diff --git a/public/locales/pt_BR/status-effect.json b/public/locales/pt_BR/status-effect.json index 9b33b9fa8f7..f3684128043 100644 --- a/public/locales/pt_BR/status-effect.json +++ b/public/locales/pt_BR/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "Nenhum", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "Nenhum" }, "poison": { "name": "Envenenamento", diff --git a/public/locales/zh_CN/status-effect.json b/public/locales/zh_CN/status-effect.json index f7fb9092107..c9d7073021c 100644 --- a/public/locales/zh_CN/status-effect.json +++ b/public/locales/zh_CN/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "无", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "无" }, "poison": { "name": "中毒", diff --git a/public/locales/zh_TW/status-effect.json b/public/locales/zh_TW/status-effect.json index 5f634a0bddf..29908593eef 100644 --- a/public/locales/zh_TW/status-effect.json +++ b/public/locales/zh_TW/status-effect.json @@ -1,12 +1,6 @@ { "none": { - "name": "無", - "description": "", - "obtain": "", - "obtainSource": "", - "activation": "", - "overlap": "", - "heal": "" + "name": "無" }, "poison": { "name": "中毒", diff --git a/src/data/status-effect.ts b/src/data/status-effect.ts index 4381db5c2c6..ffe32a02aeb 100644 --- a/src/data/status-effect.ts +++ b/src/data/status-effect.ts @@ -44,6 +44,10 @@ function getStatusEffectMessageKey(statusEffect: StatusEffect | undefined): stri } export function getStatusEffectObtainText(statusEffect: StatusEffect | undefined, pokemonNameWithAffix: string, sourceText?: string): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } + if (!sourceText) { const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.obtain`as ParseKeys; return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); @@ -53,21 +57,33 @@ export function getStatusEffectObtainText(statusEffect: StatusEffect | undefined } export function getStatusEffectActivationText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.activation` as ParseKeys; return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); } export function getStatusEffectOverlapText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.overlap` as ParseKeys; return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); } export function getStatusEffectHealText(statusEffect: StatusEffect, pokemonNameWithAffix: string): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.heal` as ParseKeys; return i18next.t(i18nKey, { pokemonNameWithAffix: pokemonNameWithAffix }); } export function getStatusEffectDescriptor(statusEffect: StatusEffect): string { + if (statusEffect === StatusEffect.NONE) { + return ""; + } const i18nKey = `${getStatusEffectMessageKey(statusEffect)}.description` as ParseKeys; return i18next.t(i18nKey); } diff --git a/src/test/data/status-effect.test.ts b/src/test/data/status-effect.test.ts new file mode 100644 index 00000000000..bca3bd21c70 --- /dev/null +++ b/src/test/data/status-effect.test.ts @@ -0,0 +1,301 @@ +import { + StatusEffect, + getStatusEffectActivationText, + getStatusEffectDescriptor, + getStatusEffectHealText, + getStatusEffectObtainText, + getStatusEffectOverlapText, +} from "#app/data/status-effect"; +import { mockI18next } from "#test/utils/testUtils"; +import i18next from "i18next"; +import { afterEach, beforeAll, describe, expect, it, vi } from "vitest"; + +const pokemonName = "PKM"; +const sourceText = "SOURCE"; + +describe("status-effect", () => { + beforeAll(() => { + i18next.init(); + }); + + describe("NONE", () => { + const statusEffect = StatusEffect.NONE; + + it("should return the obtain text", () => { + mockI18next(); + + const text = getStatusEffectObtainText(statusEffect, pokemonName); + console.log("text:", text); + expect(text).toBe(""); + + const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); + expect(emptySourceText).toBe(""); + }); + + it("should return the source-obtain text", () => { + mockI18next(); + + const text = getStatusEffectObtainText(statusEffect, pokemonName, sourceText); + expect(text).toBe(""); + + const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); + expect(emptySourceText).toBe(""); + }); + + it("should return the activation text", () => { + mockI18next(); + const text = getStatusEffectActivationText(statusEffect, pokemonName); + expect(text).toBe(""); + }); + + it("should return the overlap text", () => { + mockI18next(); + const text = getStatusEffectOverlapText(statusEffect, pokemonName); + expect(text).toBe(""); + }); + + it("should return the heal text", () => { + mockI18next(); + const text = getStatusEffectHealText(statusEffect, pokemonName); + expect(text).toBe(""); + }); + + it("should return the descriptor", () => { + mockI18next(); + const text = getStatusEffectDescriptor(statusEffect); + expect(text).toBe(""); + }); + }); + + describe("POISON", () => { + const statusEffect = StatusEffect.POISON; + + it("should return the obtain text", () => { + mockI18next(); + + const text = getStatusEffectObtainText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:poison.obtain"); + + const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); + expect(emptySourceText).toBe("statusEffect:poison.obtain"); + }); + + it("should return the activation text", () => { + mockI18next(); + const text = getStatusEffectActivationText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:poison.activation"); + }); + + it("should return the descriptor", () => { + mockI18next(); + const text = getStatusEffectDescriptor(statusEffect); + expect(text).toBe("statusEffect:poison.description"); + }); + + it("should return the heal text", () => { + mockI18next(); + const text = getStatusEffectHealText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:poison.heal"); + }); + + it("should return the overlap text", () => { + mockI18next(); + const text = getStatusEffectOverlapText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:poison.overlap"); + }); + }); + + describe("TOXIC", () => { + const statusEffect = StatusEffect.TOXIC; + + it("should return the obtain text", () => { + mockI18next(); + + const text = getStatusEffectObtainText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:toxic.obtain"); + + const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); + expect(emptySourceText).toBe("statusEffect:toxic.obtain"); + }); + + it("should return the activation text", () => { + mockI18next(); + const text = getStatusEffectActivationText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:toxic.activation"); + }); + + it("should return the descriptor", () => { + mockI18next(); + const text = getStatusEffectDescriptor(statusEffect); + expect(text).toBe("statusEffect:toxic.description"); + }); + + it("should return the heal text", () => { + mockI18next(); + const text = getStatusEffectHealText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:toxic.heal"); + }); + + it("should return the overlap text", () => { + mockI18next(); + const text = getStatusEffectOverlapText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:toxic.overlap"); + }); + }); + + describe("PARALYSIS", () => { + const statusEffect = StatusEffect.PARALYSIS; + + it("should return the obtain text", () => { + mockI18next(); + + const text = getStatusEffectObtainText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:paralysis.obtain"); + + const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); + expect(emptySourceText).toBe("statusEffect:paralysis.obtain"); + }); + + it("should return the activation text", () => { + mockI18next(); + const text = getStatusEffectActivationText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:paralysis.activation"); + }); + + it("should return the descriptor", () => { + mockI18next(); + const text = getStatusEffectDescriptor(statusEffect); + expect(text).toBe("statusEffect:paralysis.description"); + }); + + it("should return the heal text", () => { + mockI18next(); + const text = getStatusEffectHealText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:paralysis.heal"); + }); + + it("should return the overlap text", () => { + mockI18next(); + const text = getStatusEffectOverlapText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:paralysis.overlap"); + }); + }); + + describe("SLEEP", () => { + const statusEffect = StatusEffect.SLEEP; + + it("should return the obtain text", () => { + mockI18next(); + + const text = getStatusEffectObtainText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:sleep.obtain"); + + const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); + expect(emptySourceText).toBe("statusEffect:sleep.obtain"); + }); + + it("should return the activation text", () => { + mockI18next(); + const text = getStatusEffectActivationText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:sleep.activation"); + }); + + it("should return the descriptor", () => { + mockI18next(); + const text = getStatusEffectDescriptor(statusEffect); + expect(text).toBe("statusEffect:sleep.description"); + }); + + it("should return the heal text", () => { + mockI18next(); + const text = getStatusEffectHealText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:sleep.heal"); + }); + + it("should return the overlap text", () => { + mockI18next(); + const text = getStatusEffectOverlapText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:sleep.overlap"); + }); + }); + + describe("FREEZE", () => { + const statusEffect = StatusEffect.FREEZE; + + it("should return the obtain text", () => { + mockI18next(); + + const text = getStatusEffectObtainText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:freeze.obtain"); + + const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); + expect(emptySourceText).toBe("statusEffect:freeze.obtain"); + }); + + it("should return the activation text", () => { + mockI18next(); + const text = getStatusEffectActivationText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:freeze.activation"); + }); + + it("should return the descriptor", () => { + mockI18next(); + const text = getStatusEffectDescriptor(statusEffect); + expect(text).toBe("statusEffect:freeze.description"); + }); + + it("should return the heal text", () => { + mockI18next(); + const text = getStatusEffectHealText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:freeze.heal"); + }); + + it("should return the overlap text", () => { + mockI18next(); + const text = getStatusEffectOverlapText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:freeze.overlap"); + }); + }); + + describe("BURN", () => { + const statusEffect = StatusEffect.BURN; + + it("should return the obtain text", () => { + mockI18next(); + + const text = getStatusEffectObtainText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:burn.obtain"); + + const emptySourceText = getStatusEffectObtainText(statusEffect, pokemonName, ""); + expect(emptySourceText).toBe("statusEffect:burn.obtain"); + }); + + it("should return the activation text", () => { + mockI18next(); + const text = getStatusEffectActivationText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:burn.activation"); + }); + + it("should return the descriptor", () => { + mockI18next(); + const text = getStatusEffectDescriptor(statusEffect); + expect(text).toBe("statusEffect:burn.description"); + }); + + it("should return the heal text", () => { + mockI18next(); + const text = getStatusEffectHealText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:burn.heal"); + }); + + it("should return the overlap text", () => { + mockI18next(); + const text = getStatusEffectOverlapText(statusEffect, pokemonName); + expect(text).toBe("statusEffect:burn.overlap"); + }); + }); + + afterEach(() => { + vi.resetAllMocks(); + }); +});