Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CamLamb committed Sep 1, 2023
1 parent 7e328d0 commit ca372ee
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
12 changes: 7 additions & 5 deletions src/e2e_tests/pages/peoplefinder/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def goto_profile_view_page(self):
self.page.get_by_text("Back to profile").click()
return ProfileViewPage(self.page)

def goto_profile_edit_team_page(self):
self.page.get_by_text("Team and role").click()
return ProfileEditPage(self.page)

@property
def first_name(self):
return self.page.get_attribute("input[name=first_name]", "value")
Expand Down Expand Up @@ -56,16 +60,14 @@ def add_role(self, job_title: str, head_of_team: bool):
self.page.get_by_test_id("add-role").click()

# The new role form should be the last one.
form = self.page.get_by_test_id("role-form").last
formset = self.page.get_by_test_id("role-formset").last
# Lets fill out the form.
form.get_by_label("Job title").fill(job_title)
formset.get_by_test_id("job-title").fill(job_title)

# The head_of_team input should default to false, so we only need to click it if
# we need to set it to true.
if head_of_team:
form.get_by_label("Head of team").click()

self.page.get_by_test_id("save-role").click()
formset.get_by_label("Head of team").click()

def save_profile(self):
self.page.get_by_test_id("save-profile").click()
Expand Down
7 changes: 4 additions & 3 deletions src/e2e_tests/test_peoplefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def test_profile(superuser, user, page: Page):
# Profile edit page
profile_edit_page = profile_view_page.goto_profile_edit_page()
assert profile_edit_page.first_name == "John"
assert profile_edit_page.manager == "Super User"
profile_edit_page.add_role(job_title="CEO", head_of_team=True)
profile_edit_page.save_profile()
profile_edit_team_page = profile_edit_page.goto_profile_edit_team_page()
assert profile_edit_team_page.manager == "Super User"
profile_edit_team_page.add_role(job_title="CEO", head_of_team=True)
profile_edit_team_page.save_profile()

# Updated profile page
profile_view_page = profile_edit_page.goto_profile_view_page()
Expand Down
6 changes: 5 additions & 1 deletion src/peoplefinder/forms/crispy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def __init__(self, *args, **kwargs):
legend="Team",
),
Fieldset(
"job_title",
Field(
"job_title",
data_testid="job-title",
),
"head_of_team",
legend_size=Size.SMALL,
legend="Job title",
Expand Down Expand Up @@ -46,5 +49,6 @@ def __init__(self, *args, **kwargs):
"""
),
data_formset_form="",
data_testid="role-formset",
),
)
3 changes: 2 additions & 1 deletion src/peoplefinder/services/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def get_profile_section_mapping(

def get_profile_section_values(
self, person: "Person", profile_section: ProfileSections
) -> List[Tuple[str, str]]:
) -> List[Tuple[str, str, str]]:
profile_section_fields = self.get_profile_section_mapping(
profile_section,
).get("fields", [])
Expand All @@ -506,6 +506,7 @@ def get_profile_section_values(
if field_value not in [None, ""]:
values.append(
(
field_name,
field_label,
field_value,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<a href="{% url 'profile-view' profile.slug %}"
class="govuk-link"
{% if data_testid %}data-testid="data_testid"{% endif %}>{{ profile.full_name }}</a>
{% if data_testid %}data-testid="{{ data_testid }}"{% endif %}>{{ profile.full_name }}</a>
5 changes: 3 additions & 2 deletions src/peoplefinder/templates/peoplefinder/profile-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ <h2 class="govuk-heading-m" id="team-and-role-heading">Team and role</h2>
<div data-formset="{{ teams_formset.prefix }}">
{% crispy teams_formset teams_formset_helper %}
<button class="govuk-button govuk-button--secondary"
data-formset-add="{{ teams_formset_blank_form_url }}">Add a role</button>
data-formset-add="{{ teams_formset_blank_form_url }}"
data-testid="add-role">Add a role</button>
</div>
{% endif %}
<br>
<button class="govuk-button" type="submit">Save section</button>
<button class="govuk-button" type="submit" data-testid="save-profile">Save section</button>
</form>
<p class="govuk-body-s">
All the information on your profile will be visible to DBT staff and contractors on
Expand Down
14 changes: 9 additions & 5 deletions src/peoplefinder/templates/peoplefinder/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ <h1 class="govuk-heading-l mb-0" data-testid="full-name">{{ profile.full_name }}
<dt class="govuk-visually-hidden">Preferred email</dt>
{% if profile.contact_email %}
<dd>
<a href="mailto:{{ profile.contact_email }}" class="govuk-link">{{ profile.contact_email }}</a>
<a href="mailto:{{ profile.contact_email }}"
class="govuk-link"
data-testid="preferred-email">{{ profile.contact_email }}</a>
</dd>
{% else %}
<dd>
<a href="mailto:{{ profile.email }}" class="govuk-link">{{ profile.email }}</a>
<a href="mailto:{{ profile.email }}"
class="govuk-link"
data-testid="preferred-email">{{ profile.email }}</a>
</dd>
{% endif %}

Expand Down Expand Up @@ -156,9 +160,9 @@ <h2 class="govuk-summary-card__title">{{ profile_section.title }}</h2>
<dl class="govuk-summary-list">
{% for profile_value in profile_section.values %}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ profile_value.0 }}</dt>
<dd class="govuk-summary-list__value">
{{ profile_value.1 }}
<dt class="govuk-summary-list__key">{{ profile_value.1 }}</dt>
<dd class="govuk-summary-list__value" data-testid="{{ profile_value.0 }}">
{{ profile_value.2 }}
</dd>
</div>
{% empty %}
Expand Down

0 comments on commit ca372ee

Please sign in to comment.