Skip to content
Snippets Groups Projects
Commit 7466a397 authored by Håvard Borgen Myrekrok's avatar Håvard Borgen Myrekrok
Browse files

Merge branch 'refactor/scripts/myathletes.js' into 'master'

Refactor/scripts/myathletes.js

See merge request !7
parents 5780f01c 3d0711ce
No related branches found
No related tags found
1 merge request!7Refactor/scripts/myathletes.js
Pipeline #128073 passed
......@@ -21,7 +21,7 @@ const userResults1 = {
"id": userId1,
"email": "",
"username": username1,
"athletes": [],
"athletes": [`https://secfit-t2-backend.herokuapp.com/api/users/${userId2}/`],
"phone_number": "",
"country": "",
"city": "",
......@@ -29,7 +29,7 @@ const userResults1 = {
"coach": null,
"workouts": [],
"coach_files": [],
"athlete_files": [],
"athlete_files": ["https://secfit-t2-backend.herokuapp.com/api/athlete-files/1/"],
"bio": bio1,
"birthday": birthday1,
"favorite_exercise": favoriteExercise1
......@@ -45,7 +45,7 @@ const userResults2 = {
"country": "",
"city": "",
"street_address": "",
"coach": null,
"coach": `https://secfit-t2-backend.herokuapp.com/api/users/${userId1}/`,
"workouts": [],
"coach_files": [],
"athlete_files": [],
......@@ -201,6 +201,23 @@ const commentsResult = {
"results": []
}
const offersResult = {
"count": 0,
"next": null,
"previous": null,
"results": []
}
const fileName = "filnavn.txt"
const athleteFilesResult = {
"url":"https://secfit-t2-backend.herokuapp.com/api/athlete-files/1/",
"id":1,
"owner":"coach",
"file":`https://secfit-t2-backend.herokuapp.com/media/users/${userId2}/${fileName}`,
"athlete":`https://secfit-t2-backend.herokuapp.com/api/users/${userId2}/`
}
// const wor
describe('profilepage', () => {
......@@ -293,6 +310,20 @@ describe('profilepage', () => {
},
commentsResult
)
cy.intercept(
{
method: 'GET',
url: `https://secfit-t2-backend.herokuapp.com/api/offers/*`,
},
offersResult
)
cy.intercept(
{
method: 'GET',
url: `https://secfit-t2-backend.herokuapp.com/api/athlete-files/*`,
},
athleteFilesResult
)
cy.get('#btn-login').click()
cy.visit('/')
});
......@@ -369,5 +400,10 @@ describe('profilepage', () => {
cy.get("#bio").should("have.value", bio1)
})
it('visit my athletes', () => {
cy.visit('/myathletes.html')
cy.get(`#tab-${username2}`).click()
cy.get(`#tab-contents-${username2} > div > a`).first().should("have.text", fileName)
})
})
\ No newline at end of file
......@@ -51,25 +51,20 @@ function createFilledRow(templateFilledAthlete, inputValue, controls, disabled)
controls.appendChild(filledDiv);
}
async function displayFiles() {
let user = await getCurrentUser();
let templateAthlete = document.querySelector("#template-athlete-tab");
let templateFiles = document.querySelector("#template-files");
async function addFilesToAthlete(files, createTabContentsInput) {
let templateFile = document.querySelector("#template-file");
let listTab = document.querySelector("#list-tab");
let navTabContent = document.querySelector("#nav-tabContent");
for (let fileUrl of user.athlete_files) {
for (let fileUrl of files) {
let response = await sendRequest("GET", fileUrl);
let file = await response.json();
response = await sendRequest("GET", file.athlete);
let athlete = await response.json();
createTabContentsInput.athlete = athlete;
let tabPanel = document.querySelector(`#tab-contents-${athlete.username}`)
if (!tabPanel) {
tabPanel = createTabContents(templateAthlete, athlete, listTab, templateFiles, navTabContent);
tabPanel = createTabContents(createTabContentsInput);
}
let divFiles = tabPanel.querySelector(".uploaded-files");
......@@ -77,14 +72,17 @@ async function displayFiles() {
divFiles.appendChild(aFile);
}
}
for (let athleteUrl of user.athletes) {
async function addFileInputToAthlete(athletes, createTabContentsInput) {
for (let athleteUrl of athletes) {
let response = await sendRequest("GET", athleteUrl);
let athlete = await response.json();
createTabContentsInput.athlete = athlete;
let tabPanel = document.querySelector(`#tab-contents-${athlete.username}`)
if (!tabPanel) {
tabPanel = createTabContents(templateAthlete, athlete, listTab, templateFiles, navTabContent);
tabPanel = createTabContents(createTabContentsInput);
}
let uploadBtn = document.querySelector(`#btn-upload-${athlete.username}`);
uploadBtn.disabled = false;
......@@ -93,6 +91,22 @@ async function displayFiles() {
let fileInput = tabPanel.querySelector(".form-control");
fileInput.disabled = false;
}
}
async function displayFiles() {
let user = await getCurrentUser();
let createTabContentsInput = {
templateAthlete: document.querySelector("#template-athlete-tab"),
athlete: null,
listTab: document.querySelector("#list-tab"),
templateFiles: document.querySelector("#template-files"),
navTabContent: document.querySelector("#nav-tabContent")
}
await addFilesToAthlete(user.athlete_files, createTabContentsInput);
await addFileInputToAthlete(user.athletes, createTabContentsInput);
if (user.athlete_files.length == 0 && user.athletes.length == 0) {
let p = document.createElement("p");
......@@ -101,7 +115,13 @@ async function displayFiles() {
}
}
function createTabContents(templateAthlete, athlete, listTab, templateFiles, navTabContent) {
function createTabContents({
templateAthlete,
athlete,
listTab,
templateFiles,
navTabContent
}) {
let cloneAthlete = templateAthlete.content.cloneNode(true);
let a = cloneAthlete.querySelector("a");
......@@ -179,7 +199,7 @@ async function submitRoster() {
}
}
}
let response = await sendRequest("PUT", currentUser.url, body);
await sendRequest("PUT", currentUser.url, body);
location.reload();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment