Skip to content

Commit

Permalink
поправил тесты
Browse files Browse the repository at this point in the history
  • Loading branch information
Geksanit committed Feb 1, 2018
1 parent 64fa6cd commit fd9c5cb
Show file tree
Hide file tree
Showing 7 changed files with 2,815 additions and 373 deletions.
22 changes: 11 additions & 11 deletions build/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 32 additions & 26 deletions build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,45 @@
<main>
<h1>Игра «Жизнь»</h1>
<div class="game">
<table id="board"></table>
<div id="controls">
<div class="container">
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small button-mix">start</button>
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small button-mix">pause</button>
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small button-mix">clear</button>
<table class="js-game__board game__board"></table>
<div class="js-game__controls game__controls">
<div class="game__container">
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small game__button js-game__button-start">start</button>
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small game__button js-game__button-pause">pause</button>
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small game__button js-game__button-clear">clear</button>
</div>
<div class="container">
<div class="label">speed</div>
<div class="slider slider_color_undefined slider-mix">
<div class="slider__view">1</div>
<div class="slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="1" max="10" value="1">
<div class="game__container">
<div class="game__label">speed</div>
<div class="game__slider">
<div class="slider slider_color_undefined js-game__slider-speed">
<div class="slider__view js-slider__view">1</div>
<div class="slider__line js-slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="1" max="10" value="1">
</div>
</div>
</div>
<div class="container">
<div class="label">width</div>
<div class="slider slider_color_undefined slider-mix">
<div class="slider__view">10</div>
<div class="slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="0" max="100" value="10">
<div class="game__container">
<div class="game__label">width</div>
<div class="game__slider">
<div class="slider slider_color_undefined js-game__slider-width">
<div class="slider__view js-slider__view">10</div>
<div class="slider__line js-slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="1" max="100" value="10">
</div>
</div>
</div>
<div class="container">
<div class="label">height</div>
<div class="slider slider_color_undefined slider-mix">
<div class="slider__view">10</div>
<div class="slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="0" max="100" value="10">
<div class="game__container">
<div class="game__label">height</div>
<div class="game__slider">
<div class="slider slider_color_undefined js-game__slider-height">
<div class="slider__view js-slider__view">10</div>
<div class="slider__line js-slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="1" max="100" value="10">
</div>
</div>
</div>
<div class="container">
<div class="status"></div>
<div class="game__container">
<div class="game__status js-game__status"></div>
</div>
</div>
</div>
Expand Down
2,795 changes: 2,603 additions & 192 deletions build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/components/standart-button/standart-button.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ mixin standart-button(options)
if (options.color !== 'blue' && options.color !== 'orange')
- options.color = 'blue'

