mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-12 19:32:17 +02:00
Add test for filtering by types
This commit is contained in:
parent
7dc0c4be83
commit
3d8b35dd6e
@ -11,6 +11,7 @@ import { allSpecies, getPokemonSpecies, type PokemonForm } from "#app/data/pokem
|
|||||||
import { Button } from "#enums/buttons";
|
import { Button } from "#enums/buttons";
|
||||||
import { DropDownColumn } from "#app/ui/filter-bar";
|
import { DropDownColumn } from "#app/ui/filter-bar";
|
||||||
import type PokemonSpecies from "#app/data/pokemon-species";
|
import type PokemonSpecies from "#app/data/pokemon-species";
|
||||||
|
import { PokemonType } from "#enums/pokemon-type";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all permutations of elements from an array
|
* Return all permutations of elements from an array
|
||||||
@ -82,6 +83,34 @@ describe("UI - Pokedex", () => {
|
|||||||
return speciesSet;
|
return speciesSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute a set of pokemon that have one of the specified type(s)
|
||||||
|
*
|
||||||
|
* Includes all forms of the pokemon
|
||||||
|
* @param types The types to filter for
|
||||||
|
*/
|
||||||
|
function getSpeciesWithType(...types: PokemonType[]): Set<Species> {
|
||||||
|
const speciesSet = new Set<Species>();
|
||||||
|
const tySet = new Set<PokemonType>(types);
|
||||||
|
|
||||||
|
// get the pokemon and its forms
|
||||||
|
outer: for (const pkmn of allSpecies) {
|
||||||
|
// @ts-ignore We know that type2 might be null.
|
||||||
|
if (tySet.has(pkmn.type1) || tySet.has(pkmn.type2)) {
|
||||||
|
speciesSet.add(pkmn.speciesId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const form of pkmn.forms) {
|
||||||
|
// @ts-ignore We know that type2 might be null.
|
||||||
|
if (tySet.has(form.type1) || tySet.has(form.type2)) {
|
||||||
|
speciesSet.add(pkmn.speciesId);
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return speciesSet;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create mocks for the abilities of a species.
|
* Create mocks for the abilities of a species.
|
||||||
* This is used to set the abilities of a species to a specific value.
|
* This is used to set the abilities of a species to a specific value.
|
||||||
@ -207,6 +236,35 @@ describe("UI - Pokedex", () => {
|
|||||||
expect(whiteListCount).toBe(whitelist.length);
|
expect(whiteListCount).toBe(whitelist.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should filter to show only the pokemon with a type when filtering by a single type", async () => {
|
||||||
|
const pokedexHandler = await runToOpenPokedex();
|
||||||
|
|
||||||
|
// @ts-ignore filterBar is private
|
||||||
|
pokedexHandler.filterBar.getFilter(DropDownColumn.TYPES).toggleOptionState(PokemonType.NORMAL + 1);
|
||||||
|
|
||||||
|
const expectedPokemon = getSpeciesWithType(PokemonType.NORMAL);
|
||||||
|
// @ts-ignore private
|
||||||
|
const filteredPokemon = new Set(pokedexHandler.filteredPokemonData.map(pokemon => pokemon.species.speciesId));
|
||||||
|
|
||||||
|
expect(filteredPokemon).toEqual(expectedPokemon);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Todo: Pokemon with a mega that adds a type do not show up in the filter, e.g. pinsir.
|
||||||
|
it.todo("should show only the pokemon with one of the types when filtering by multiple types", async () => {
|
||||||
|
const pokedexHandler = await runToOpenPokedex();
|
||||||
|
|
||||||
|
// @ts-ignore filterBar is private
|
||||||
|
pokedexHandler.filterBar.getFilter(DropDownColumn.TYPES).toggleOptionState(PokemonType.NORMAL + 1);
|
||||||
|
// @ts-ignore filterBar is private
|
||||||
|
pokedexHandler.filterBar.getFilter(DropDownColumn.TYPES).toggleOptionState(PokemonType.FLYING + 1);
|
||||||
|
|
||||||
|
const expectedPokemon = getSpeciesWithType(PokemonType.NORMAL, PokemonType.FLYING);
|
||||||
|
// @ts-ignore private
|
||||||
|
const filteredPokemon = new Set(pokedexHandler.filteredPokemonData.map(pokemon => pokemon.species.speciesId));
|
||||||
|
|
||||||
|
expect(filteredPokemon).toEqual(expectedPokemon);
|
||||||
|
});
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
* Tests for UI Input *
|
* Tests for UI Input *
|
||||||
****************************/
|
****************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user