Commit deed07d5 authored by Pernille Nødtvedt Welle-Watne's avatar Pernille Nødtvedt Welle-Watne
Browse files

E2e

parent b609cbe7
......@@ -126,3 +126,27 @@ If you want to run this as a mobile application
It's possible you will need to add the platforms you want to run and build.
The following documentation can be used to run the application in an Android emulator: \
https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html
##Tests
### Django
To run test for backend enter
`python manage.py test`
With coverage TODO
### Cypress
To run the test in cypress go to the frontend folder and enter in different terminals:
`npm run test:dev`
`npm run django:testserver`
`npm run cypress:open`
# Generated by Django 3.1 on 2021-03-04 22:41
# Generated by Django 3.1 on 2021-03-09 18:39
from django.db import migrations, models
import django.utils.timezone
......
# Generated by Django 3.1 on 2021-03-04 22:41
# Generated by Django 3.1 on 2021-03-09 18:39
from django.conf import settings
from django.db import migrations, models
......@@ -27,4 +27,7 @@ class Migration(migrations.Migration):
name='coach',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owner', to=settings.AUTH_USER_MODEL),
),
migrations.DeleteModel(
name='WorkoutRequest',
),
]
# Generated by Django 3.1 on 2021-03-04 22:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('suggested_workouts', '0002_auto_20210304_2241'),
]
operations = [
migrations.AddField(
model_name='suggestedworkout',
name='visibility',
field=models.CharField(default='PU', max_length=8),
),
]
# Generated by Django 3.1 on 2021-03-04 23:00
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('suggested_workouts', '0003_suggestedworkout_visibility'),
]
operations = [
migrations.RemoveField(
model_name='suggestedworkout',
name='visibility',
),
]
# Generated by Django 3.1 on 2021-03-04 23:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('suggested_workouts', '0004_remove_suggestedworkout_visibility'),
]
operations = [
migrations.AddField(
model_name='suggestedworkout',
name='visibility',
field=models.CharField(blank=True, default='', max_length=8, null=True),
),
]
# Generated by Django 3.1 on 2021-03-05 09:29
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('suggested_workouts', '0005_suggestedworkout_visibility'),
]
operations = [
migrations.RemoveField(
model_name='suggestedworkout',
name='visibility',
),
migrations.DeleteModel(
name='WorkoutRequest',
),
]
# Generated by Django 3.1 on 2021-03-04 22:41
# Generated by Django 3.1 on 2021-03-09 18:39
from django.conf import settings
from django.db import migrations, models
......
# Generated by Django 3.1 on 2021-03-04 22:41
# Generated by Django 3.1 on 2021-03-09 18:39
from django.conf import settings
from django.db import migrations, models
......@@ -8,7 +8,7 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('suggested_workouts', '0002_auto_20210304_2241'),
('suggested_workouts', '0002_auto_20210309_1939'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('workouts', '0001_initial'),
]
......
......@@ -142,7 +142,9 @@ class WorkoutList(
# - The workout has coach visibility and the requesting user is the owner's coach
qs = Workout.objects.filter(
Q(visibility="PU")
| Q(owner=self.request.user)
| (Q(visibility="CO") & Q(owner__coach=self.request.user))
| (Q(visibility= "PR") & Q(owner=self.request.user))
).distinct()
# Check if the planned workout has happened
if len(qs) > 0:
......
......@@ -6,3 +6,4 @@ node_modules/
# Generated by Cordova
#/plugins/
platforms/browser/www/
{
"baseUrl": "http://localhost:8001"
}
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
\ No newline at end of file
[
{
"model": "workouts.exercise",
"pk": 1,
"fields": {
"name": "Push-up",
"description": "A push-up (or press-up in British English) is a common calisthenics exercise beginning from the prone position.",
"unit": "reps"
}
},
{
"model": "workouts.exercise",
"pk": 2,
"fields": {
"name": "Crunch",
"description": "The crunch is one of the most popular abdominal exercises.",
"unit": "reps"
}
},
{
"model": "workouts.exercise",
"pk": 3,
"fields": {
"name": "Plank",
"description": "The plank is an isometric core strength exercise that involves maintaining a position similar to a push-up for the maximum possible time.",
"unit": "seconds"
}
}
]
\ No newline at end of file
[
{
"model": "suggested_workouts.suggestedworkout",
"pk": 1,
"fields": {
"name": "Suggested Workout Seed",
"date": null,
"notes": "heiheihei",
"coach": 1,
"athlete": 2,
"status": "p"
}
}
]
\ No newline at end of file
[
{
"model": "users.user",
"pk": 1,
"fields": {
"password": "pbkdf2_sha256$216000$dwLWHh4UQcb1$WCO07fF5B35w+18a+hGFrJwUOnlHaTbzrEzhS+VfFOc=",
"last_login": null,
"is_superuser": false,
"username": "coach",
"first_name": "",
"last_name": "",
"email": "coach@hei.no",
"is_staff": false,
"is_active": true,
"date_joined": "2021-03-06T13:30:38.062Z",
"coach": null,
"phone_number": "90909",
"country": "uuu",
"city": "uuu",
"street_address": "uu",
"groups": [],
"user_permissions": []
}
},
{
"model": "users.user",
"pk": 2,
"fields": {
"password": "pbkdf2_sha256$216000$FDoyirNZ6PwZ$Q7Fk+PDkyQg3yVF5L/snqMgpS8q6gP3Q7kgbfVDjhAU=",
"last_login": null,
"is_superuser": false,
"username": "athlete",
"first_name": "",
"last_name": "",
"email": "athlete@hei.no",
"is_staff": false,
"is_active": true,
"date_joined": "2021-03-06T13:30:56.670Z",
"coach": 1,
"phone_number": "99",
"country": "hh",
"city": "hhh",
"street_address": "h",
"groups": [],
"user_permissions": []
}
},
{
"model": "users.offer",
"pk": 1,
"fields": {
"owner": 1,
"recipient": 2,
"status": "d",
"timestamp": "2021-03-06T13:31:08.471Z"
}
},
{
"model": "workouts.exercise",
"pk": 1,
"fields": {
"name": "Push-up",
"description": "A push-up (or press-up in British English) is a common calisthenics exercise beginning from the prone position.",
"unit": "reps"
}
},
{
"model": "workouts.exercise",
"pk": 2,
"fields": {
"name": "Crunch",
"description": "The crunch is one of the most popular abdominal exercises.",
"unit": "reps"
}
},
{
"model": "workouts.exercise",
"pk": 3,
"fields": {
"name": "Plank",
"description": "The plank is an isometric core strength exercise that involves maintaining a position similar to a push-up for the maximum possible time.",
"unit": "seconds"
}
}
]
[
{
"model": "workouts.workout",
"pk": 1,
"fields": {
"name": "Workout Private - Coach",
"date": "2021-03-01T23:03:00Z",
"notes": "Hei",
"owner": 1,
"planned": false,
"visibility": "PR"
}
},
{
"model": "workouts.workout",
"pk": 2,
"fields": {
"name": "Workout Visible for Coach",
"date": "2021-03-01T23:05:00Z",
"notes": "dddd",
"owner": 2,
"planned": false,
"visibility": "CO"
}
},
{
"model": "workouts.workout",
"pk": 3,
"fields": {
"name": "Workout Public - Coach",
"date": "2021-03-06T23:09:00Z",
"notes": "dddd",
"owner": 1,
"planned": false,
"visibility": "PU"
}
}
]
\ No newline at end of file
/// <reference types="cypress" />
context('Actions', () => {
beforeEach(() => {
cy.visit('https://example.cypress.io/commands/actions')
})
// https://on.cypress.io/interacting-with-elements
it('.type() - type into a DOM element', () => {
// https://on.cypress.io/type
cy.get('.action-email')
.type('fake@email.com').should('have.value', 'fake@email.com')
// .type() with special character sequences
.type('{leftarrow}{rightarrow}{uparrow}{downarrow}')
.type('{del}{selectall}{backspace}')
// .type() with key modifiers
.type('{alt}{option}') //these are equivalent
.type('{ctrl}{control}') //these are equivalent
.type('{meta}{command}{cmd}') //these are equivalent
.type('{shift}')
// Delay each keypress by 0.1 sec
.type('slow.typing@email.com', { delay: 100 })
.should('have.value', 'slow.typing@email.com')
cy.get('.action-disabled')
// Ignore error checking prior to type
// like whether the input is visible or disabled
.type('disabled error checking', { force: true })
.should('have.value', 'disabled error checking')
})
it('.focus() - focus on a DOM element', () => {
// https://on.cypress.io/focus
cy.get('.action-focus').focus()
.should('have.class', 'focus')
.prev().should('have.attr', 'style', 'color: orange;')
})
it('.blur() - blur off a DOM element', () => {
// https://on.cypress.io/blur
cy.get('.action-blur').type('About to blur').blur()
.should('have.class', 'error')
.prev().should('have.attr', 'style', 'color: red;')
})
it('.clear() - clears an input or textarea element', () => {
// https://on.cypress.io/clear
cy.get('.action-clear').type('Clear this text')
.should('have.value', 'Clear this text')
.clear()
.should('have.value', '')
})
it('.submit() - submit a form', () => {
// https://on.cypress.io/submit
cy.get('.action-form')
.find('[type="text"]').type('HALFOFF')
cy.get('.action-form').submit()
.next().should('contain', 'Your form has been submitted!')
})
it('.click() - click on a DOM element', () => {
// https://on.cypress.io/click
cy.get('.action-btn').click()
// You can click on 9 specific positions of an element:
// -----------------------------------
// | topLeft top topRight |
// | |
// | |
// | |
// | left center right |
// | |
// | |
// | |
// | bottomLeft bottom bottomRight |
// -----------------------------------
// clicking in the center of the element is the default
cy.get('#action-canvas').click()
cy.get('#action-canvas').click('topLeft')
cy.get('#action-canvas').click('top')
cy.get('#action-canvas').click('topRight')
cy.get('#action-canvas').click('left')
cy.get('#action-canvas').click('right')
cy.get('#action-canvas').click('bottomLeft')
cy.get('#action-canvas').click('bottom')
cy.get('#action-canvas').click('bottomRight')
// .click() accepts an x and y coordinate
// that controls where the click occurs :)
cy.get('#action-canvas')
.click(80, 75) // click 80px on x coord and 75px on y coord
.click(170, 75)
.click(80, 165)
.click(100, 185)
.click(125, 190)
.click(150, 185)
.click(170, 165)
// click multiple elements by passing multiple: true
cy.get('.action-labels>.label').click({ multiple: true })
// Ignore error checking prior to clicking
cy.get('.action-opacity>.btn').click({ force: true })
})
it('.dblclick() - double click on a DOM element', () => {
// https://on.cypress.io/dblclick
// Our app has a listener on 'dblclick' event in our 'scripts.js'
// that hides the div and shows an input on double click
cy.get('.action-div').dblclick().should('not.be.visible')
cy.get('.action-input-hidden').should('be.visible')
})
it('.rightclick() - right click on a DOM element', () => {
// https://on.cypress.io/rightclick
// Our app has a listener on 'contextmenu' event in our 'scripts.js'
// that hides the div and shows an input on right click
cy.get('.rightclick-action-div').rightclick().should('not.be.visible')
cy.get('.rightclick-action-input-hidden').should('be.visible')
})
it('.check() - check a checkbox or radio element', () => {
// https://on.cypress.io/check
// By default, .check() will check all
// matching checkbox or radio elements in succession, one after another
cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]')
.check().should('be.checked')
cy.get('.action-radios [type="radio"]').not('[disabled]')
.check().should('be.checked')
// .check() accepts a value argument
cy.get('.action-radios [type="radio"]')
.check('radio1').should('be.checked')
// .check() accepts an array of values
cy.get('.action-multiple-checkboxes [type="checkbox"]')
.check(['checkbox1', 'checkbox2']).should('be.checked')
// Ignore error checking prior to checking
cy.get('.action-checkboxes [disabled]')
.check({ force: true }).should('be.checked')
cy.get('.action-radios [type="radio"]')
.check('radio3', { force: true }).should('be.checked')
})
it('.uncheck() - uncheck a checkbox element', () => {
// https://on.cypress.io/uncheck
// By default, .uncheck() will uncheck all matching
// checkbox elements in succession, one after another
cy.get('.action-check [type="checkbox"]')
.not('[disabled]')
.uncheck().should('not.be.checked')
// .uncheck() accepts a value argument
cy.get('.action-check [type="checkbox"]')
.check('checkbox1')
.uncheck('checkbox1').should('not.be.checked')
// .uncheck() accepts an array of values
cy.get('.action-check [type="checkbox"]')
.check(['checkbox1', 'checkbox3'])
.uncheck(['checkbox1', 'checkbox3']).should('not.be.checked')
// Ignore error checking prior to unchecking
cy.get('.action-check [disabled]')
.uncheck({ force: true }).should('not.be.checked')
})
it('.select() - select an option in a <select> element', () => {
// https://on.cypress.io/select
// at first, no option should be selected
cy.get('.action-select')
.should('have.value', '--Select a fruit--')
// Select option(s) with matching text content
cy.get('.action-select').select('apples')
// confirm the apples were selected
// note that each value starts with "fr-" in our HTML
cy.get('.action-select').should('have.value', 'fr-apples')
cy.get('.action-select-multiple')
.select(['apples', 'oranges', 'bananas'])
// when getting multiple values, invoke "val" method first
.invoke('val')
.should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
// Select option(s) with matching value
cy.get('.action-select').select('fr-bananas')
// can attach an assertion right away to the element
.should('have.value', 'fr-bananas')
cy.get('.action-select-multiple')
.select(['fr-apples', 'fr-oranges', 'fr-bananas'])
.invoke('val')
.should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
// assert the selected values include oranges
cy.get('.action-select-multiple')
.invoke('val').should('include', 'fr-oranges')
})
it('.scrollIntoView() - scroll an element into view', () => {
// https://on.cypress.io/scrollintoview
// normally all of these buttons are hidden,
// because they're not within
// the viewable area of their parent
// (we need to scroll to see them)
cy.get('#scroll-horizontal button')
.should('not.be.visible')
// scroll the button into view, as if the user had scrolled
cy.get('#scroll-horizontal button').scrollIntoView()
.should('be.visible')
cy.get('#scroll-vertical button')
.should('not.be.visible')
// Cypress handles the scroll direction needed
cy.get('#scroll-vertical button').scrollIntoView()