Client - update e2e tests (wip) and build

This commit is contained in:
Sam 2021-10-31 21:04:47 +01:00
parent 23066c52a8
commit fb6491638c
18 changed files with 105 additions and 95 deletions

View File

@ -4,4 +4,6 @@ import pytest
@pytest.fixture
def firefox_options(firefox_options):
firefox_options.add_argument('--headless')
firefox_options.add_argument('--width=1920')
firefox_options.add_argument('--height=1080')
return firefox_options

View File

@ -9,9 +9,7 @@ class TestIndex:
def test_navbar_contains_all_links(self, selenium):
selenium.get(TEST_URL)
nav = selenium.find_element_by_tag_name('nav').text
nav = selenium.find_element_by_id('nav').text
assert "FitTrackee" in nav
assert "Dashboard" in nav
assert "Login" in nav
assert "Register" in nav
assert "en" in nav

View File

@ -7,26 +7,28 @@ class TestLogin:
def test_navbar_contains_login(self, selenium):
selenium.get(URL)
nav = selenium.find_element_by_tag_name('nav').text
nav = selenium.find_element_by_id('nav').text
assert 'Login' in nav
def test_h1_contains_login(self, selenium):
selenium.get(URL)
title = selenium.find_element_by_tag_name('h1').text
assert 'Login' in title
def test_it_displays_login_form(self, selenium):
selenium.get(URL)
inputs = selenium.find_elements_by_tag_name('input')
assert len(inputs) == 3
assert inputs[0].get_attribute('name') == 'email'
assert len(inputs) == 2
assert inputs[0].get_attribute('id') == 'email'
assert inputs[0].get_attribute('type') == 'email'
assert inputs[1].get_attribute('name') == 'password'
assert inputs[1].get_attribute('id') == 'password'
assert inputs[1].get_attribute('type') == 'password'
assert inputs[2].get_attribute('name') == ''
assert inputs[2].get_attribute('type') == 'submit'
button = selenium.find_element_by_tag_name('button')
assert button.get_attribute('type') == 'submit'
assert 'Log in' in button.text
forgot_password_link = selenium.find_element_by_class_name(
'password-forgotten'
)
assert forgot_password_link.tag_name == 'a'
assert 'Forgot password?' in forgot_password_link.text
def test_user_can_log_in(self, selenium):
user = {

View File

@ -4,16 +4,14 @@ from .utils import register_valid_user
class TestLogout:
def test_user_can_log_out(self, selenium):
user = register_valid_user(selenium)
nav_items = selenium.find_elements_by_class_name('nav-item')
user_menu = selenium.find_element_by_class_name('nav-items-user-menu')
logout_link = user_menu.find_elements_by_class_name('nav-item')[2]
nav_items[5].click()
logout_link.click()
selenium.implicitly_wait(1)
nav = selenium.find_element_by_tag_name('nav').text
nav = selenium.find_element_by_id('nav').text
assert 'Register' in nav
assert 'Login' in nav
assert user['username'] not in nav
assert 'Logout' not in nav
message = selenium.find_element_by_class_name('card-body').text
assert 'You are now logged out. Click here to log back in.' in message

View File

@ -8,13 +8,16 @@ class TestProfile:
user = register_valid_user(selenium)
selenium.get(URL)
user_header = selenium.find_element_by_class_name('user-header')
assert user['username'] in user_header.text
assert '0\nworkouts' in user_header.text
assert '0\nkm' in user_header.text
assert '0\nsports' in user_header.text
assert 'Profile' in selenium.find_element_by_tag_name('h1').text
assert (
user['username']
in selenium.find_element_by_class_name('userName').text
)
assert (
user['username']
in selenium.find_element_by_class_name('userName').text
)
user_infos = selenium.find_element_by_id('user-infos')
assert 'Registration date' in user_infos.text
assert 'First name' in user_infos.text
assert 'Last name' in user_infos.text
assert 'Birth date' in user_infos.text
assert 'Location' in user_infos.text
assert 'Bio' in user_infos.text

View File

@ -15,17 +15,19 @@ class TestRegistration:
selenium.implicitly_wait(1)
inputs = selenium.find_elements_by_tag_name('input')
assert len(inputs) == 5
assert inputs[0].get_attribute('name') == 'username'
assert len(inputs) == 4
assert inputs[0].get_attribute('id') == 'username'
assert inputs[0].get_attribute('type') == 'text'
assert inputs[1].get_attribute('name') == 'email'
assert inputs[1].get_attribute('id') == 'email'
assert inputs[1].get_attribute('type') == 'email'
assert inputs[2].get_attribute('name') == 'password'
assert inputs[2].get_attribute('id') == 'password'
assert inputs[2].get_attribute('type') == 'password'
assert inputs[3].get_attribute('name') == 'password_conf'
assert inputs[3].get_attribute('id') == 'confirm-password'
assert inputs[3].get_attribute('type') == 'password'
assert inputs[4].get_attribute('name') == ''
assert inputs[4].get_attribute('type') == 'submit'
button = selenium.find_element_by_tag_name('button')
assert button.get_attribute('type') == 'submit'
assert 'Register' in button.text
def test_user_can_register(self, selenium):
user = register_valid_user(selenium)
@ -44,7 +46,7 @@ class TestRegistration:
register(selenium, user_infos)
assert selenium.current_url == URL
nav = selenium.find_element_by_tag_name('nav').text
nav = selenium.find_element_by_id('nav').text
assert 'Register' in nav
assert 'Login' in nav
@ -62,8 +64,8 @@ class TestRegistration:
register(selenium, user_infos)
assert selenium.current_url == URL
errors = selenium.find_element_by_tag_name('code').text
assert 'Sorry. That user already exists.' in errors
errors = selenium.find_element_by_class_name('error-message').text
assert 'That user already exists' in errors
def test_user_can_not_register_if_email_is_already_taken(self, selenium):
user_name = random_string()
@ -77,8 +79,8 @@ class TestRegistration:
register(selenium, user_infos)
assert selenium.current_url == URL
errors = selenium.find_element_by_tag_name('code').text
assert 'Sorry. That user already exists.' in errors
errors = selenium.find_element_by_class_name('error-message').text
assert 'That user already exists' in errors
def test_user_can_not_register_if_username_is_too_short(self, selenium):
user_name = random_string(2)
@ -92,8 +94,8 @@ class TestRegistration:
register(selenium, user_infos)
assert selenium.current_url == URL
errors = selenium.find_element_by_tag_name('code').text
assert '3 to 12 characters required for username.' in errors
errors = selenium.find_element_by_class_name('error-message').text
assert 'Username: 3 to 12 characters required' in errors
def test_user_can_not_register_if_username_is_too_long(self, selenium):
user_name = random_string(13)
@ -107,8 +109,8 @@ class TestRegistration:
register(selenium, user_infos)
assert selenium.current_url == URL
errors = selenium.find_element_by_tag_name('code').text
assert '3 to 12 characters required for username.' in errors
errors = selenium.find_element_by_class_name('error-message').text
assert 'Username: 3 to 12 characters required' in errors
def test_it_displays_error_if_passwords_do_not_match(self, selenium):
user_name = random_string()
@ -122,7 +124,7 @@ class TestRegistration:
register(selenium, user_infos)
assert selenium.current_url == URL
errors = selenium.find_element_by_tag_name('code').text
errors = selenium.find_element_by_class_name('error-message').text
assert 'Password and password confirmation don\'t match' in errors
def test_it_displays_error_if_password_is_too_short(self, selenium):
@ -137,5 +139,5 @@ class TestRegistration:
register(selenium, user_infos)
assert selenium.current_url == URL
errors = selenium.find_element_by_tag_name('code').text
assert '8 characters required for password.' in errors
errors = selenium.find_element_by_class_name('error-message').text
assert 'Password: 8 characters required' in errors

View File

@ -7,32 +7,37 @@ from .utils import TEST_URL, register_valid_user
class TestWorkout:
def test_user_can_add_workout_without_gpx(self, selenium):
register_valid_user(selenium)
nav_items = selenium.find_elements_by_class_name('nav-item')
app_menu = selenium.find_element_by_class_name('nav-items-app-menu')
add_workout_link = app_menu.find_elements_by_class_name('nav-item')[3]
nav_items[3].click()
add_workout_link.click()
selenium.implicitly_wait(1)
radio_buttons = selenium.find_elements_by_class_name(
'add-workout-radio'
)
radio_buttons[1].click()
radio_button = selenium.find_element_by_id('withoutGpx')
radio_button.click()
selenium.find_element_by_name('title').send_keys('Workout title')
select = Select(selenium.find_element_by_name('sport_id'))
select = Select(selenium.find_element_by_id('sport'))
select.select_by_index(1)
selenium.find_element_by_name('workout_date').send_keys('2018-12-20')
selenium.find_element_by_name('workout_time').send_keys('14:05')
selenium.find_element_by_name('duration').send_keys('01:00:00')
selenium.find_element_by_name('distance').send_keys('10')
selenium.find_element_by_class_name('btn-primary').click()
selenium.find_element_by_name('title').send_keys('Workout title')
selenium.find_element_by_name('workout-date').send_keys('2018-12-20')
selenium.find_element_by_name('workout-time').send_keys('14:05')
selenium.find_element_by_name('workout-duration-hour').send_keys('01')
selenium.find_element_by_name('workout-duration-minutes').send_keys(
'00'
)
selenium.find_element_by_name('workout-duration-seconds').send_keys(
'00'
)
selenium.find_element_by_name('workout-distance').send_keys('10')
confirm_button = selenium.find_element_by_class_name('confirm')
confirm_button.click()
WebDriverWait(selenium, 10).until(
EC.url_changes(f"{TEST_URL}/workouts/add")
)
workout_details = selenium.find_element_by_class_name(
'workout-details'
).text
workout_details = selenium.find_element_by_id('workout-info').text
assert 'Duration: 1:00:00' in workout_details
assert 'Distance: 10 km' in workout_details
assert 'Average speed: 10 km/h' in workout_details
assert 'Max. speed: 10 km/h' in workout_details
assert 'Average Speed: 10 km/h' in workout_details
assert 'Max. Speed: 10 km/h' in workout_details

View File

@ -18,26 +18,26 @@ def random_string(length=8):
def register(selenium, user):
selenium.get(f'{TEST_URL}/register')
selenium.implicitly_wait(1)
username = selenium.find_element_by_name('username')
username = selenium.find_element_by_id('username')
username.send_keys(user.get('username'))
email = selenium.find_element_by_name('email')
email = selenium.find_element_by_id('email')
email.send_keys(user.get('email'))
password = selenium.find_element_by_name('password')
password = selenium.find_element_by_id('password')
password.send_keys(user.get('password'))
password_conf = selenium.find_element_by_name('password_conf')
password_conf = selenium.find_element_by_id('confirm-password')
password_conf.send_keys(user.get('password_conf'))
submit_button = selenium.find_element_by_class_name('btn')
submit_button = selenium.find_element_by_tag_name('button')
submit_button.click()
def login(selenium, user):
selenium.get(f'{TEST_URL}/login')
selenium.implicitly_wait(1)
email = selenium.find_element_by_name('email')
email = selenium.find_element_by_id('email')
email.send_keys(user.get('email'))
password = selenium.find_element_by_name('password')
password = selenium.find_element_by_id('password')
password.send_keys(user.get('password'))
submit_button = selenium.find_element_by_class_name('btn')
submit_button = selenium.find_element_by_tag_name('button')
submit_button.click()
@ -50,7 +50,7 @@ def register_valid_user(selenium):
'password_conf': 'p@ssw0rd',
}
register(selenium, user)
WebDriverWait(selenium, 10).until(EC.url_changes(f"{TEST_URL}/register"))
WebDriverWait(selenium, 15).until(EC.url_changes(f"{TEST_URL}/register"))
return user
@ -61,13 +61,12 @@ def login_valid_user(selenium, user):
def assert_navbar(selenium, user):
nav = selenium.find_element_by_tag_name('nav').text
nav = selenium.find_element_by_id('nav').text
assert 'Register' not in nav
assert 'Login' not in nav
assert 'Dashboard' in nav
assert 'Workouts' in nav
assert 'Statistics' in nav
assert 'Add workout' in nav
assert 'Add a workout' in nav
assert user['username'] in nav
assert 'Logout' in nav
assert 'en' in nav

