Skip to content

Conversation

@eoL95
Copy link

@eoL95 eoL95 commented May 10, 2017

Copy link
Collaborator

@VasiliiKuznecov VasiliiKuznecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно сделать тесты независимыми

gameBoardElement.addEventListener('click', function (event) {
move(event.target.id);
if (checkWin()) {
document.querySelector('.game-victory').style.display = 'block';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше сделать через навешивание класса, у которого будет соотвествующее свойство

}

function printBoard() {
while (gameBoardElement.firstChild) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно, например, сделать gameBoardElement.innerHtml = ''


it('should initialize a game field', function () {
var gameCells = document.getElementsByClassName('game-cell');
chai.assert.equal(gameCells.length, 16);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно еще проверить, что числа разные и от 1 до 15

});

it('should move cell up', function () {
var gameBoardCopy = gameBoard.slice();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лезть в переменную, используемую в код плохо (если хотим поменять название, то надо менять и в тестах)
да и вообще, тесты не должны знать о внутренней логике кода

gameBoardCopy[4] = 0;
var cell = document.getElementById('4');
cell.click();
chai.assert.deepEqual(gameBoardCopy, gameBoard);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мы не это должны проверять, не то, что в памяти поменялось
в памяти то может и поменялась, но что отображается в интерфейсе при этом?
мы должны взять пустую ячейку, проверить, что она заполнилась правильным числом
должны взять ячейку, которую кликнули, проверить, что она стала пустой

cell.click();
chai.assert.deepEqual(gameBoardCopy, gameBoard);
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

еще нужна проверка на то, что если мы кликнем по ячейке далеко от пустой, ничего не произойдет

});

it('should move cell down', function () {
var gameBoardCopy = gameBoard.slice();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у тебя тесты сейчас зависят друг от друга, а надо чтобы были независимы, чтобы можно было отдельно запустить любой
поэтому в начале каждого теста надо создавать поле (можно создавать его с помощью массива значений, чтобы проверить конкретный случай)

});

it('should take message if player win', function () {
gameBoard = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 15];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

опять лезем во внутренности кода игры, не надо так делать, надо инициализировать поле заранее подготовленными числами

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants