Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Secfit Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
T2
Secfit Frontend
Commits
7466a397
Commit
7466a397
authored
Apr 15, 2021
by
Håvard Borgen Myrekrok
Browse files
Options
Downloads
Plain Diff
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
!7
Refactor/scripts/myathletes.js
Pipeline
#128073
passed
Apr 15, 2021
Stage: test
Stage: production
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cypress/integration/test_spec.js
+39
-3
39 additions, 3 deletions
cypress/integration/test_spec.js
www/scripts/myathletes.js
+34
-14
34 additions, 14 deletions
www/scripts/myathletes.js
with
73 additions
and
17 deletions
cypress/integration/test_spec.js
+
39
−
3
View file @
7466a397
...
...
@@ -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
This diff is collapsed.
Click to expand it.
www/scripts/myathletes.js
+
34
−
14
View file @
7466a397
...
...
@@ -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
,
nav
TabContent
);
tabPanel
=
createTabContents
(
create
TabContent
sInput
);
}
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
,
nav
TabContent
);
tabPanel
=
createTabContents
(
create
TabContent
sInput
);
}
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
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment