Commit b482b332 authored by Haakon Gunleiksrud's avatar Haakon Gunleiksrud
Browse files

Merge branch 'leaderboardIntegrationTest' of...

Merge branch 'leaderboardIntegrationTest' of https://gitlab.stud.idi.ntnu.no/tmwang/tdt4242-base into leaderboardIntegrationTest
parents 020e0998 9f8767fe
Pipeline #114147 passed with stage
in 32 seconds
This diff is collapsed.
...@@ -156,6 +156,9 @@ MEDIA_URL = "/media/" ...@@ -156,6 +156,9 @@ MEDIA_URL = "/media/"
REST_FRAMEWORK = { REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
# Increased the page size to 100, because the front-end doesn't fetch more workouts
# than what the page size is here
"PAGE_SIZE": 100, "PAGE_SIZE": 100,
"DEFAULT_AUTHENTICATION_CLASSES": ( "DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication", "rest_framework_simplejwt.authentication.JWTAuthentication",
......
geckodriver.log
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -17,7 +17,7 @@ from datetime import datetime ...@@ -17,7 +17,7 @@ from datetime import datetime
# Before running this test, remember to host the application on http://localhost:9090 using docker-compose up --build # Before running this test, remember to host the application on http://localhost:9090 using docker-compose up --build
# in the main project folder # in the main project folder
# Test is run by: python seleniumLikeIntegrationTest.py (when in the workouts-folder) # Test is run by: python seleniumLikeSystemTest.py (when in the workouts-folder and while website is live with docker)
class TestWorkoutLikes(unittest.TestCase): class TestWorkoutLikes(unittest.TestCase):
# Creates two unique usernames to be used in the tests; # Creates two unique usernames to be used in the tests;
...@@ -25,6 +25,9 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -25,6 +25,9 @@ class TestWorkoutLikes(unittest.TestCase):
uniqueUsername1 = "LikeTestUser1-" + datetime.utcnow().strftime("%m-%d-%Y-%H-%M-%S.%f") uniqueUsername1 = "LikeTestUser1-" + datetime.utcnow().strftime("%m-%d-%Y-%H-%M-%S.%f")
uniqueUsername2 = "LikeTestUser2-" + datetime.utcnow().strftime("%m-%d-%Y-%H-%M-%S.%f") uniqueUsername2 = "LikeTestUser2-" + datetime.utcnow().strftime("%m-%d-%Y-%H-%M-%S.%f")
# Simple password for test users
userPassword = "ABCD1234"
# Runs before each test # Runs before each test
def setUp(self): def setUp(self):
...@@ -33,8 +36,9 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -33,8 +36,9 @@ class TestWorkoutLikes(unittest.TestCase):
# Sets an implicit wait of 10 seconds (Test will wait for up to 10 seconds for an expected DOM element) # Sets an implicit wait of 10 seconds (Test will wait for up to 10 seconds for an expected DOM element)
self.driver.implicitly_wait(10) self.driver.implicitly_wait(10)
# Tests that a user auto-likes his own workout # Tests that a user auto-likes his own workout
def test_auto_liked_own_workout_and_only_one_like(self): def test01_auto_liked_own_workout_and_only_one_like(self):
driver = self.driver driver = self.driver
# Opens the web browser, and logs out just in case someone was already logged in # Opens the web browser, and logs out just in case someone was already logged in
...@@ -60,8 +64,8 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -60,8 +64,8 @@ class TestWorkoutLikes(unittest.TestCase):
# Inputs values in all the registration fields # Inputs values in all the registration fields
usernameField.send_keys(uniqueUsername) usernameField.send_keys(uniqueUsername)
emailField.send_keys(uniqueUsername+"@test.test") emailField.send_keys(uniqueUsername+"@test.test")
passwordField.send_keys("123") passwordField.send_keys(self.__class__.userPassword)
repeatPasswordField.send_keys("123") repeatPasswordField.send_keys(self.__class__.userPassword)
phoneNumberField.send_keys("12312312") phoneNumberField.send_keys("12312312")
countryField.send_keys("Norway") countryField.send_keys("Norway")
cityField.send_keys("Narvik") cityField.send_keys("Narvik")
...@@ -73,7 +77,7 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -73,7 +77,7 @@ class TestWorkoutLikes(unittest.TestCase):
# The "new workout" button sometimes doesn't registers clicks even though it has been loaded into the DOM. # The "new workout" button sometimes doesn't registers clicks even though it has been loaded into the DOM.
# Therefore, we wait 1 second before clicking it # Therefore, we wait 1 second before clicking it
time.sleep(1) time.sleep(0.5)
# Finds and clicks the button that opens the page for creating a new workout # Finds and clicks the button that opens the page for creating a new workout
newWorkoutButton = driver.find_element_by_id("btn-create-workout") newWorkoutButton = driver.find_element_by_id("btn-create-workout")
...@@ -85,31 +89,28 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -85,31 +89,28 @@ class TestWorkoutLikes(unittest.TestCase):
workoutNotesField = driver.find_element_by_id("inputNotes") workoutNotesField = driver.find_element_by_id("inputNotes")
# Waits until fields become editable # Waits until fields become editable
time.sleep(2) time.sleep(1)
# Inputs values into fields # Inputs values into fields
workoutNameField.send_keys("TestWorkout") workoutNameField.send_keys("TestWorkout")
workoutDateField.clear(); workoutDateField.clear();
workoutDateField.send_keys("2020-01-01 12:00"); workoutDateField.send_keys("1111-01-01 00:01");
workoutNotesField.send_keys("This is an auto-generated workout meant for testing") workoutNotesField.send_keys("This is an auto-generated workout meant for testing")
time.sleep(0.5)
time.sleep(1)
# Finds and clicks the button that publishes the new workout # Finds and clicks the button that publishes the new workout
publishWorkoutButton = driver.find_element_by_id("btn-ok-workout") publishWorkoutButton = driver.find_element_by_id("btn-ok-workout")
publishWorkoutButton.click() publishWorkoutButton.click()
time.sleep(0.5)
time.sleep(2)
# Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being # Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being
# loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this. # loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this.
self.scroll_down() self.scroll_down()
time.sleep(1)
# Finds and clicks the button that views the user's own workouts # Finds and clicks the button that views the user's own workouts
myWorkoutsButton = driver.find_element_by_id("list-my-workouts-list") myWorkoutsButton = driver.find_element_by_id("list-my-workouts-list")
myWorkoutsButton.click() myWorkoutsButton.click()
time.sleep(2) time.sleep(1)
# Finds the like button and the like amount of the newly-created workout # Finds the like button and the like amount of the newly-created workout
likeButton = driver.find_elements_by_css_selector("a.like-button")[-1] likeButton = driver.find_elements_by_css_selector("a.like-button")[-1]
...@@ -135,7 +136,7 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -135,7 +136,7 @@ class TestWorkoutLikes(unittest.TestCase):
time.sleep(1) time.sleep(1)
likeButton.click() likeButton.click()
time.sleep(2) time.sleep(1)
# Gets the newest like number that is in the DOM # Gets the newest like number that is in the DOM
likeNumber = driver.find_elements_by_css_selector("td.like-amount")[-1] likeNumber = driver.find_elements_by_css_selector("td.like-amount")[-1]
...@@ -146,17 +147,16 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -146,17 +147,16 @@ class TestWorkoutLikes(unittest.TestCase):
# Refresh the site so that we can be sure that we fetch the newest like amounts, and that the workout wasn't # Refresh the site so that we can be sure that we fetch the newest like amounts, and that the workout wasn't
# actually re-liked by the owner (that no change happened in the database) # actually re-liked by the owner (that no change happened in the database)
driver.refresh() driver.refresh()
time.sleep(2) time.sleep(1)
# Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being # Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being
# loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this. # loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this.
self.scroll_down() self.scroll_down()
time.sleep(1)
# Finds and clicks the button that views the user's own workouts # Finds and clicks the button that views the user's own workouts
myWorkoutsButton = driver.find_element_by_id("list-my-workouts-list") myWorkoutsButton = driver.find_element_by_id("list-my-workouts-list")
myWorkoutsButton.click() myWorkoutsButton.click()
time.sleep(2) time.sleep(1)
# Finds the like button and the like amount of the newly-created workout # Finds the like button and the like amount of the newly-created workout
likeButton = driver.find_elements_by_css_selector("a.like-button")[-1] likeButton = driver.find_elements_by_css_selector("a.like-button")[-1]
...@@ -169,11 +169,9 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -169,11 +169,9 @@ class TestWorkoutLikes(unittest.TestCase):
# Tests that the like button is still active (already liked by the owner) # Tests that the like button is still active (already liked by the owner)
self.assertEqual("like-button active", likeButton.get_attribute("class")) self.assertEqual("like-button active", likeButton.get_attribute("class"))
time.sleep(1)
# Tests that a user can like another user's public workout *once* # Tests that a user can like another user's public workout *once*
def test_liked_by_other_user_and_only_one_like(self): def test02_liked_by_other_user_and_only_one_like(self):
driver = self.driver driver = self.driver
# Opens the web browser, and logs out just in case someone was already logged in # Opens the web browser, and logs out just in case someone was already logged in
...@@ -199,8 +197,8 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -199,8 +197,8 @@ class TestWorkoutLikes(unittest.TestCase):
# Inputs values in all the registration fields # Inputs values in all the registration fields
usernameField.send_keys(uniqueUsername) usernameField.send_keys(uniqueUsername)
emailField.send_keys(uniqueUsername + "@test.test") emailField.send_keys(uniqueUsername + "@test.test")
passwordField.send_keys("123") passwordField.send_keys(self.__class__.userPassword)
repeatPasswordField.send_keys("123") repeatPasswordField.send_keys(self.__class__.userPassword)
phoneNumberField.send_keys("12312312") phoneNumberField.send_keys("12312312")
countryField.send_keys("Norway") countryField.send_keys("Norway")
cityField.send_keys("Narvik") cityField.send_keys("Narvik")
...@@ -209,13 +207,11 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -209,13 +207,11 @@ class TestWorkoutLikes(unittest.TestCase):
# Finds and clicks the button that creates the account # Finds and clicks the button that creates the account
createAccountButton = driver.find_element_by_id("btn-create-account") createAccountButton = driver.find_element_by_id("btn-create-account")
createAccountButton.click() createAccountButton.click()
time.sleep(0.5)
time.sleep(1)
# Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being # Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being
# loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this. # loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this.
self.scroll_down() self.scroll_down()
time.sleep(1)
# Finds the like button and the like amount of the newly-created workout # Finds the like button and the like amount of the newly-created workout
likeButton = driver.find_elements_by_css_selector("a.like-button")[-1] likeButton = driver.find_elements_by_css_selector("a.like-button")[-1]
...@@ -229,7 +225,7 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -229,7 +225,7 @@ class TestWorkoutLikes(unittest.TestCase):
# Clicks the like button # Clicks the like button
likeButton.click() likeButton.click()
time.sleep(2) time.sleep(1)
# Gets the newest like number that is in the DOM # Gets the newest like number that is in the DOM
likeNumber = driver.find_elements_by_css_selector("td.like-amount")[-1] likeNumber = driver.find_elements_by_css_selector("td.like-amount")[-1]
...@@ -245,7 +241,6 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -245,7 +241,6 @@ class TestWorkoutLikes(unittest.TestCase):
# Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being # Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being
# loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this. # loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this.
self.scroll_down() self.scroll_down()
time.sleep(1)
# Finds the like button and the like amount of the newly-created workout # Finds the like button and the like amount of the newly-created workout
likeButton = driver.find_elements_by_css_selector("a.like-button")[-1] likeButton = driver.find_elements_by_css_selector("a.like-button")[-1]
...@@ -257,7 +252,7 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -257,7 +252,7 @@ class TestWorkoutLikes(unittest.TestCase):
# Tests that the like button is still active (already liked) # Tests that the like button is still active (already liked)
self.assertEqual("like-button active", likeButton.get_attribute("class")) self.assertEqual("like-button active", likeButton.get_attribute("class"))
time.sleep(1) time.sleep(0.5)
# Tries to re-click the like button to unlike; this should not be possible # Tries to re-click the like button to unlike; this should not be possible
try: try:
...@@ -273,7 +268,7 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -273,7 +268,7 @@ class TestWorkoutLikes(unittest.TestCase):
time.sleep(1) time.sleep(1)
likeButton.click() likeButton.click()
time.sleep(2) time.sleep(1)
# Gets the newest like number that is in the DOM # Gets the newest like number that is in the DOM
likeNumber = driver.find_elements_by_css_selector("td.like-amount")[-1] likeNumber = driver.find_elements_by_css_selector("td.like-amount")[-1]
...@@ -284,12 +279,11 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -284,12 +279,11 @@ class TestWorkoutLikes(unittest.TestCase):
# Refresh the site so that we can be sure that we fetch the newest like amounts, and that the workout wasn't # Refresh the site so that we can be sure that we fetch the newest like amounts, and that the workout wasn't
# actually re-liked by the owner (that the change happened in the database as well) # actually re-liked by the owner (that the change happened in the database as well)
driver.refresh() driver.refresh()
time.sleep(2) time.sleep(1)
# Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being # Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being
# loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this. # loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this.
self.scroll_down() self.scroll_down()
time.sleep(1)
# Finds the like button and the like amount of the newly-created workout # Finds the like button and the like amount of the newly-created workout
likeButton = driver.find_elements_by_css_selector("a.like-button")[-1] likeButton = driver.find_elements_by_css_selector("a.like-button")[-1]
...@@ -302,20 +296,18 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -302,20 +296,18 @@ class TestWorkoutLikes(unittest.TestCase):
# Tests that the like button is still active (already liked) # Tests that the like button is still active (already liked)
self.assertEqual("like-button active", likeButton.get_attribute("class")) self.assertEqual("like-button active", likeButton.get_attribute("class"))
time.sleep(1)
# *Not a test*, just a cleanup that deletes the workout that was created during the other tests. Tried using # *Not a test*, just a cleanup that deletes the workout that was created during the other tests. Tried using
# tearDownClass, but that did not let me access the website # tearDownClass, but that did not let me access the website
def test_remove_created_workout(self): def test99_remove_created_workout(self):
driver = self.driver driver = self.driver
# Opens the web browser, and logs out just in case someone was already logged in # Opens the web browser, and logs out just in case someone was already logged in
driver.get("http://localhost:9090/logout.html") driver.get("http://localhost:9090/logout.html")
time.sleep(2) time.sleep(1)
driver.get("http://localhost:9090/login.html") driver.get("http://localhost:9090/login.html")
time.sleep(2) time.sleep(1)
# Finds all the input fields in the register form # Finds all the input fields in the register form
usernameField = driver.find_element_by_name('username') usernameField = driver.find_element_by_name('username')
...@@ -326,33 +318,31 @@ class TestWorkoutLikes(unittest.TestCase): ...@@ -326,33 +318,31 @@ class TestWorkoutLikes(unittest.TestCase):
# Inputs values in all the registration fields # Inputs values in all the registration fields
usernameField.send_keys(uniqueUsername) usernameField.send_keys(uniqueUsername)
passwordField.send_keys("123") passwordField.send_keys(self.__class__.userPassword)
logInButton = driver.find_element_by_id("btn-login") logInButton = driver.find_element_by_id("btn-login")
logInButton.click() logInButton.click()
time.sleep(2) time.sleep(1)
# Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being # Scrolls to the bottom of the page; a 'problem' (due to dynamic loading) with not every workout being
# loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this. # loaded into the DOM appears when we have too many workouts. Scrolling to the bottom fixes this.
self.scroll_down() self.scroll_down()
time.sleep(1)
# Finds and clicks the button that views the user's own workouts # Finds and clicks the button that views the user's own workouts
myWorkoutsButton = driver.find_element_by_id("list-my-workouts-list") myWorkoutsButton = driver.find_element_by_id("list-my-workouts-list")
myWorkoutsButton.click() myWorkoutsButton.click()
time.sleep(2) time.sleep(0.5)
workout = driver.find_elements_by_css_selector("a.list-group-item")[-1] workout = driver.find_elements_by_css_selector("a.list-group-item")[-1]
workout.click() workout.click()
time.sleep(2) time.sleep(1)
editButton = driver.find_element_by_id("btn-edit-workout") editButton = driver.find_element_by_id("btn-edit-workout")
editButton.click() editButton.click()
time.sleep(1) time.sleep(0.5)
deleteWorkoutButton = driver.find_element_by_id("btn-delete-workout") deleteWorkoutButton = driver.find_element_by_id("btn-delete-workout")
deleteWorkoutButton.click() deleteWorkoutButton.click()
time.sleep(1)
# Runs after running the tests # Runs after running the tests
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
</div> </div>
</form> </form>
<div class="row"> <div class="row" id="leaderboardTitle">
<div class="col-lg"> <div class="col-lg">
<h3 class="mt-3">Leaderboard</h3> <h3 class="mt-3">Leaderboard</h3>
</div> </div>
......
...@@ -135,10 +135,7 @@ async function fetchLeaderBoards(id) { ...@@ -135,10 +135,7 @@ async function fetchLeaderBoards(id) {
let table = document.getElementById("leaderboardstable"); let table = document.getElementById("leaderboardstable");
let row, cell; let row, cell;
//The user's own score will always be placed last in the JSON response for (let i = 0; i < Math.min(6, data.length); i++) {
let userIndex = data.length - 1;
for (let i = 0; i < data.length - 1; i++) {
row = table.insertRow(); row = table.insertRow();
cell = row.insertCell(); cell = row.insertCell();
cell.textContent = data[i].rank; cell.textContent = data[i].rank;
...@@ -147,16 +144,6 @@ async function fetchLeaderBoards(id) { ...@@ -147,16 +144,6 @@ async function fetchLeaderBoards(id) {
cell = row.insertCell(); cell = row.insertCell();
cell.textContent = data[i].value; cell.textContent = data[i].value;
} }
//If the user is not in top 5, the users score will also be rendered
if (data[userIndex].rank > 5) {
row = table.insertRow();
cell = row.insertCell();
cell.textContent = data[userIndex].rank;
cell = row.insertCell();
cell.textContent = data[userIndex].name;
cell = row.insertCell();
cell.textContent = data[userIndex].value;
}
} }
return data; return data;
...@@ -167,6 +154,8 @@ window.addEventListener("DOMContentLoaded", async () => { ...@@ -167,6 +154,8 @@ window.addEventListener("DOMContentLoaded", async () => {
okButton = document.querySelector("#btn-ok-exercise"); okButton = document.querySelector("#btn-ok-exercise");
deleteButton = document.querySelector("#btn-delete-exercise"); deleteButton = document.querySelector("#btn-delete-exercise");
editButton = document.querySelector("#btn-edit-exercise"); editButton = document.querySelector("#btn-edit-exercise");
leaderboardTable = document.querySelector("#leaderboardstable");
leaderboardTitle = document.querySelector("#leaderboardTitle");
oldFormData = null; oldFormData = null;
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
...@@ -197,7 +186,9 @@ window.addEventListener("DOMContentLoaded", async () => { ...@@ -197,7 +186,9 @@ window.addEventListener("DOMContentLoaded", async () => {
okButton.addEventListener("click", async () => await createExercise()); okButton.addEventListener("click", async () => await createExercise());
cancelButton.addEventListener("click", handleCancelButtonDuringCreate); cancelButton.addEventListener("click", handleCancelButtonDuringCreate);
}
leaderboardTable.style.display = "none";
leaderboardTitle.style.display = "none";
}
}); });
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<td> <td>
Likes: Likes:
</td> </td>
<td></td> <td class="like-amount"></td>
<td> <td>
<a href="#" class="like-button"> <a href="#" class="like-button">
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment