diff --git a/cypress/e2e/game-loading.cy.js b/cypress/e2e/game-loading.cy.js index 27e7fc0..cd941ea 100644 --- a/cypress/e2e/game-loading.cy.js +++ b/cypress/e2e/game-loading.cy.js @@ -8,11 +8,13 @@ describe('the word is hidden when the game starts', () => { it('should display the word hidden with underscores', () => { cy.visit('/') .get('div.centered') + .get('div#word') .contains('_') .should('be.visible') cy.visit('/') .get('div.centered') + .get('div#word') .invoke('text') .should('match', /(_)+/) }) diff --git a/cypress/e2e/guesses.cy.js b/cypress/e2e/guesses.cy.js new file mode 100644 index 0000000..6692804 --- /dev/null +++ b/cypress/e2e/guesses.cy.js @@ -0,0 +1,57 @@ +it('asks for a character guess', () => { + cy.visit('/') + .get('div.centered') + .get('div.guess') + .get('div') + .contains("What's your next guess?") + .should('be.visible') + .next('div') + .get('input[type="text"]') + .next('button[type="button"]#confirmGuess') + .contains('Confirm') +}) + +describe('handles invalid characters', () => { + it('reports an error if guess is an invalid character', () => { + cy.visit('/') + .get('input.guess') + .type('1') + .get('button[type="button"]#confirmGuess') + .click() + .get('input.guess') + .should('have.css', 'border') + .should('include', '2px solid rgb(255, 0, 0)') + }) + + it('removes the error class when the user changes the input', () => { + cy.visit('/') + .get('input.guess') + .clear() + .should('not.have.css', 'border: 2px solid rgb(255, 0, 0)') + + cy.visit('/') + .get('input.guess') + .type('a') + .should('not.have.css', 'border: 2px solid rgb(255, 0, 0)') + }) +}) + +it('accepts valid guesses', () => { + let letter + + cy.visit('/') + .get('div#word > span:first-of-type') + .invoke('attr', 'x-data', '{ hidden:false }') + .invoke('attr', 'x-data', '{ hidden:true }') + .then(($el) => { + letter = $el.text() + cy.get('input.guess') + .type(letter) + }) + .invoke('attr', 'x-data', '{ hidden:true }') + .get('button[type="button"]#confirmGuess') + .click() + .get('div#word > span:first-of-type') + .should('have.attr', 'x-data', '{ hidden:false }') + .should('contain.text', letter) +}) diff --git a/index.html b/index.html index cf5d4bb..8af70b7 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,6 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> Hangman game - + -
- +
+
+ +
+
+
What's your next guess?
+
+ + +
+
+ +