60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
import { PADDLE_WIDE_WIDTH } from '../../config';
|
|
import { Perk } from '../../entities/perk/perk';
|
|
import { Game } from '../../game';
|
|
import { updatePerks } from './updatePerks';
|
|
|
|
describe('updatePerks', () => {
|
|
it('Возвращает корректное значение при неверных типах аргументов', () => {
|
|
const game = new Game([[[1]]]);
|
|
|
|
expect(updatePerks(null, 100, 1)).toBeNull();
|
|
expect(updatePerks(game, null, 1)).toBeNull();
|
|
expect(updatePerks(game, -1, 1)).toBeNull();
|
|
expect(updatePerks(game, 100, null)).toBeNull();
|
|
expect(updatePerks(game, 100, -1)).toBeNull();
|
|
});
|
|
|
|
it('Двигает бонус вниз в зависимости от времени', () => {
|
|
const game = new Game([[[1]]]);
|
|
const perk = new Perk(500, 10, 10, 10, 'slow', 3);
|
|
game.perks.push(perk);
|
|
|
|
updatePerks(game, 600, 1);
|
|
|
|
expect(perk.y).toBe(13);
|
|
expect(game.perks).toContain(perk);
|
|
});
|
|
|
|
it('Ловит бонус ракеткой, применяет эффект и убирает его', () => {
|
|
const game = new Game([[[1]]]);
|
|
const speedBefore = game.ball.speed;
|
|
const { paddle } = game;
|
|
game.perks.push(new Perk(paddle.x, paddle.y - 1, 10, 10, 'slow', 0));
|
|
|
|
updatePerks(game, 600, 1);
|
|
|
|
expect(game.perks).toHaveLength(0);
|
|
expect(game.ball.speed).toBeLessThan(speedBefore);
|
|
});
|
|
|
|
it('Ловит бонус wide, расширяет ракетку до фиксированной ширины', () => {
|
|
const game = new Game([[[1]]]);
|
|
const { paddle } = game;
|
|
game.perks.push(new Perk(paddle.x, paddle.y - 1, 10, 10, 'wide', 0));
|
|
|
|
updatePerks(game, 600, 1);
|
|
|
|
expect(game.perks).toHaveLength(0);
|
|
expect(paddle.width).toBe(PADDLE_WIDE_WIDTH);
|
|
});
|
|
|
|
it('Убирает бонус, улетевший за нижнюю границу', () => {
|
|
const game = new Game([[[1]]]);
|
|
game.perks.push(new Perk(0, 601, 10, 10, 'slow', 0));
|
|
|
|
updatePerks(game, 600, 1);
|
|
|
|
expect(game.perks).toHaveLength(0);
|
|
});
|
|
});
|