pokerogue/test/data/splash_messages.test.ts
damocleas 19c61a041f
[Misc] New Splash Texts, March 2025 (#5345)
* Update splash-messages.ts 1

* Add Pokemon name splash text

This will display a random Pokemon's name, followed by an exclamation point (ex. "Bulbasaur!").

* Make Pokemon name splash message weighted

* Update splash-messages.ts

* Update splash-messages.ts

* fix trailing spaces

* Update splash-messages.ts

* Update splash-messages.ts

* Add splashes which use random Pokemon

* Update splash message tests

* Update splash-messages.ts

* Update splash-messages.ts

* Missing comma

* Fix length on test

It even says to do so whenever weight multipliers are adjusted...

* Update splash-messages.ts

* add missing prefix thing

* adjusted comment in splash_messages.test.ts

* Update splash-messages.ts

* fix blank line

* Add gender splash message code

This makes the specific April Fools splash message functional.
Also fixed a linter issue with the randomPokemon code.

* Update title-ui-handler.ts changed battles won fallback number to -1

* Update splash-messages.ts

* changed afd to 2 days

* Update splash_messages.test.ts

* Update src/data/splash-messages.ts

Co-authored-by: Jannik Tappert <38758606+CodeTappert@users.noreply.github.com>

---------

Co-authored-by: Madmadness65 <blaze.the.fireman@gmail.com>
Co-authored-by: Madmadness65 <59298170+Madmadness65@users.noreply.github.com>
Co-authored-by: Jannik Tappert <38758606+CodeTappert@users.noreply.github.com>
2025-03-27 19:56:26 -07:00

75 lines
2.7 KiB
TypeScript

import { getSplashMessages } from "#app/data/splash-messages";
import { describe, expect, it, vi, afterEach, beforeEach } from "vitest";
import * as Constants from "#app/constants";
describe("Data - Splash Messages", () => {
it("should contain at least 15 splash messages", () => {
expect(getSplashMessages().length).toBeGreaterThanOrEqual(15);
});
// Make sure to adjust this test if the weight is changed!
it("should add contain 15 `battlesWon` splash messages", () => {
const battlesWonMessages = getSplashMessages().filter((message) => message === "splashMessages:battlesWon");
expect(battlesWonMessages).toHaveLength(15);
});
describe("Seasonal", () => {
beforeEach(() => {
vi.spyOn(Constants, "USE_SEASONAL_SPLASH_MESSAGES", "get").mockReturnValue(true);
});
afterEach(() => {
vi.useRealTimers(); // reset system time
});
it("should contain new years messages from Jan 1 to Jan 15", () => {
testSeason(new Date("2025-01-01"), new Date("2025-01-15"), "newYears");
});
it("should contain valentines messages from Feb 7 to Feb 21", () => {
testSeason(new Date("2025-02-07"), new Date("2025-02-21"), "valentines");
});
it("should contain april fools messages from April 1 to April 3", () => {
testSeason(new Date("2025-04-01"), new Date("2025-04-03"), "aprilFools");
});
it("should contain halloween messages from Oct 15 to Oct 31", () => {
testSeason(new Date("2025-10-15"), new Date("2025-10-31"), "halloween");
});
it("should contain winter holiday messages from Dec 1 to Dec 31", () => {
testSeason(new Date("2025-12-01"), new Date("2025-12-31"), "winterHoliday");
});
});
});
/**
* Helpoer method to test seasonal messages
* @param startDate The seasons start date
* @param endDate The seasons end date
* @param prefix the splash message prefix (e.g. `newYears` or `xmas`)
*/
function testSeason(startDate: Date, endDate: Date, prefix: string) {
const filterFn = (message: string) => message.startsWith(`splashMessages:${prefix}.`);
const beforeDate = new Date(startDate);
beforeDate.setDate(startDate.getDate() - 1);
const afterDate = new Date(endDate);
afterDate.setDate(endDate.getDate() + 1);
const dates: Date[] = [beforeDate, startDate, endDate, afterDate];
const [before, start, end, after] = dates.map(date => {
vi.setSystemTime(date);
console.log("System time set to", date);
const count = getSplashMessages().filter(filterFn).length;
return count;
});
expect(before).toBe(0);
expect(start).toBeGreaterThanOrEqual(10); // make sure to adjust if weight is changed!
expect(end).toBeGreaterThanOrEqual(10); // make sure to adjust if weight is changed!
expect(after).toBe(0);
}