From b16bd89f17c73b7886e502aed8ad5e8af0552112 Mon Sep 17 00:00:00 2001 From: ReneGV Date: Tue, 2 Jul 2024 19:54:59 -0600 Subject: [PATCH 1/2] [bug][ui] Fix eternatus candy count and display hatched egg count (#2761) * Display eternatus eggs * Trigger Build --- src/ui/starter-select-ui-handler.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index db014432b13..687f65281b4 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -2077,9 +2077,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonHatchedIcon, this.pokemonHatchedCountText ].map(c => c.setVisible(false)); - } else if (species.speciesId === Species.ETERNATUS) { - this.pokemonHatchedIcon.setVisible(false); - this.pokemonHatchedCountText.setVisible(false); + this.pokemonFormText.setY(25); } else { this.pokemonCaughtHatchedContainer.setY(25); this.pokemonShinyIcon.setY(117); @@ -2091,6 +2089,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.pokemonCandyCountText.setText(`x${this.scene.gameData.starterData[species.speciesId].candyCount}`); this.pokemonCandyCountText.setVisible(true); this.pokemonFormText.setVisible(true); + this.pokemonFormText.setY(42); this.pokemonHatchedIcon.setVisible(true); this.pokemonHatchedCountText.setVisible(true); From cc36cdb1a86b8d83e0b87396c46a42375d8ce0a8 Mon Sep 17 00:00:00 2001 From: flx-sta <50131232+flx-sta@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:00:44 -0700 Subject: [PATCH 2/2] [Tests] add unit tests for accounts (#2748) * add unit tests for accounts * only import from vitest (not node:test) * resolve comments * improve test coverage for accounts.updateUserInfo * add test coverage for account.initLoggedInUser() * code style improvements --- src/test/account.spec.ts | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/test/account.spec.ts diff --git a/src/test/account.spec.ts b/src/test/account.spec.ts new file mode 100644 index 00000000000..28e48ce9933 --- /dev/null +++ b/src/test/account.spec.ts @@ -0,0 +1,74 @@ +import * as battleScene from "#app/battle-scene.js"; +import { describe, expect, it, vi } from "vitest"; +import { initLoggedInUser, loggedInUser, updateUserInfo } from "../account"; +import * as utils from "../utils"; + +describe("account", () => { + describe("initLoggedInUser", () => { + it("should set loggedInUser to Guest and lastSessionSlot to -1", () => { + initLoggedInUser(); + + expect(loggedInUser.username).toBe("Guest"); + expect(loggedInUser.lastSessionSlot).toBe(-1); + }); + }); + + describe("updateUserInfo", () => { + it("should set loggedInUser to Guest if bypassLogin is true", async () => { + vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(true); + + const [success, status] = await updateUserInfo(); + + expect(success).toBe(true); + expect(status).toBe(200); + expect(loggedInUser.username).toBe("Guest"); + expect(loggedInUser.lastSessionSlot).toBe(-1); + }); + + it("should fetch user info from the API if bypassLogin is false", async () => { + vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(utils, "apiFetch").mockResolvedValue( + new Response( + JSON.stringify({ + username: "test", + lastSessionSlot: 99, + }), + { + status: 200, + } + ) + ); + + const [success, status] = await updateUserInfo(); + + expect(success).toBe(true); + expect(status).toBe(200); + expect(loggedInUser.username).toBe("test"); + expect(loggedInUser.lastSessionSlot).toBe(99); + }); + + it("should handle resolved API errors", async () => { + vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(utils, "apiFetch").mockResolvedValue( + new Response(null, { status: 401 }) + ); + + const [success, status] = await updateUserInfo(); + + expect(success).toBe(false); + expect(status).toBe(401); + }); + + it("should handle rejected API errors", async () => { + const consoleErrorSpy = vi.spyOn(console, "error"); + vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); + vi.spyOn(utils, "apiFetch").mockRejectedValue(new Error("Api failed!")); + + const [success, status] = await updateUserInfo(); + + expect(success).toBe(false); + expect(status).toBe(500); + expect(consoleErrorSpy).toHaveBeenCalled(); + }); + }); +});