forked from mate-academy/js_2048_game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs2048Game.spec.js
62 lines (50 loc) · 1.91 KB
/
js2048Game.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
Cypress.Commands.add('shuffleBoxes', (arrow1, arrow2, times) => {
cy.get('.button.start').click();
for (let n = 0; n < times; n++) {
cy.get('body').type(arrow1);
cy.get('body').type(arrow2);
}
});
describe('2048 game', () => {
beforeEach(() => {
cy.visit('/');
});
it('should show the initial score', () => {
cy.get('.button.start').click();
cy.get('.game-score').should('have.value', '');
});
it('should show the score shuffling to the left and up only', () => {
cy.shuffleBoxes('{leftArrow}', '{upArrow}', 3);
cy.get('.game-score').invoke('text').then(parseFloat).should('be.gt', 1);
});
it('should show the score shuffling to the right and up only', () => {
cy.shuffleBoxes('{rightArrow}', '{upArrow}', 3);
cy.get('.game-score').invoke('text').then(parseFloat).should('be.gt', 1);
});
it('should show the score shuffling to the right and down only', () => {
cy.shuffleBoxes('{rightArrow}', '{downArrow}', 3);
cy.get('.game-score').invoke('text').then(parseFloat).should('be.gt', 1);
});
it('should show the score shuffling to the left and down only', () => {
cy.shuffleBoxes('{leftArrow}', '{downArrow}', 3);
cy.get('.game-score').invoke('text').then(parseFloat).should('be.gt', 1);
});
it('should reset the score', () => {
cy.shuffleBoxes('{leftArrow}', '{downArrow}', 3);
cy.get('.game-score').invoke('text').then(parseFloat).should('be.gt', 1);
cy.get('.button.restart').click();
cy.get('.game-score').should('have.value', '');
});
it('should show message in case of the loss', () => {
cy.get('.button.start').click();
for (let n = 0; n < 100; n++) {
cy.get('body').type('{rightArrow}');
cy.get('body').type('{downArrow}');
cy.get('body').type('{leftArrow}');
cy.get('body').type('{upArrow}');
}
cy.contains('You lose! Restart the game?')
.should('be.visible');
});
});