From a0544902fc333c6ed2f5afff9ac840260e9ebdf4 Mon Sep 17 00:00:00 2001 From: mariusz-sm <74978639+mariusz-sm@users.noreply.github.com> Date: Mon, 15 Feb 2021 17:17:10 +0100 Subject: [PATCH] MNG-119 Add_player_class_tests (#41) * Add test for too long name * Add test for too many pokemons * Add test for useMango * Add test for addPokemon function --- src/__tests__/playerClass.spec.ts | 81 +++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/__tests__/playerClass.spec.ts diff --git a/src/__tests__/playerClass.spec.ts b/src/__tests__/playerClass.spec.ts new file mode 100644 index 0000000..c665c0f --- /dev/null +++ b/src/__tests__/playerClass.spec.ts @@ -0,0 +1,81 @@ +import { Player } from "../playerClass"; +import { Pokemon } from "../pokemonClass"; +import { PokemonFactory } from "../pokemonFactory"; +import * as data from "../../assets/poke_data.json"; + +describe("Test Player class", () => { + const pokeData = data.pokemons; + const factory = new PokemonFactory(pokeData); + + const player = (name: string, pokemons: Pokemon[]) => { + return new Player(name, pokemons) + }; + + it("Should throw error when player name is longer than 8", () => { + // Given + const name = "Elizabeth" + const pokemonList = [ + factory.getPokemonByName("bulbasaur"), + factory.getPokemonByName("charmander"), + factory.getPokemonByName("pikachu"), + ] + + // When + const playerWithTooLongName = () => player(name, pokemonList) + + // Then + expect(playerWithTooLongName).toThrow("Too long name") + }); + + it("Should throw error when list of pokemons is longer than 3", () => { + // Given + const name = "Mark" + const pokemonList = [ + factory.getPokemonByName("bulbasaur"), + factory.getPokemonByName("charmander"), + factory.getPokemonByName("pikachu"), + factory.getPokemonByName("squirtle") + ] + + // When + const playerWithTooMuchPokemens = () => player(name, pokemonList) + + // Then + expect(playerWithTooMuchPokemens).toThrow("Wrong number of pokemons") + }); + + it("Should throw error when player has not mango", () => { + // Given + const name = "Mark" + const pokemonList = [ + factory.getPokemonByName("bulbasaur"), + factory.getPokemonByName("charmander"), + factory.getPokemonByName("pikachu"), + ] + + // When + const playerOne = player(name, pokemonList) + const useMango = () => playerOne.useMango() + useMango() + + // Then + expect(useMango).toThrow("You cannot use mango. You use all mangos") + }); + + it("Checks if addPokemon function works", () => { + // Given + const name = "Mark" + const pokemonList = [ + factory.getPokemonByName("bulbasaur"), + factory.getPokemonByName("charmander") + ] + + // When + const playerOne = player(name, pokemonList) + playerOne.addPokemon(factory.getPokemonByName("squirtle")) + const numberOfPokemons = playerOne.pokemons.length + + // Then + expect(numberOfPokemons).toEqual(3) + }); +}); \ No newline at end of file