Skip to content
Snippets Groups Projects
Commit c3780e15 authored by Runar Sæther's avatar Runar Sæther
Browse files

Merge branch '13-integration-tests' into 'master'

Resolve "Integration tests"

Closes #13

See merge request !16
parents da09d746 c9c7f229
No related branches found
No related tags found
1 merge request!16Resolve "Integration tests"
Pipeline #165568 passed with stages
in 36 seconds
Showing with 587 additions and 2 deletions
......@@ -4,5 +4,6 @@
"viewportWidth": 1920,
"viewportHeight": 1080,
"hideXHR": true,
"baseUrl": "http://localhost:3000/"
"baseUrl": "http://localhost:3000/",
"integrationFolder": "cypress/tests"
}
......@@ -127,6 +127,19 @@
"pk": 5,
"fields": { "workout": 4, "exercise": 1, "sets": 1, "number": 1 }
},
{
"model": "meals.meal",
"pk": 1,
"fields": {
"name": "user1 public",
"date": "2022-03-15T16:27:52Z",
"notes": "-",
"calories": 100,
"is_veg": false,
"owner": 1,
"visibility": "PU"
}
},
{
"model": "users.user",
"pk": 1,
......@@ -180,7 +193,7 @@
"pk": 3,
"fields": {
"password": "pbkdf2_sha256$216000$8eypiQmHCcOI$YtXyNQS6cWAvdxsSJ43mDSUhlwNv0zBAfrMUg7UpilQ=",
"last_login": "2022-03-14T20:51:34.298Z",
"last_login": "2022-03-16T19:24:53.129Z",
"is_superuser": true,
"username": "admin",
"first_name": "",
......@@ -222,5 +235,53 @@
"user_permissions": [],
"subscribers": []
}
},
{
"model": "users.user",
"pk": 6,
"fields": {
"password": "pbkdf2_sha256$216000$D1tukOvBpmfO$TBp+hGgYOpMB3jXrtM0DyY8zAhatkBHWao/xX7A91VE=",
"last_login": null,
"is_superuser": false,
"username": "user4",
"first_name": "",
"last_name": "",
"email": "user4@test.com",
"is_staff": false,
"is_active": true,
"date_joined": "2022-03-16T19:49:53.773Z",
"coach": null,
"phone_number": "",
"country": "",
"city": "",
"street_address": "",
"groups": [],
"user_permissions": [],
"subscribers": []
}
},
{
"model": "users.user",
"pk": 7,
"fields": {
"password": "pbkdf2_sha256$216000$P5c2knblxRJZ$M3lJoVU7ARotDxJrG1USE694NF8MYkbQqY/9GBnHeys=",
"last_login": null,
"is_superuser": false,
"username": "user5",
"first_name": "",
"last_name": "",
"email": "user5@test.com",
"is_staff": false,
"is_active": true,
"date_joined": "2022-03-16T19:50:42.456Z",
"coach": null,
"phone_number": "",
"country": "",
"city": "",
"street_address": "",
"groups": [],
"user_permissions": [],
"subscribers": [6]
}
}
]
......@@ -94,3 +94,70 @@ Cypress.Commands.add("workoutShouldNotBeVisibleOnWorkoutDetailPage", (id, title)
cy.get("#inputName").should("not.have.value", title);
cy.contains("Could not retrieve workout data!").should("be.visible");
});
Cypress.Commands.add("createWorkout", (name, date, notes, visibility, exerciseInstances) => {
cy.getCookie("access").then((cookie) => {
cy.request({
method: "POST",
url: "http://localhost:8000/api/workouts/",
headers: {
Authorization: `Bearer ${cookie.value}`
},
body: {
name: name,
date: date,
notes: notes,
visibility: visibility,
exercise_instances: exerciseInstances
}
}).then((response) => {
expect(response.status).to.eq(201);
});
});
});
Cypress.Commands.add(
"createExercise",
(name, description, unit, duration, calories, muscleGroup) => {
cy.getCookie("access").then((cookie) => {
cy.request({
method: "POST",
url: "http://localhost:8000/api/exercises/",
headers: {
Authorization: `Bearer ${cookie.value}`
},
body: {
name: name,
description: description,
unit: unit,
duration: duration,
calories: calories,
muscleGroup: muscleGroup
}
}).then((response) => {
expect(response.status).to.eq(201);
});
});
}
);
Cypress.Commands.add("createMeal", (name, date, visibility, notes, calories) => {
cy.getCookie("access").then((cookie) => {
cy.request({
method: "POST",
url: "http://localhost:8000/api/meals/",
headers: {
Authorization: `Bearer ${cookie.value}`
},
body: {
name: name,
date: date,
visibility: visibility,
notes: notes,
calories: calories
}
}).then((response) => {
expect(response.status).to.eq(201);
});
});
});
......@@ -14,6 +14,7 @@ describe("athlete workout visibility", () => {
const password = "user2";
before(() => {
cy.visit("index.html");
cy.clearCookies();
// Log in once before any tests run
......
......@@ -15,6 +15,7 @@ describe("coach workout visibility", () => {
const password = "user1";
before(() => {
cy.visit("index.html");
cy.clearCookies();
// Log in once before any tests run
......
......@@ -13,6 +13,7 @@ describe("visitor workout visibility", () => {
const password = "user3";
before(() => {
cy.visit("index.html");
cy.clearCookies();
// Log in once before any tests run
......
describe("notifications", () => {
// User credentials
const username = "user4";
const password = "user4";
before(() => {
cy.visit("index.html");
cy.clearCookies();
// Log in once before any tests run
cy.login(username, password);
});
beforeEach(() => {
// Before each test, preserve the access and refresh cookies (i.e. stay logged in)
Cypress.Cookies.preserveOnce("access", "refresh");
cy.window().then((win) => {
win.sessionStorage.setItem("username", username);
});
});
it("page loads", () => {
cy.visit("index.html");
cy.get(".navbar-nav").contains("Notifications").click();
cy.location("pathname").should("eq", "/notifications.html");
});
it("receive notifications when user you subscribe to posts content", () => {
// Check that no notifications are received
cy.visit("notifications.html");
cy.contains("You have no notifications").should("be.visible");
/**
* user4 subscribes to user5, so user4 should receive notifications when user5
* posts workouts, exercises and meals
*/
// Create workout
cy.login("user5", "user5");
cy.createWorkout("user5 workout", new Date(), "notes", "PU", [
{ exercise: "http://localhost:8000/api/exercises/1/", number: "10", sets: "10" }
]);
// Check if workout notification is received and points to correct workout
cy.login("user4", "user4");
cy.visit("index.html");
cy.get("#nav-notifications-count").should("be.visible"); // Check not read
cy.get("#nav-notifications-count").should("have.text", "1"); // Check not read
cy.visit("notifications.html");
cy.get("#notifications-container").find("a").should("have.length", 1);
cy.get("#notifications-container")
.contains("user5 posted a new workout: user5 workout")
.should("be.visible");
cy.get("#notifications-container")
.contains("user5 posted a new workout: user5 workout")
.should("have.class", "list-group-item-primary"); // Check not read
cy.get("#notifications-container")
.contains("user5 posted a new workout: user5 workout")
.click();
cy.get("#inputName").should("have.value", "user5 workout");
cy.get("#nav-notifications-count").should("not.be.visible"); // Check read
cy.visit("notifications.html");
cy.get("#notifications-container")
.contains("user5 posted a new workout: user5 workout")
.should("not.have.class", "list-group-item-primary"); // Check read
// Create exercise and meal
cy.login("user5", "user5");
cy.createExercise("user5 exercise", "desc", "reps", "10", "100", "Legs");
cy.createMeal("user5 meal", new Date(), "PU", "notes", "100");
// Check if exercise and meal notifications are received and point to correct exercise and meal
cy.login("user4", "user4");
cy.visit("index.html");
cy.get("#nav-notifications-count").should("be.visible"); // Check not read
cy.get("#nav-notifications-count").should("have.text", "2"); // Check not read
cy.visit("notifications.html");
cy.get("#notifications-container").find("a").should("have.length", 3);
cy.get("#notifications-container")
.contains("user5 posted a new exercise: user5 exercise")
.should("be.visible");
cy.get("#notifications-container")
.contains("user5 posted a new meal: user5 meal")
.should("be.visible");
cy.get("#notifications-container")
.contains("user5 posted a new exercise: user5 exercise")
.should("have.class", "list-group-item-primary"); // Check not read
cy.get("#notifications-container")
.contains("user5 posted a new meal: user5 meal")
.should("have.class", "list-group-item-primary"); // Check not read
cy.get("#notifications-container")
.contains("user5 posted a new exercise: user5 exercise")
.click();
cy.get("#inputName").should("have.value", "user5 exercise");
cy.go("back");
cy.get("#notifications-container").contains("user5 posted a new meal: user5 meal").click();
cy.get("#inputName").should("have.value", "user5 meal");
cy.get("#nav-notifications-count").should("not.be.visible"); // Check read
cy.visit("notifications.html");
cy.get("#notifications-container")
.contains("user5 posted a new exercise: user5 exercise")
.should("not.have.class", "list-group-item-primary"); // Check read
cy.get("#notifications-container")
.contains("user5 posted a new meal: user5 meal")
.should("not.have.class", "list-group-item-primary"); // Check read
});
});
describe("profile", () => {
// User credentials
const username = "user2";
const password = "user2";
before(() => {
cy.visit("index.html");
cy.clearCookies();
// Log in once before any tests run
cy.login(username, password);
});
beforeEach(() => {
// Before each test, preserve the access and refresh cookies (i.e. stay logged in)
Cypress.Cookies.preserveOnce("access", "refresh");
cy.window().then((win) => {
win.sessionStorage.setItem("username", username);
});
});
it("page loads", () => {
cy.visit("index.html");
cy.get(".navbar-nav").contains(`Profile (${username})`).click();
cy.location("pathname").should("eq", "/profile.html");
cy.location("search").should("eq", `?username=${username}`);
});
it("own profile content", () => {
cy.visit(`/profile.html?username=${username}`);
cy.get("#username").contains(username).should("be.visible");
cy.get("#button-user-subscribe").should("not.be.visible");
cy.get("#button-user-unsubscribe").should("not.be.visible");
// Test subsciber and subscriptions counts
cy.get("#subscribers").should("be.visible");
cy.get("#subscribers")
.invoke("text")
.should("match", /^[0-9]*$/);
cy.get("#subscriptions").should("be.visible");
cy.get("#subscriptions")
.invoke("text")
.should("match", /^[0-9]*$/);
// Test default content visible
cy.get("#workout-content").should("be.visible");
cy.get("#exercise-content").should("not.be.visible");
cy.get("#meal-content").should("not.be.visible");
// Test workouts list
cy.get("#list-tab").contains("Workouts").should("have.class", "active");
cy.get("#list-tab").contains("Exercises").should("not.have.class", "active");
cy.get("#list-tab").contains("Meals").should("not.have.class", "active");
cy.get("#workout-content").find("a").should("have.length", 1);
cy.get("#workout-content").contains("user2 public").click();
cy.location("pathname").should("eq", "/workout.html");
cy.location("search").should("eq", `?id=1`);
cy.go("back");
// Test exercises list
cy.get("#list-tab").contains("Exercises").click();
cy.get("#list-tab").contains("Workouts").should("not.have.class", "active");
cy.get("#list-tab").contains("Exercises").should("have.class", "active");
cy.get("#list-tab").contains("Meals").should("not.have.class", "active");
cy.get("#exercise-content").find("a").should("have.length", 2);
cy.get("#exercise-content").contains("Push-ups").click();
cy.location("pathname").should("eq", "/exercise.html");
cy.location("search").should("eq", `?id=1`);
cy.go("back");
// Test meals list
cy.get("#list-tab").contains("Meals").click();
cy.get("#list-tab").contains("Workouts").should("not.have.class", "active");
cy.get("#list-tab").contains("Exercises").should("not.have.class", "active");
cy.get("#list-tab").contains("Meals").should("have.class", "active");
cy.get("#meal-content").find("a").should("have.length", 0);
});
it("others profile content", () => {
cy.visit("/profile.html?username=user1");
cy.get("#username").contains("user1").should("be.visible");
cy.get("#button-user-subscribe").should("be.visible");
cy.get("#button-user-unsubscribe").should("not.be.visible");
// Test subsciber and subscriptions counts
cy.get("#subscribers").should("be.visible");
cy.get("#subscribers")
.invoke("text")
.should("match", /^[0-9]*$/);
cy.get("#subscriptions").should("be.visible");
cy.get("#subscriptions")
.invoke("text")
.should("match", /^[0-9]*$/);
// Test default content visible
cy.get("#workout-content").should("be.visible");
cy.get("#exercise-content").should("not.be.visible");
cy.get("#meal-content").should("not.be.visible");
// Test workouts list
cy.get("#list-tab").contains("Workouts").should("have.class", "active");
cy.get("#list-tab").contains("Exercises").should("not.have.class", "active");
cy.get("#list-tab").contains("Meals").should("not.have.class", "active");
cy.get("#workout-content").find("a").should("have.length", 1);
cy.get("#workout-content").contains("user1 public").click();
cy.location("pathname").should("eq", "/workout.html");
cy.location("search").should("eq", `?id=7`);
cy.go("back");
// Test exercises list
cy.get("#list-tab").contains("Exercises").click();
cy.get("#list-tab").contains("Workouts").should("not.have.class", "active");
cy.get("#list-tab").contains("Exercises").should("have.class", "active");
cy.get("#list-tab").contains("Meals").should("not.have.class", "active");
cy.get("#exercise-content").find("a").should("have.length", 0);
// Test meals list
cy.get("#list-tab").contains("Meals").click();
cy.get("#list-tab").contains("Workouts").should("not.have.class", "active");
cy.get("#list-tab").contains("Exercises").should("not.have.class", "active");
cy.get("#list-tab").contains("Meals").should("have.class", "active");
cy.get("#meal-content").find("a").should("have.length", 1);
cy.get("#meal-content").contains("user1 public").click();
cy.location("pathname").should("eq", "/meal.html");
cy.location("search").should("eq", `?id=1`);
cy.go("back");
});
});
describe("subscription", () => {
// User credentials
const username = "user2";
const password = "user2";
before(() => {
cy.visit("index.html");
cy.clearCookies();
// Log in once before any tests run
cy.login(username, password);
});
beforeEach(() => {
// Before each test, preserve the access and refresh cookies (i.e. stay logged in)
Cypress.Cookies.preserveOnce("access", "refresh");
cy.window().then((win) => {
win.sessionStorage.setItem("username", username);
});
});
it("subscribe to user", () => {
// Check user2's subscriptions count
cy.visit(`/profile.html?username=${username}`);
cy.get("#subscriptions").should("have.text", "0");
// Check user1's subscribers count
cy.visit("/profile.html?username=user1");
cy.get("#subscribers").should("have.text", "0");
// Subscribe to user1 and check increased subscribers count
cy.get("#button-user-subscribe").click();
cy.get("#button-user-subscribe").should("not.be.visible");
cy.get("#button-user-unsubscribe").should("be.visible");
cy.get("#subscribers").should("have.text", "1");
// Check increased subscriptions count for user2
cy.visit(`/profile.html?username=${username}`);
cy.get("#subscriptions").should("have.text", "1");
});
it("unsubscribe to user", () => {
// Check user2's subscriptions count
cy.visit(`/profile.html?username=${username}`);
cy.get("#subscriptions").should("have.text", "1");
// Check user1's subscribers count
cy.visit("/profile.html?username=user1");
cy.get("#subscribers").should("have.text", "1");
// Unubscribe to user1 and check decreased subscribers count
cy.get("#button-user-unsubscribe").click();
cy.get("#button-user-unsubscribe").should("not.be.visible");
cy.get("#button-user-subscribe").should("be.visible");
cy.get("#subscribers").should("have.text", "0");
// Check decreased subscriptions count for user2
cy.visit(`/profile.html?username=${username}`);
cy.get("#subscriptions").should("have.text", "0");
});
});
describe("user search", () => {
// User credentials
const username = "user2";
const password = "user2";
before(() => {
cy.visit("index.html");
cy.clearCookies();
// Log in once before any tests run
cy.login(username, password);
});
beforeEach(() => {
// Before each test, preserve the access and refresh cookies (i.e. stay logged in)
Cypress.Cookies.preserveOnce("access", "refresh");
cy.window().then((win) => {
win.sessionStorage.setItem("username", username);
});
});
it("page loads", () => {
cy.visit("index.html");
cy.get(".navbar-nav").contains("User search").click();
cy.location("pathname").should("eq", "/usersearch.html");
cy.get("#input-username").should("be.visible");
cy.get("#button-user-search").should("be.visible");
cy.get(".list-group").find("a").should("have.length", 6);
cy.get(".list-group").contains("user2").get(".badge").should("be.visible");
});
it("no matching user", () => {
cy.visit("usersearch.html");
cy.get("#input-username").type("nonexistent");
cy.get("#button-user-search").click();
cy.contains("No users matching the search nonexistent").should("be.visible");
});
it("searching", () => {
cy.visit("usersearch.html");
cy.get("#input-username").type("user");
cy.get("#button-user-search").click();
cy.get(".list-group").find("a").should("have.length", 5);
cy.get(".list-group").contains("user1").should("be.visible");
cy.get(".list-group").contains("user2").should("be.visible");
cy.get(".list-group").contains("user3").should("be.visible");
cy.get(".list-group").contains("admin").should("not.exist");
cy.get("#input-username").type("1");
cy.get("#button-user-search").click();
cy.get(".list-group").find("a").should("have.length", 1);
cy.get(".list-group").contains("user1").should("be.visible");
cy.get(".list-group").contains("user1").click();
cy.location("pathname").should("eq", "/profile.html");
cy.location("search").should("eq", "?username=user1");
});
});
describe("visit profile through author", () => {
// User credentials
const username = "user2";
const password = "user2";
before(() => {
cy.visit("index.html");
cy.clearCookies();
// Log in once before any tests run
cy.login(username, password);
});
beforeEach(() => {
// Before each test, preserve the access and refresh cookies (i.e. stay logged in)
Cypress.Cookies.preserveOnce("access", "refresh");
cy.window().then((win) => {
win.sessionStorage.setItem("username", username);
});
});
it("visit profile through author of workout", () => {
cy.visit("workout.html?id=7");
cy.get("#owner_username_profile_link").then((link) => {
cy.wrap(link).should("be.visible");
cy.wrap(link).should("have.text", "user1");
cy.wrap(link).click();
});
cy.location("pathname").should("eq", "/profile.html");
cy.location("search").should("eq", "?username=user1");
});
it("visit profile through author of exercise", () => {
cy.visit("exercise.html?id=1");
cy.get("#owner_username_profile_link").then((link) => {
cy.wrap(link).should("be.visible");
cy.wrap(link).should("have.text", "user2");
cy.wrap(link).click();
});
cy.location("pathname").should("eq", "/profile.html");
cy.location("search").should("eq", "?username=user2");
});
it("visit profile through author of meal", () => {
cy.visit("meal.html?id=1");
cy.get("#owner_username_profile_link").then((link) => {
cy.wrap(link).should("be.visible");
cy.wrap(link).should("have.text", "user1");
cy.wrap(link).click();
});
cy.location("pathname").should("eq", "/profile.html");
cy.location("search").should("eq", "?username=user1");
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment