From 259932a54852eea6380d2b97d146ef5762cdb9a2 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Sun, 23 Oct 2022 10:52:55 +0100 Subject: [PATCH] FIX #502: Possibility to choose 'no selection' in session log form Ref #501...may help/fix this...uncertain yet. Need to finish writing the relevant test! --- RIGS/templatetags/filters.py | 2 + pipeline/source_assets/js/autocompleter.js | 30 +++++++------ templates/partials/button.html | 2 + training/templates/edit_training_record.html | 2 +- .../templates/partials/supervisor_field.html | 2 +- training/templates/session_log_form.html | 15 ++++--- training/tests/conftest.py | 9 ++++ training/tests/pages.py | 39 ++++++++++++++++ training/tests/test_interaction.py | 45 ++++++++++++++++--- 9 files changed, 118 insertions(+), 28 deletions(-) diff --git a/RIGS/templatetags/filters.py b/RIGS/templatetags/filters.py index 7efd42bb..658bd315 100644 --- a/RIGS/templatetags/filters.py +++ b/RIGS/templatetags/filters.py @@ -216,6 +216,8 @@ def button(type, url=None, pk=None, clazz="", icon=None, text="", id=None, style return {'submit': True, 'class': 'btn-info', 'icon': 'fa-search', 'text': 'Search', 'id': id, 'style': style} elif type == 'submit': return {'submit': True, 'class': 'btn-primary', 'icon': 'fa-save', 'text': 'Save', 'id': id, 'style': style} + elif type == 'today': + return {'today': True, 'id': id} return {'target': url, 'pk': pk, 'class': clazz, 'icon': icon, 'text': text, 'id': id, 'style': style} diff --git a/pipeline/source_assets/js/autocompleter.js b/pipeline/source_assets/js/autocompleter.js index e917b7f0..4672fe27 100644 --- a/pipeline/source_assets/js/autocompleter.js +++ b/pipeline/source_assets/js/autocompleter.js @@ -47,14 +47,16 @@ function initPicker(obj) { //log: 3, preprocessData: function (data) { var i, l = data.length, array = []; - array.push({ - text: clearSelectionLabel, - value: '', - data:{ - update_url: '', - subtext:'' - } - }); + if (!obj.data('noclear')) { + array.push({ + text: clearSelectionLabel, + value: '', + data:{ + update_url: '', + subtext:'' + } + }); + } if (l) { for(i = 0; i < l; i++){ @@ -71,11 +73,13 @@ function initPicker(obj) { return array; } }; - - obj.prepend($("") - .attr("value",'') - .text(clearSelectionLabel) - .data('update_url','')); //Add "clear selection" option + console.log(obj.data); + if (!obj.data('noclear')) { + obj.prepend($("") + .attr("value",'') + .text(clearSelectionLabel) + .data('update_url','')); //Add "clear selection" option + } obj.selectpicker().ajaxSelectPicker(options); //Initiaise selectPicker diff --git a/templates/partials/button.html b/templates/partials/button.html index 3a353365..c89e1516 100644 --- a/templates/partials/button.html +++ b/templates/partials/button.html @@ -4,6 +4,8 @@ {{ text }} {% elif copy %} +{% elif today %} + {% else %} {{ text }} {% endif %} diff --git a/training/templates/edit_training_record.html b/training/templates/edit_training_record.html index 5d7c8e6d..c8d9b051 100644 --- a/training/templates/edit_training_record.html +++ b/training/templates/edit_training_record.html @@ -43,7 +43,7 @@ {% render_field form.date|add_class:'form-control'|attr:'type="date"' value=training_date %} {% endwith %} - + {% button 'today' id='id_date' %}
diff --git a/training/templates/partials/supervisor_field.html b/training/templates/partials/supervisor_field.html index a58e697b..52afe576 100644 --- a/training/templates/partials/supervisor_field.html +++ b/training/templates/partials/supervisor_field.html @@ -1,5 +1,5 @@ - {% if supervisor %} {% endif %} diff --git a/training/templates/session_log_form.html b/training/templates/session_log_form.html index d006c04d..3a4aa115 100644 --- a/training/templates/session_log_form.html +++ b/training/templates/session_log_form.html @@ -28,25 +28,26 @@ {% include 'form_errors.html' %} {% csrf_token %}

People

-
+
{% include 'partials/supervisor_field.html' %}
-
+
-

Training Items

{% for depth in depths %} -
+
-
{% endfor %}

Session Information

-
- {% include 'partials/form_field.html' with field=form.date %} +
+ {% include 'partials/form_field.html' with field=form.date col='col-sm-6' %} + {% button 'today' id='id_date' %}
{% include 'partials/form_field.html' with field=form.notes %} diff --git a/training/tests/conftest.py b/training/tests/conftest.py index 1393ee8f..08c58845 100644 --- a/training/tests/conftest.py +++ b/training/tests/conftest.py @@ -30,6 +30,15 @@ def training_item(db): training_item.delete() +@pytest.fixture +def training_item_2(db): + training_category = models.TrainingCategory.objects.create(reference_number=2, name="Sound") + training_item = models.TrainingItem.objects.create(category=training_category, reference_number=1, description="Fundamentals of Audio") + yield training_item + training_category.delete() + training_item.delete() + + @pytest.fixture def level(db): level = models.TrainingLevel.objects.create(description="There is no description.", level=models.TrainingLevel.TECHNICIAN) diff --git a/training/tests/pages.py b/training/tests/pages.py index 44e898d6..c55c1516 100644 --- a/training/tests/pages.py +++ b/training/tests/pages.py @@ -40,3 +40,42 @@ class AddQualification(FormPage): @property def success(self): return 'add' not in self.driver.current_url + + +class SessionLog(FormPage): + URL_TEMPLATE = 'training/session_log' + + _supervisor_selector = (By.CSS_SELECTOR, 'div#supervisor_group>div.bootstrap-select') + _trainees_selector = (By.CSS_SELECTOR, 'div#trainees_group>div.bootstrap-select') + _training_started_selector = (By.XPATH, '//div[1]/div/div/form/div[4]/div') + _training_complete_selector = (By.XPATH, '//div[1]/div/div/form/div[4]/div') + _competency_assessed_selector = (By.XPATH, '//div[1]/div/div/form/div[5]/div') + + form_items = { + 'date': (regions.DatePicker, (By.ID, 'id_date')), + 'notes': (regions.TextBox, (By.ID, 'id_notes')), + } + + @property + def supervisor_selector(self): + return regions.BootstrapSelectElement(self, self.find_element(*self._supervisor_selector)) + + @property + def trainees_selector(self): + return regions.BootstrapSelectElement(self, self.find_element(*self._trainees_selector)) + + @property + def training_started_selector(self): + return regions.BootstrapSelectElement(self, self.find_element(*self._training_started_selector)) + + @property + def training_complete_selector(self): + return regions.BootstrapSelectElement(self, self.find_element(*self._training_complete_selector)) + + @property + def competency_assessed_selector(self): + return regions.BootstrapSelectElement(self, self.find_element(*self._competency_assessed_selector)) + + @property + def success(self): + return 'log' not in self.driver.current_url diff --git a/training/tests/test_interaction.py b/training/tests/test_interaction.py index 3d2c2112..bf5e2b13 100644 --- a/training/tests/test_interaction.py +++ b/training/tests/test_interaction.py @@ -12,6 +12,15 @@ from training import models from training.tests import pages +def select_super(page, supervisor): + page.supervisor_selector.toggle() + assert page.supervisor_selector.is_open + page.supervisor_selector.search(supervisor.name[:-6]) + time.sleep(2) # Slow down for javascript + assert page.supervisor_selector.options[0].selected + page.supervisor_selector.toggle() + + def test_add_qualification(logged_in_browser, live_server, trainee, supervisor, training_item): page = pages.AddQualification(logged_in_browser.driver, live_server.url, pk=trainee.pk).open() # assert page.name in str(trainee) @@ -30,12 +39,7 @@ def test_add_qualification(logged_in_browser, live_server, trainee, supervisor, assert page.item_selector.options[0].selected page.item_selector.toggle() - page.supervisor_selector.toggle() - assert page.supervisor_selector.is_open - page.supervisor_selector.search(supervisor.name[:-6]) - time.sleep(2) # Slow down for javascript - assert page.supervisor_selector.options[0].selected - page.supervisor_selector.toggle() + select_super(page, supervisor) page.submit() assert page.success @@ -44,3 +48,32 @@ def test_add_qualification(logged_in_browser, live_server, trainee, supervisor, assert qualification.date == date assert qualification.notes == "A note" assert qualification.depth == models.TrainingItemQualification.STARTED + + +def test_session_log(logged_in_browser, live_server, trainee, supervisor, training_item, training_item_2): + page = pages.SessionLog(logged_in_browser.driver, live_server.url).open() + + page.date = date = datetime.date(2001, 1, 10) + page.notes = note = "A general note" + + time.sleep(2) # Slow down for javascript + + select_super(page, supervisor) + + page.trainees_selector.toggle() + assert page.trainees_selector.is_open + page.trainees_selector.search(trainee.first_name) + time.sleep(2) # Slow down for javascript + page.trainees_selector.set_option(trainee.name, True) + # assert page.trainees_selector.options[0].selected + page.trainees_selector.toggle() + + page.training_started_selector.toggle() + assert page.training_started_selector.is_open + page.training_started_selector.search(training_item.description[:-2]) + time.sleep(2) # Slow down for javascript + # assert page.training_started_selector.options[0].selected + page.training_started_selector.toggle() + + page.submit() + assert page.success