button(disabled = options.disabled ? true : false class = "standart-button js-standart-button standart-button_color_" + options.color + " standart-button_size_" + options.size + " " + options.mix) #{options.title}
button(disabled = !!options.disabled class = "standart-button js-standart-button standart-button_color_" + options.color + " standart-button_size_" + options.size + " " + options.mix) #{options.title}
115 changes: 62 additions & 53 deletions frontend/mvc/controller/Controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,49 @@ describe('контроллер', () => {
let div: HTMLElement;
describe('подготовка к тестам, вставка html кода', () => {
div = document.createElement('div');
div.insertAdjacentHTML('beforeEnd', `<div class="game">
<table class="js-game__board"></table>
<div class="js-game__controls">
<div class="game__container">
<button class="js-game__button">start</button>
<button class="js-game__button">pause</button>
<button class="js-game__button">clear</button>
</div>
<div class="game__container">
<div class="game__label">speed</div>
<div class="game__slider">
<div class="slider__view">1</div>
<input class="slider__input js-slider__input" type="range" min="1" max="10" value="1">
</div>
</div>
<div class="game__container">
<div class="game__label">width</div>
<div class="game__slider">
<div class="slider__view">10</div>
<input class="slider__input js-slider__input" type="range" min="0" max="100" value="10">
</div>
</div>
<div class="game__container">
<div class="game__label">height</div>
<div class="game__slider">
<div class="slider__view">10</div>
<input class="slider__input js-slider__input" type="range" min="0" max="100" value="10">
</div>
</div>
<div class="game__container">
<div class="js-game__status"></div>
</div>
</div>
div.insertAdjacentHTML('beforeEnd', `
<div class="game">
<table class="js-game__board game__board"></table>
<div class="js-game__controls game__controls">
<div class="game__container">
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small game__button js-game__button-start">start</button>
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small game__button js-game__button-pause">pause</button>
<button class="standart-button js-standart-button standart-button_color_blue standart-button_size_small game__button js-game__button-clear">clear</button>
</div>
<div class="game__container">
<div class="game__label">speed</div>
<div class="game__slider">
<div class="slider slider_color_undefined js-game__slider-speed">
<div class="slider__view js-slider__view">1</div>
<div class="slider__line js-slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="1" max="10" value="1">
</div>
</div>
</div>
<div class="game__container">
<div class="game__label">width</div>
<div class="game__slider">
<div class="slider slider_color_undefined js-game__slider-width">
<div class="slider__view js-slider__view">10</div>
<div class="slider__line js-slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="1" max="100" value="10">
</div>
</div>
</div>
<div class="game__container">
<div class="game__label">height</div>
<div class="game__slider">
<div class="slider slider_color_undefined js-game__slider-height">
<div class="slider__view js-slider__view">10</div>
<div class="slider__line js-slider__line"></div>
<input class="slider__input js-slider__input" type="range" min="1" max="100" value="10">
</div>
</div>
</div>
<div class="game__container">
<div class="game__status js-game__status"></div>
</div>
</div>
</div>`);
document.body.appendChild(div);
it('проверка', () => {
Expand All @@ -56,25 +66,18 @@ describe('контроллер', () => {
});
describe('setRunning', () => {
it('сообщает вью отобразить статус true', () => {
const spy1: SinonStub = sinon.stub(controller.view, 'setButtons');
const spy2: SinonStub = sinon.stub(controller.view, 'setStatus');
const spy: SinonStub = sinon.stub(controller.view, 'setStatus');
controller.setRunning(true);
assert.strictEqual(controller.isRunning, true);
assert.isOk(true);
assert.isOk(spy1.calledWith(true));
assert.isOk(spy2.calledWith(true));
spy1.restore();
spy2.restore();
assert.isOk(spy.calledWith(true));
spy.restore();
});
it('сообщает вью отобразить статус false', () => {
const spy1: SinonStub = sinon.stub(controller.view, 'setButtons');
const spy2: SinonStub = sinon.stub(controller.view, 'setStatus');
const spy: SinonStub = sinon.stub(controller.view, 'setStatus');
controller.setRunning(false);
assert.strictEqual(controller.isRunning, false);
assert.isOk(spy1.calledWith(false));
assert.isOk(spy2.calledWith(false));
spy1.restore();
spy2.restore();
assert.isOk(spy.calledWith(false));
spy.restore();
});
});
describe('anim', () => {
Expand All @@ -101,7 +104,8 @@ describe('контроллер', () => {
describe('handleCell', () => {
it('вызывет соответствующий метод модели', () => {
const spy: SinonStub = sinon.stub(controller.model, 'toggleCell');
controller.handleCell({ row: 2, cell:1 });

controller.view.tableCellChanged.notify({ row: 2, cell:1 });
assert.isOk(spy.calledWith(2, 1));
spy.restore();
});
Expand All @@ -110,35 +114,39 @@ describe('контроллер', () => {
it('клик по кнопке start запускает цикл анимации', () => {
const spy: SinonStub = sinon.stub(controller, 'anim');
assert.equal(controller.isRunning, false, 'before false');
controller.handlerButtons({ nameButton: 'start' });

controller.view.startEvent.notify({});
assert.equal(controller.isRunning, true, 'after true');
assert.isOk(spy.called);
spy.restore();
});
it('клик по кнопке pause останавливает цикл анимации', () => {
assert.equal((controller.isRunning), true, 'before true');
controller.handlerButtons({ nameButton: 'pause' });

controller.view.pauseEvent.notify({});
assert.equal((controller.isRunning), false, 'after false');
});
it('клик по кнопке clear очищает матрицу модели и останавливает цикл анимации', () => {
const spy: SinonStub = sinon.stub(controller.model, 'clearMatrix');
controller.setRunning(true);
assert.equal((controller.isRunning), true, 'before true');
controller.handlerButtons({ nameButton: 'clear' });

controller.view.clearEvent.notify({});
assert.equal((controller.isRunning), false, 'after false');
assert.isOk(spy.called);
spy.restore();
});
});
describe('handleSliders', () => {
it('слайдер speed, регулирует частоту цикла анимации', () => {
controller.handlerSliders({ value: 5, nameSlider: 'speed' });
controller.view.speedChanged.notify({ value: 5 });
assert.equal(controller.fps, 5);
});
it('слайдер Width', () => {
const spy1: SinonStub = sinon.stub(controller.model, 'setWidthMatrix');
const spy2: SinonStub = sinon.stub(controller, 'setRunning');
controller.handlerSliders({ value: 16, nameSlider: 'width' });

controller.view.widthChanged.notify({ value: 16 });
assert.isOk(spy1.calledWith(16));
assert.isOk(spy2.calledWith(false));
spy1.restore();
Expand All @@ -147,7 +155,8 @@ describe('контроллер', () => {
it('слайдер Height', () => {
const spy1: SinonStub = sinon.stub(controller.model, 'setHeightMatrix');
const spy2: SinonStub = sinon.stub(controller, 'setRunning');
controller.handlerSliders({ value: 15, nameSlider: 'height' });

controller.view.heightChanged.notify({ value: 15 });
assert.isOk(spy1.calledWith(15));
assert.isOk(spy2.calledWith(false));
spy1.restore();
Expand Down
Loading

0 comments on commit fd9c5cb

Please sign in to comment.