-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
93 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Example user template template | ||
### Example user template | ||
|
||
# IntelliJ project files | ||
.idea | ||
*.iml | ||
out | ||
gen | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 62 additions & 42 deletions
104
frontend/mvc/view/Painter.spec.js → frontend/mvc/view/View.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,126 @@ | ||
/* global assert */ | ||
import Model from '../model/Model'; | ||
import View from './View'; | ||
|
||
import Board from '../model/Board'; | ||
import Painter from './Painter'; | ||
|
||
describe('Представление', function () { | ||
describe('Представление', () => { | ||
// вставка html в контроллере | ||
// const div = document.createElement('div'); | ||
// div.insertAdjacentHTML('beforeEnd', '<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></div><div class="container"><div class="label">speed</div><div class="slider slider-mix"><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="container"><div class="label">width</div><div class="slider slider-mix"><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="container"><div class="label">height</div><div class="slider slider-mix"><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="container"><div class="status"></div></div></div></div>'); | ||
// document.body.appendChild(div); | ||
describe('painter', function () { | ||
const table = document.createElement('table'); | ||
const board = new Board(5, 5); | ||
const painter = new Painter(board, table); | ||
board.setCell(1, 1); | ||
const tbody = painter.painter(400); | ||
it('создает и заполняет tbody в соостветсви с моделью', function () { | ||
assert.equal(tbody.children.length, 5, '5 строк'); | ||
assert.equal(tbody.children[0].children.length, 5, '5 столбцов'); | ||
const modelRows = 5; | ||
const modelColumns = 5; | ||
let model; | ||
let view; | ||
beforeEach(() => { | ||
model = new Model(modelRows, modelColumns); | ||
view = new View(model); | ||
}); | ||
describe('конструктор', () => { | ||
it('initDOMElements', () => { | ||
assert.equal(view.table, document.getElementById('board')); | ||
assert.equal(view.controls, document.getElementById('controls')); | ||
}); | ||
it('initEvents', () => { | ||
|
||
}); | ||
it('initHandlers', () => { | ||
|
||
}); | ||
it('сразу задает класс живым ячейкам', function () { | ||
it('initSubscription', () => { | ||
|
||
}); | ||
}); | ||
describe('getNewTbody', () => { | ||
it('создает и заполняет tbody в соостветсви с моделью', () => { | ||
console.log(0, view.table.children); | ||
console.dir(view); | ||
view.model.toggleCell(1, 1); | ||
console.log(1, view); | ||
const tbody = view.getNewTbody(view.model.matrix, 400); | ||
assert.equal(tbody.children.length, modelRows, '5 строк'); | ||
assert.equal(tbody.children[0].children.length, modelColumns, '5 столбцов'); | ||
}); | ||
it('сразу задает класс живым ячейкам', () => { | ||
view.model.toggleCell(1, 1); | ||
const tbody = view.getNewTbody(view.model.matrix, 400); | ||
assert.equal(tbody.children[1].children[1].className, 'live', 'класс живой клетки'); | ||
}); | ||
it('вычисляет ширину ячейки, в инлайн стили', function () { | ||
it('вычисляет ширину ячейки, в инлайн стили', () => { | ||
view.model.toggleCell(1, 1); | ||
const tbody = view.getNewTbody(view.model.matrix, 400); | ||
assert.equal(tbody.children[1].children[1].style.width, 400 / 5 + 'px', 'ширина'); | ||
assert.equal(tbody.children[1].children[1].style.height, 400 / 5 + 'px', 'высота'); | ||
}); | ||
}); | ||
describe('new table', function () { | ||
const table = document.createElement('table'); | ||
const board = new Board(6, 6); | ||
const painter = new Painter(board, table); | ||
board.setCell(1, 1); | ||
|
||
it('содает tbody, и вставляет в таблицу', function () { | ||
describe('initTable', () => { | ||
it('содает tbody, и вставляет в таблицу', () => { | ||
const { table } = view; | ||
assert.equal(table.children.length, 0, 'нет tbody'); | ||
painter.newTable(); | ||
view.model.setCell(1, 1); | ||
// view.initTable(); | ||
assert.equal(table.children.length, 1, 'появился tbody'); | ||
const tbody = table.children[0]; | ||
assert.equal(tbody.children.length, 6, '6 строк'); | ||
assert.equal(tbody.children[0].children.length, 6, '6 столбцов'); | ||
assert.equal(tbody.children[1].children[1].className, 'live', 'класс живой клетки'); | ||
}); | ||
it('заменяет tbody, если есть', function () { | ||
it('заменяет tbody, если есть', () => { | ||
board.setCell(1, 1); | ||
painter.newTable(); | ||
painter.initTable(); | ||
const tbody = table.children[0]; | ||
assert.equal(table.children.length, 1); | ||
assert.equal(tbody.children[1].children[1].className, '', 'класс живой клетки'); | ||
}); | ||
it('при ресайзе модели таблица тоже меняется', function () { | ||
it('при ресайзе модели таблица тоже меняется', () => { | ||
board.resize(8, 9); | ||
painter.newTable(); | ||
painter.initTable(); | ||
const tbody = table.children[0]; | ||
assert.equal(tbody.children.length, 8, '8 строк'); | ||
assert.equal(tbody.children[0].children.length, 9, '9 столбцов'); | ||
}); | ||
}); | ||
describe('repainter', function () { | ||
describe('repainter', () => { | ||
const table = document.createElement('table'); | ||
const board = new Board(5, 5); | ||
const painter = new Painter(board, table); | ||
board.setCell(1, 1); | ||
painter.newTable(); | ||
painter.repainter(); | ||
const tbody = table.children[0]; | ||
it('размер не меняет', function () { | ||
it('размер не меняет', () => { | ||
assert.equal(tbody.children.length, 5, '5 строк, размер не должен меняться'); | ||
assert.equal(tbody.children[0].children.length, 5, '5 столбцов, размер не должен меняться'); | ||
}); | ||
it('меняет класс существующих ячеек в соответствии с моделью', function () { | ||
it('меняет класс существующих ячеек в соответствии с моделью', () => { | ||
assert.equal(tbody.children[1].children[1].className, 'live', 'класс изменился'); | ||
}); | ||
}); | ||
describe('tableCellToggle', function () { | ||
describe('tableCellToggle', () => { | ||
const table = document.createElement('table'); | ||
const board = new Board(5, 5); | ||
const painter = new Painter(board, table); | ||
const td = document.createElement('td'); | ||
it('переключает класс', function () { | ||
it('переключает класс', () => { | ||
painter.tableCellToggle(td); | ||
assert.equal(td.classList[0], 'live'); | ||
}); | ||
it('переключает класс', function () { | ||
it('переключает класс', () => { | ||
painter.tableCellToggle(td); | ||
assert.equal(td.classList[0], undefined); | ||
}); | ||
}); | ||
describe('statusToggle', function () { | ||
describe('statusToggle', () => { | ||
const painter = new Painter(new Board(5, 5), document.createElement('table'), document.getElementById('controls')); | ||
const buttons = painter.buttons; | ||
const status = painter.controls.getElementsByClassName('status')[0]; | ||
it('start', function () { | ||
it('start', () => { | ||
painter.statusToggle(false); | ||
assert.equal(buttons[0].disabled, false, 'start button'); | ||
assert.equal(buttons[1].disabled, true, 'pause button'); | ||
assert.equal(status.classList[1], 'status_stopped') | ||
assert.equal(status.classList[1], 'status_stopped'); | ||
}); | ||
it('pause', function () { | ||
it('pause', () => { | ||
painter.statusToggle(true); | ||
assert.equal(buttons[0].disabled, true, 'start button'); | ||
assert.equal(buttons[1].disabled, false, 'pause button'); | ||
assert.equal(status.classList[1], undefined) | ||
assert.equal(status.classList[1], undefined); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters