Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full happy path 1 #38

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions cypress/e2e/exemption-happy-path.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,63 @@ describe('Happy passes', () => {
cy.get('.govuk-button').click()

cy.get('h1').should('include.text', 'Does your registrant have written permission to apply for a .gov.uk domain name?')
cy.get('#id_written_permission_1').click()
cy.get('.govuk-button').click()

cy.get('h1').should('include.text', 'Upload evidence of written permission')
cy.get('input[type=file]').selectFile('request_a_govuk_domain/static/images/govuk-crest.png')
cy.get('.govuk-button').click()

cy.get('h1').should('include.text', 'Upload evidence of written permission')
cy.get('a').should('include.text', 'govuk-crest.png')
cy.get('.govuk-button').click()

// Domain
cy.get('h1').should('include.text', 'What .gov.uk domain name do you want?')
cy.get('#id_domain_name').type('foobar')
cy.get('.govuk-button').click()

// Minister
cy.get('h1').should('include.text', 'Has a central government minister requested the domain name?')
cy.get('#id_minister_radios_1').click()
cy.get('.govuk-button').click()

// Minister upload
cy.get('h1').should('include.text', 'Upload evidence of the minister\'s request')
cy.get('input[type=file]').selectFile('request_a_govuk_domain/static/images/govuk-crest.png')
cy.get('.govuk-button').click()

// Minister upload confirmation
cy.get('h1').should('include.text', 'Upload evidence of the minister\'s request')
cy.get('a').should('include.text', 'govuk-crest.png')
cy.get('.govuk-button').click()

// Applicant details
cy.get('h1').should('include.text', 'Applicant details')
cy.get('#id_applicant_name').type('Joe Bloggs')
cy.get('#id_applicant_phone').type('01225672736')
cy.get('#id_applicant_email').type('[email protected]')
cy.get('.govuk-button').click()

// Registrant details
cy.get('h1').should('include.text', 'Registrant details')
cy.get('#id_registrant_full_name').type('Robert Smith')
cy.get('#id_registrant_phone').type('01225672345')
cy.get('#id_registrant_email_address').type('[email protected]')
cy.get('.govuk-button').click()

// Registry details
cy.get('h1').should('include.text', 'Registrant details for publishing to the registry')
cy.get('#id_registrant_role').type('Robert Smith')
cy.get('#id_registrant_contact_phone').type('01225672345')
cy.get('#id_registrant_contact_email').type('[email protected]')
cy.get('.govuk-button').click()

// Confirm
cy.get('h1').should('include.text', 'Check your answers')
cy.get('.govuk-button').click()

// Success
cy.get('h1').should('include.text', 'Application submitted')
})
})
108 changes: 98 additions & 10 deletions request_a_govuk_domain/request/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class ApplicantDetailsForm(forms.Form):
label="Full name",
)