View File

@ -64,7 +64,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/img/workouts/mountains.svg"
},
{
"revision": "d31c98a045a9575934a29b6870e4155f",
"revision": "2cfd100ce4c5acaf0068499df96fa840",
"url": "/index.html"
},
{
@ -80,7 +80,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/admin.c784857e.css"
},
{
"revision": "62a8f1fddcb801ef130d",
"revision": "d9bfacb8dc8f5a151839",
"url": "/static/css/app.6f17ce7a.css"
},
{
@ -108,8 +108,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/reset.528e2916.css"
},
{
"revision": "79125f2c2b3a6ae866d6",
"url": "/static/css/workouts.e7912750.css"
"revision": "71aefc8221f9e9fcf5c2",
"url": "/static/css/workouts.80ddc1b5.css"
},
{
"revision": "e719f9244c69e28e7d00e725ca1e280e",
@ -196,8 +196,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/admin.b2c267a7.js"
},
{
"revision": "62a8f1fddcb801ef130d",
"url": "/static/js/app.ccf74644.js"
"revision": "d9bfacb8dc8f5a151839",
"url": "/static/js/app.da2a9740.js"
},
{
"revision": "bd7d183c9f68e5f4027d",
@ -240,7 +240,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/reset.607f183f.js"
},
{
"revision": "79125f2c2b3a6ae866d6",
"url": "/static/js/workouts.6d428fcc.js"
"revision": "71aefc8221f9e9fcf5c2",
"url": "/static/js/workouts.850179fa.js"
}
]);

View File

@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts(
"/precache-manifest.270aa73e5830a623ad4ac1a46bb6e66e.js"
"/precache-manifest.2993d681f0886c270e7f04b02d8ff7c6.js"
);
workbox.core.setCacheNameDetails({prefix: "fittrackee_client"});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -166,6 +166,7 @@
<div class="form-item">
<label>{{ $t('workouts.DISTANCE') }} (km):</label>
<input
name="workout-distance"
type="number"
min="0"
step="0.1"