From 75dcd486d5bd06f6e58f56fdc05aea85884746f9 Mon Sep 17 00:00:00 2001
From: hollum <hollum@hotmail.com>
Date: Sun, 20 Mar 2022 19:07:23 +0100
Subject: [PATCH] black box testing for FR5

---
 frontend/cypress/integration/FR5.spec.js      | 62 +++++++++++++++++++
 frontend/cypress/integration/exercise.spec.js | 22 +++++++
 frontend/cypress/integration/first.spec.js    | 33 ----------
 frontend/cypress/integration/goals.spec.js    | 42 ++++++++++---
 frontend/cypress/integration/profile.spec.js  |  7 ++-
 frontend/cypress/integration/register.spec.js | 26 ++++----
 frontend/www/goals.html                       |  2 +-
 frontend/www/scripts/defaults.js              |  2 +-
 frontend/www/scripts/goals.js                 |  2 +-
 9 files changed, 139 insertions(+), 59 deletions(-)
 create mode 100644 frontend/cypress/integration/FR5.spec.js
 create mode 100644 frontend/cypress/integration/exercise.spec.js
 delete mode 100644 frontend/cypress/integration/first.spec.js

diff --git a/frontend/cypress/integration/FR5.spec.js b/frontend/cypress/integration/FR5.spec.js
new file mode 100644
index 0000000..4e18581
--- /dev/null
+++ b/frontend/cypress/integration/FR5.spec.js
@@ -0,0 +1,62 @@
+var baseUrl = "localhost:9090"
+
+describe('Black box testing', () => {
+    function logWorkout(workoutname, publicbool){
+        cy.get("#btn-create-workout").click();
+        cy.get('input[name="name"]').type(workoutname);
+        if(publicbool){
+            cy.get("#inputVisibility").select("Public");
+        }else{
+            cy.get("#inputVisibility").select("Private")
+        }
+        cy.get('input[name="date"]').click().then(input => {
+            input[0].dispatchEvent(new Event('input', { bubbles: true }))
+            input.val('2017-04-30T13:00')
+        }).click()
+        cy.get('#inputNotes').type('This is a note')
+        cy.get("#btn-ok-workout").click();
+    }
+
+
+    it('Logg personal workout and check if added in my list', function() {
+        this.login(this.athleteUser)
+        cy.get('#list-my-workouts-list').click();
+        cy.get('h5').contains('Public Workout');
+    })
+
+    it('Logg public personal and check if added', function() {
+        this.login(this.athleteUser)
+        cy.get('#list-public-workouts-list').click();
+        cy.get('h5').contains('Public Workout');
+    })
+
+    it('Logg public and check if added', function() {
+        this.login(this.athleteUser)
+        logWorkout("Public Workout", true);
+        cy.url().should('include', "/workouts.html");
+        cy.get('h5').contains('Public Workout')
+    })
+
+
+    it('See details of public workout', function() {
+        this.login(this.athleteUser)
+        cy.get('#list-public-workouts-list').click();
+        cy.get('h5').contains('Public Workout').parent().click();
+        cy.get('#inputName').should('be.visible');
+        cy.get('#inputNotes').should('be.visible');
+        cy.get('#customFile').should('be.visible');
+    })
+
+    it('User should not be able to see other private workouts', function() {
+        this.login(this.athleteUser)
+        logWorkout("Private Workout", false);
+        cy.get('#btn-logout', { timeout: 10000 }).click()
+        cy.wait(4000)
+        this.login(this.coachUser)
+        cy.wait(2000)
+        cy.get('h5').contains('Private Workout').should('not.exist');
+        cy.get('#list-public-workouts-list').click();
+        cy.get('h5').contains('Private Workout').should('not.exist');
+    })
+
+})
diff --git a/frontend/cypress/integration/exercise.spec.js b/frontend/cypress/integration/exercise.spec.js
new file mode 100644
index 0000000..136247a
--- /dev/null
+++ b/frontend/cypress/integration/exercise.spec.js
@@ -0,0 +1,22 @@
+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')
+
+        cy.get('#inputName', { timeout: 10000 }).type('Workout')
+        cy.get('#inputDescription').type('Description')
+        cy.get('#inputUnit').type('10')
+        cy.get('#inputDuration').type("-10")
+        cy.get('#inputCalories').type("-10")
+        cy.get('select[name="muscleGroup"]').eq(0).select('Legs', {force: true})
+
+        cy.intercept({method: 'POST', url: '/api/exercises/' }).as('createRequest')
+        cy.get('#btn-ok-exercise').click()
+        cy.wait('@createRequest')
+
+        cy.get('.alert').should('be.visible');
+    })
+
+})
diff --git a/frontend/cypress/integration/first.spec.js b/frontend/cypress/integration/first.spec.js
deleted file mode 100644
index 80d8730..0000000
--- a/frontend/cypress/integration/first.spec.js
+++ /dev/null
@@ -1,33 +0,0 @@
-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})
-    }
-
-})
diff --git a/frontend/cypress/integration/goals.spec.js b/frontend/cypress/integration/goals.spec.js
index e0708ff..e3307c7 100644
--- a/frontend/cypress/integration/goals.spec.js
+++ b/frontend/cypress/integration/goals.spec.js
@@ -7,8 +7,8 @@ const getDate = () => {
 
 //
 
-describe('Create goal', () => {
-    it('Go to goals', function() {
+describe('Check goals', () => {
+    it('Create goal', function() {
         this.login(this.athleteUser)
         cy.get('#nav-goals').click()
         cy.get('#btn-create-goal').click()
@@ -24,25 +24,49 @@ describe('Create goal', () => {
                 input.val('2017-04-30T13:00')
             })
             .click()
-        cy.intercept({method: 'POST', url: '/api/goal/' }).as('createRequest')
+       // cy.intercept({method: 'POST', url: '/api/goal/' }).as('createRequest')
         cy.get('#btn-ok-goal').click()
-        cy.wait('@createRequest')
+        cy.wait(1000)
+
+        cy.get('h2').eq(0).contains("GOAL_NAME")
+        //cy.wait('@createRequest')
         cy.url().should('include', 'goals.html')
     })
 
-
     it('Edit goal', function() {
         this.login(this.athleteUser)
         cy.get('#nav-goals').click()
         cy.get('.card-link')
             .eq(0).click()
 
-        cy.intercept({method: 'GET', url: '/api/goal/1/' }).as('createRequest')
-        cy.wait('@createRequest')
+        cy.get('#inputName', { timeout: 10000 }).type("_EDITED")
+
+
+
+        //cy.intercept({method: 'DELETE', url: '/api/goal/1/' }).as('createRequest')
+        cy.get('#btn-ok-goal').click()
+        cy.wait(1000)
+
+        cy.get('h2').eq(0).contains("GOAL_NAME_EDITED")
+
+    })
+
+
+    it('Delete goal', function() {
+        this.login(this.athleteUser)
+        cy.get('#nav-goals').click()
+        cy.get('.card-link')
+            .eq(0).click()
+
+        //cy.intercept({method: 'GET', url: '/api/goal/1/' }).as('createRequest')
+        //cy.wait('@createRequest')
+        cy.wait(1000)
+
 
-        cy.intercept({method: 'DELETE', url: '/api/goal/1/' }).as('createRequest')
+        //cy.intercept({method: 'DELETE', url: '/api/goal/1/' }).as('createRequest')
         cy.get('#btn-delete-goal').click()
-        cy.wait('@createRequest')
+        cy.wait(1000)
+        //cy.wait('@createRequest')
 
         cy.url().should('include', 'goals.html')
     })
diff --git a/frontend/cypress/integration/profile.spec.js b/frontend/cypress/integration/profile.spec.js
index 028f773..761aad7 100644
--- a/frontend/cypress/integration/profile.spec.js
+++ b/frontend/cypress/integration/profile.spec.js
@@ -6,9 +6,14 @@ describe('Test profile page', () => {
         this.login(this.athleteUser)
 
         cy.get('#nav-profile').click()
-        cy.get('#phone_number').type("12345678")
+        cy.get('#main_gym').type("SiT Moholt")
+        cy.get('#favourite_exercise').type("Cardio")
         cy.get('#btn-edit-account').click()
+        cy.wait(1000)
         cy.url().should('include', 'profile.html')
+
+        cy.get('#main_gym').should('have.value', 'SiT Moholt');
+        cy.get('#favourite_exercise').should('have.value', 'Cardio');
     })
 
 
diff --git a/frontend/cypress/integration/register.spec.js b/frontend/cypress/integration/register.spec.js
index 74f240e..d7eddbc 100644
--- a/frontend/cypress/integration/register.spec.js
+++ b/frontend/cypress/integration/register.spec.js
@@ -6,7 +6,7 @@ var baseUrl = "localhost:9090"
 /**
  * The only validation done in the frontend is thorugh email
  */
-const ThreeHundredChars = "tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 ";
+const HundredAndFiftyTwo = "tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 tdt4242 ";
 
 describe('boundary tests registration page', () => {
     beforeEach(() => {
@@ -25,16 +25,16 @@ describe('boundary tests registration page', () => {
 
     it('Test upper boundary limit', () => {
 
-        cy.get('input[name="username"]').type(ThreeHundredChars)
-        cy.get('input[name="email"]').type(ThreeHundredChars)
-        cy.get('input[name="password"]').type(ThreeHundredChars)
-        cy.get('input[name="password1"]').type(ThreeHundredChars)
-        cy.get('input[name="phone_number"]').type(ThreeHundredChars)
-        cy.get('input[name="country"]').type(ThreeHundredChars)
-        cy.get('input[name="city"]').type(ThreeHundredChars)
-        cy.get('input[name="street_address"]').type(ThreeHundredChars)
-        // cy.get('input[name="main_gym"]').type(ThreeHundredChars)
-        // cy.get('input[name="favourite_exercise"]').type(ThreeHundredChars)
+        cy.get('input[name="username"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="email"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="password"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="password1"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="phone_number"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="country"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="city"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="street_address"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="main_gym"]').type(HundredAndFiftyTwo)
+        cy.get('input[name="favourite_exercise"]').type(HundredAndFiftyTwo)
 
 
         cy.get('#btn-create-account').click()
@@ -46,8 +46,8 @@ describe('boundary tests registration page', () => {
         cy.get('li').contains('country').children('ul').children('li').contains("Ensure this field has no more than 50 characters.")
         cy.get('li').contains('city').children('ul').children('li').contains("Ensure this field has no more than 50 characters.")
         cy.get('li').contains('street_address').children('ul').children('li').contains("Ensure this field has no more than 50 characters.")
-        // cy.get('li').contains('main_gym').children('ul').children('li').contains("Ensure this field has no more than 50 characters.")
-        // cy.get('li').contains('favourite_exercise').children('ul').children('li').contains("Ensure this field has no more than 50 characters.")
+        cy.get('li').contains('main_gym').children('ul').children('li').contains("Ensure this field has no more than 50 characters.")
+        cy.get('li').contains('favourite_exercise').children('ul').children('li').contains("Ensure this field has no more than 50 characters.")
 
     });
 
diff --git a/frontend/www/goals.html b/frontend/www/goals.html
index 5acb9e3..b56e608 100644
--- a/frontend/www/goals.html
+++ b/frontend/www/goals.html
@@ -25,7 +25,7 @@
 
 
 
-  <template id="template-exercise">
+  <template id="template-goals">
     <div class="card ml-1" style="width: 24rem;">
       <div class="card-body">
         <h2 class="card-title" ></h2>
diff --git a/frontend/www/scripts/defaults.js b/frontend/www/scripts/defaults.js
index f09e5b1..5adc962 100644
--- a/frontend/www/scripts/defaults.js
+++ b/frontend/www/scripts/defaults.js
@@ -1 +1 @@
-const HOST = "http://localhost:8000";
+const HOST = "http://localhost:9090";
diff --git a/frontend/www/scripts/goals.js b/frontend/www/scripts/goals.js
index a4b86cc..a01bfdb 100644
--- a/frontend/www/scripts/goals.js
+++ b/frontend/www/scripts/goals.js
@@ -6,7 +6,7 @@ async function fetchExerciseTypes(request) {
 
         let goals = data.results;
         let container = document.getElementById('div-content');
-        let exerciseTemplate = document.querySelector("#template-exercise");
+        let exerciseTemplate = document.querySelector("#template-goals");
         goals.forEach(goal => {
             const exerciseAnchor = exerciseTemplate.content.firstElementChild.cloneNode(true);
             exerciseAnchor.href = `goal.html?id=${goal.id}`;
-- 
GitLab