From 1610dd9f1f54fd07a0774094b7d961cd68f53e3f Mon Sep 17 00:00:00 2001
From: hollum <hollum@hotmail.com>
Date: Thu, 10 Mar 2022 13:06:02 +0100
Subject: [PATCH] create exercise - automated test using cypress

---
 frontend/cypress/integration/first.spec.js | 34 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/frontend/cypress/integration/first.spec.js b/frontend/cypress/integration/first.spec.js
index 09febc7..0bbdf14 100644
--- a/frontend/cypress/integration/first.spec.js
+++ b/frontend/cypress/integration/first.spec.js
@@ -1,5 +1,33 @@
-describe("Simple test", () => {
-    it("Works", () => {
-        expect(true).to.equal(true)
+describe('Create exercise', () => {
+    it('Exercise creation', function() {
+        this.login(this.athleteUser)
+        cy.get('#nav-exercises').click()
+        cy.get('#btn-create-exercise').click()
+        cy.url().should('include', 'exercise.html')
+
+        typeIn(
+            'Workout',
+            'Description',
+            '10',
+            '10',
+            '10',
+            'Legs',
+        )
+        cy.intercept({method: 'POST', url: '/api/exercises/' }).as('createRequest')
+        cy.get('#btn-ok-exercise').click()
+        cy.wait('@createRequest')
+        // Successfully created exercise
+        cy.url().should('include', 'exercises.html')
     })
+
+
+    function typeIn(name, description, unit, duration, calories, muscleGroup) {
+        cy.get('#inputName', { timeout: 10000 }).type(name)
+        cy.get('#inputDescription').type(description)
+        cy.get('#inputUnit').type(unit)
+        cy.get('#inputDuration').type(duration)
+        cy.get('#inputCalories').type(calories)
+        cy.get('select[name="muscleGroup"]').eq(0).select(muscleGroup, {force: true})
+    }
+
 })
-- 
GitLab