applicant_phone_number = forms.CharField(
applicant_phone = forms.CharField(
label="Telephone number",
help_text="Your telephone number should be 11 digits. For example, 01632 660 001",
)

applicant_email_address = forms.CharField(
applicant_email = forms.CharField(
label="Email address",
)

Expand All @@ -90,8 +90,8 @@ def __init__(self, *args, **kwargs):
),
Fieldset(
HTML('<h2 class="govuk-heading-m">Applicant contact details</h2>'),
Field.text("applicant_phone_number", field_width=20),
Field.text("applicant_email_address"),
Field.text("applicant_phone", field_width=20),
Field.text("applicant_email"),
),
HTML(
"""<div class="govuk-inset-text">
Expand All @@ -103,11 +103,11 @@ def __init__(self, *args, **kwargs):


class RegistrantDetailsForm(forms.Form):
registrant_name = forms.CharField(
registrant_full_name = forms.CharField(
label="Full name",
)

registrant_phone_number = forms.CharField(
registrant_phone = forms.CharField(
label="Telephone number",
help_text="Your telephone number should be 11 digits. For example, 01632 660 001",
)
Expand All @@ -123,11 +123,11 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
Fieldset(
HTML('<h2 class="govuk-heading-m">Registrant name</h2>'),
Field.text("registrant_name", field_width=20),
Field.text("registrant_full_name", field_width=20),
),
Fieldset(
HTML('<h2 class="govuk-heading-m">Registrant contact details</h2>'),
Field.text("registrant_phone_number", field_width=20),
Field.text("registrant_phone", field_width=20),
Field.text("registrant_email_address"),
),
HTML(
Expand Down Expand Up @@ -305,7 +305,7 @@ def get_choice(self, field):


class MinisterForm(forms.Form):
exe_radio = forms.ChoiceField(
minister_radios = forms.ChoiceField(
label="",
help_text="""If the requested .gov.uk domain does not meet the domain naming rules, it could still be approved if it has ministerial support. For example, the domain is needed to support the creation of a new government department or body.""",
choices=(("yes", "Yes"), ("no", "No")),
Expand All @@ -318,7 +318,7 @@ def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.layout = Layout(
Field.radios(
"exe_radio",
"minister_radios",
legend_size=Size.MEDIUM,
legend_tag="h1",
inline=True,
Expand Down Expand Up @@ -375,6 +375,94 @@ def clean_file(self):
return file


class MinisterUploadForm(forms.Form):
file = forms.FileField(
label="Upload a file",
help_text="Support file is .jpeg or .png and the maximum size is 2.5 MB.",
error_messages={"required": "Choose the file you want to upload."},
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(
Field.text("file", field_width=Fluid.TWO_THIRDS),
),
Button("submit", "Upload evidence"),
)

def clean_file(self):
"""
Custom Error messages for
1. Size
2. Content Type
"""
file = self.cleaned_data.get("file")
if (
file is not None
and file.content_type.split("/")[0] in settings.CONTENT_TYPES
):
if file.size > int(settings.MAX_UPLOAD_SIZE):
raise forms.ValidationError(
("Please keep filesize under %s. Current filesize %s")
% (
filesizeformat(settings.MAX_UPLOAD_SIZE),
filesizeformat(file.size),
)
)
else:
raise forms.ValidationError(
"Support file is .jpeg or .png and the maximum size is 2.5 MB."
)

return file


class WrittenPermissionUploadForm(forms.Form):
file = forms.FileField(
label="Upload a file",
help_text="Support file is .jpeg or .png and the maximum size is 2.5 MB.",
error_messages={"required": "Choose the file you want to upload."},
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(
Field.text("file", field_width=Fluid.TWO_THIRDS),
),
Button("submit", "Upload evidence"),
)

def clean_file(self):
"""
Custom Error messages for
1. Size
2. Content Type
"""
file = self.cleaned_data.get("file")
if (
file is not None
and file.content_type.split("/")[0] in settings.CONTENT_TYPES
):
if file.size > int(settings.MAX_UPLOAD_SIZE):
raise forms.ValidationError(
("Please keep filesize under %s. Current filesize %s")
% (
filesizeformat(settings.MAX_UPLOAD_SIZE),
filesizeformat(file.size),
)
)
else:
raise forms.ValidationError(
"Support file is .jpeg or .png and the maximum size is 2.5 MB."
)

return file


class RegistrarForm(forms.Form):
"""
Registrar Form with organisations choice fields
Expand Down
39 changes: 24 additions & 15 deletions request_a_govuk_domain/request/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,28 @@ def is_valid_start_path(self, path: str):
return False

def is_valid_progress(self, request):
if request.session.get("registration_data") is None:
return False
for key in request.session.get("registration_data"):
if key not in [
"registrant_type",
"registrant_full_name",
"registrant_email_address",
"registrar_organisation",
"registrant_organisation_name",
"domain_purpose",
"domain_name",
]:
# A key in the session data is invalid. So go back to the beginning
request.session["registration_data"] = {}
return False
return True
# if request.session.get("registration_data") is None:
# return False
# for key in request.session.get("registration_data"):
# if key not in [
# "applicant_email",
# "applicant_name",
# "applicant_phone",
# "domain_name",
# "domain_purpose",
# "registrant_contact_email",
# "registrant_contact_phone",
# "registrant_email_address",
# "registrant_full_name",
# "registrant_organisation_name",
# "registrant_phone",
# "registrant_role",
# "registrant_type",
# "registrar_organisation",
# "written_permission",
# ]:
# # A key in the session data is invalid. So go back to the beginning
# request.session["registration_data"] = {}
# return False
# return True
2 changes: 1 addition & 1 deletion request_a_govuk_domain/request/templates/confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
{% load govuk_frontend_django %}

{% block main %}
<h1 class="govuk-heading-l">Check your answers</h1>
<form method="post" action="{% url 'confirm' %}">
{% csrf_token %}
<h2 class="govuk-heading-m">Registrar details</h2>

{% gds_summary_list %}
{% gds_summary_list_row %}
{% gds_summary_list_row_key %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ <h1 class="govuk-heading-l">
Upload evidence of the exemption
</h1>
<form method="post" action="{% url 'exemption_upload' %}" enctype="multipart/form-data">
{% csrf_token %}
{% crispy form %}
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion request_a_govuk_domain/request/templates/minister.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="govuk-grid-column-two-thirds">
{% error_summary form %}
<h1 class="govuk-heading-l">
Has a central government minister requested the {{ domain_name|safe }} domain name?
Has a central government minister requested the domain name?
</h1>
{% crispy form %}
</div>
Expand Down
27 changes: 27 additions & 0 deletions request_a_govuk_domain/request/templates/minister_upload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "base.html" %}
{% load crispy_forms_tags crispy_forms_gds %}
{% load govuk_frontend_django %}

{% block title %}Minister upload{% endblock %}

{% block main %}

{% block beforeContent %}
{% url "minister" as back_url %}
{% back_link back_url %}
{% endblock %}

{% block content %}
{% error_summary form %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
Upload evidence of the minister's request
</h1>

{% crispy form %}

</div>
</div>
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends "base.html" %}
{% load crispy_forms_tags crispy_forms_gds %}
{% load govuk_frontend_django %}

{% block title %}Minister upload confirm{% endblock %}

{% block main %}

{% block beforeContent %}
{% url "minister_upload" as back_url %}
{% back_link back_url %}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
Upload evidence of the minister's request
</h2>
<div class="govuk-hint">
Support file is .jpeg or .png and the maximum size is 10MB.
</div>

<dl class="govuk-summary-list govuk-summary-list--long-key">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<a class="govuk-link" href="/media/{{ file }}" target="_blank">{{ file }}</a>
</dt>
<dd class="govuk-summary-list__value">
<strong class="govuk-tag govuk-tag--green">
uploaded
</strong>
</dd>
<dd class="govuk-summary-list__actions">
<a class="govuk-link" href="/minister_upload">
Remove<span class="govuk-visually-hidden"> {{ file }}</span>
</a>
</dd>
</div>
</dl>
<a class="govuk-button" href="{% url "applicant_details" %}">
Continue
</a>
</div>
</div>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion request_a_govuk_domain/request/templates/success.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}

{% block main %}
<h1 class="govuk-heading-l">Thanks for submitting!</h1>
<h1 class="govuk-heading-l">Application submitted</h1>
{% endblock %}
Loading