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 @pytest.fixture
def firefox_options(firefox_options): def firefox_options(firefox_options):
firefox_options.add_argument('--headless') firefox_options.add_argument('--headless')
firefox_options.add_argument('--width=1920')
firefox_options.add_argument('--height=1080')
return firefox_options return firefox_options

View File

@ -9,9 +9,7 @@ class TestIndex:
def test_navbar_contains_all_links(self, selenium): def test_navbar_contains_all_links(self, selenium):
selenium.get(TEST_URL) 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 "FitTrackee" in nav
assert "Dashboard" in nav
assert "Login" in nav assert "Login" in nav
assert "Register" 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): def test_navbar_contains_login(self, selenium):
selenium.get(URL) selenium.get(URL)
nav = selenium.find_element_by_tag_name('nav').text nav = selenium.find_element_by_id('nav').text
assert 'Login' in nav 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): def test_it_displays_login_form(self, selenium):
selenium.get(URL) selenium.get(URL)
inputs = selenium.find_elements_by_tag_name('input') inputs = selenium.find_elements_by_tag_name('input')
assert len(inputs) == 3 assert len(inputs) == 2
assert inputs[0].get_attribute('name') == 'email' assert inputs[0].get_attribute('id') == 'email'
assert inputs[0].get_attribute('type') == '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[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): def test_user_can_log_in(self, selenium):
user = { user = {

View File

@ -4,16 +4,14 @@ from .utils import register_valid_user
class TestLogout: class TestLogout:
def test_user_can_log_out(self, selenium): def test_user_can_log_out(self, selenium):
user = register_valid_user(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) 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 'Register' in nav
assert 'Login' in nav assert 'Login' in nav
assert user['username'] not in nav assert user['username'] not in nav
assert 'Logout' 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) user = register_valid_user(selenium)
selenium.get(URL) 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 user_infos = selenium.find_element_by_id('user-infos')
assert ( assert 'Registration date' in user_infos.text
user['username'] assert 'First name' in user_infos.text
in selenium.find_element_by_class_name('userName').text assert 'Last name' in user_infos.text
) assert 'Birth date' in user_infos.text
assert ( assert 'Location' in user_infos.text
user['username'] assert 'Bio' in user_infos.text
in selenium.find_element_by_class_name('userName').text
)

View File

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

View File

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

View File

@ -18,26 +18,26 @@ def random_string(length=8):
def register(selenium, user): def register(selenium, user):
selenium.get(f'{TEST_URL}/register') selenium.get(f'{TEST_URL}/register')
selenium.implicitly_wait(1) selenium.implicitly_wait(1)
username = selenium.find_element_by_name('username') username = selenium.find_element_by_id('username')
username.send_keys(user.get('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')) 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.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')) 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() submit_button.click()
def login(selenium, user): def login(selenium, user):
selenium.get(f'{TEST_URL}/login') selenium.get(f'{TEST_URL}/login')
selenium.implicitly_wait(1) selenium.implicitly_wait(1)
email = selenium.find_element_by_name('email') email = selenium.find_element_by_id('email')
email.send_keys(user.get('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.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() submit_button.click()
@ -50,7 +50,7 @@ def register_valid_user(selenium):
'password_conf': 'p@ssw0rd', 'password_conf': 'p@ssw0rd',
} }
register(selenium, user) 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 return user
@ -61,13 +61,12 @@ def login_valid_user(selenium, user):
def assert_navbar(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 'Register' not in nav
assert 'Login' not in nav assert 'Login' not in nav
assert 'Dashboard' in nav assert 'Dashboard' in nav
assert 'Workouts' in nav assert 'Workouts' in nav
assert 'Statistics' in nav assert 'Statistics' in nav
assert 'Add workout' in nav assert 'Add a workout' in nav
assert user['username'] in nav assert user['username'] in nav
assert 'Logout' 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" "url": "/img/workouts/mountains.svg"
}, },
{ {
"revision": "d31c98a045a9575934a29b6870e4155f", "revision": "2cfd100ce4c5acaf0068499df96fa840",
"url": "/index.html" "url": "/index.html"
}, },
{ {
@ -80,7 +80,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/admin.c784857e.css" "url": "/static/css/admin.c784857e.css"
}, },
{ {
"revision": "62a8f1fddcb801ef130d", "revision": "d9bfacb8dc8f5a151839",
"url": "/static/css/app.6f17ce7a.css" "url": "/static/css/app.6f17ce7a.css"
}, },
{ {
@ -108,8 +108,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/reset.528e2916.css" "url": "/static/css/reset.528e2916.css"
}, },
{ {
"revision": "79125f2c2b3a6ae866d6", "revision": "71aefc8221f9e9fcf5c2",
"url": "/static/css/workouts.e7912750.css" "url": "/static/css/workouts.80ddc1b5.css"
}, },
{ {
"revision": "e719f9244c69e28e7d00e725ca1e280e", "revision": "e719f9244c69e28e7d00e725ca1e280e",
@ -196,8 +196,8 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/admin.b2c267a7.js" "url": "/static/js/admin.b2c267a7.js"
}, },
{ {
"revision": "62a8f1fddcb801ef130d", "revision": "d9bfacb8dc8f5a151839",
"url": "/static/js/app.ccf74644.js" "url": "/static/js/app.da2a9740.js"
}, },
{ {
"revision": "bd7d183c9f68e5f4027d", "revision": "bd7d183c9f68e5f4027d",
@ -240,7 +240,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/reset.607f183f.js" "url": "/static/js/reset.607f183f.js"
}, },
{ {
"revision": "79125f2c2b3a6ae866d6", "revision": "71aefc8221f9e9fcf5c2",
"url": "/static/js/workouts.6d428fcc.js" "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("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts( importScripts(
"/precache-manifest.270aa73e5830a623ad4ac1a46bb6e66e.js" "/precache-manifest.2993d681f0886c270e7f04b02d8ff7c6.js"
); );
workbox.core.setCacheNameDetails({prefix: "fittrackee_client"}); 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"> <div class="form-item">
<label>{{ $t('workouts.DISTANCE') }} (km):</label> <label>{{ $t('workouts.DISTANCE') }} (km):</label>
<input <input
name="workout-distance"
type="number" type="number"
min="0" min="0"
step="0.1" step="0.1"