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

Update Prepop branch with changes from main #1153

Merged
merged 25 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
08b0304
Make response expiry date mandatory (#1104)
petechd May 18, 2023
18d09f4
Bind additional contexts to flush requests (#1108)
petechd May 18, 2023
cee23dc
Schemas v3.56.0 (#1110)
MebinAbraham May 23, 2023
36fb6c7
Schemas v3.57.0 (#1113)
MebinAbraham May 25, 2023
fdc0f75
Schemas v3.57.1 (#1115)
MebinAbraham May 26, 2023
c2439d8
Schemas v3.58.0 (#1116)
MebinAbraham May 26, 2023
cc12488
Implement "progress" value source (#1044)
ONS-Guilhem-Forey May 26, 2023
82b2abe
Fix handling of invalid values in form numerical inputs (#1111)
petechd May 30, 2023
f404619
Update Chromedriver to version 113 (#1118)
katie-gardner Jun 1, 2023
12fb8ff
Feat/Grand calculated summary (#1107)
katie-gardner Jun 2, 2023
d5f7173
Fix dynamic answers functional test (#1121)
petechd Jun 6, 2023
ab19672
Schemas v3.59.0 (#1130)
berroar Jun 7, 2023
a2986c0
Schemas v3.60.0 (#1133)
berroar Jun 8, 2023
090e652
Update to chromedriver v114 (#1134)
berroar Jun 9, 2023
1dcf278
Add DESNZ theme (#1131)
petechd Jun 12, 2023
d04325c
Schemas v3.61.0 (#1139)
berroar Jun 13, 2023
f5d1b7d
Add schema changes for validator format_unit using calculated summary…
petechd Jun 20, 2023
c0bb6bb
Schemas v3.62.0 (#1144)
berroar Jun 20, 2023
004c882
Bump cryptography from 40.0.2 to 41.0.0 (#1124)
dependabot[bot] Jun 23, 2023
d2dc26a
Fix mass-metric-ton units handling (#1146)
petechd Jun 26, 2023
deb64a7
Fix unit label hover title for metric ton (#1150)
petechd Jun 30, 2023
f11fa2c
Fix list collector placeholders not resolving when preview enabled (#…
petechd Jul 3, 2023
3a3031d
Merge main into feature-prepop
MebinAbraham Jul 4, 2023
fa46ce7
Schemas v3.63.0 (#1155)
petechd Jul 5, 2023
ae7e45b
Merge remote-tracking branch 'origin/main' into merge-main-into-featu…
MebinAbraham Jul 5, 2023
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
2 changes: 1 addition & 1 deletion .schemas-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.61.0
v3.63.0
369 changes: 193 additions & 176 deletions Pipfile.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions app/jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ def format_unit(
value: int | float | Decimal,
length: UnitLengthType = "short",
) -> str:
# mass-metric-ton no longer supported for en_GB and related locales, but still present in business schema and allowed in validator,
# until removed from schema we substitute mass-tonne for mass-metric-ton before format unit
measurement_unit = "mass-tonne" if unit == "mass-metric-ton" else unit

formatted_unit: str = units.format_unit(
value=value,
measurement_unit=unit,
measurement_unit=measurement_unit,
length=length,
locale=flask_babel.get_locale(),
)

return formatted_unit


Expand All @@ -93,20 +98,15 @@ def format_unit_input_label(unit: str, unit_length: UnitLengthType = "short") ->
:param (str) unit_length length of unit text, can be one of short/long/narrow
"""
unit_label: str

if unit_length == "long":
unit_label = units.format_unit(
value=2,
measurement_unit=unit,
length=unit_length,
locale=flask_babel.get_locale(),
).replace("2 ", "")
unit_label = format_unit(value=2, unit=unit, length=unit_length).replace(
"2 ", ""
)
else:
# Type ignore: We pass an empty string as the value so that we just return the unit label
unit_label = units.format_unit(
value="", # type: ignore
measurement_unit=unit,
length=unit_length,
locale=flask_babel.get_locale(),
unit_label = format_unit(
value="", unit=unit, length=unit_length # type: ignore
).strip()

return unit_label
Expand Down
7 changes: 6 additions & 1 deletion app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from app.routes.schema import schema_blueprint
from app.routes.session import session_blueprint
from app.secrets import SecretStore, validate_required_secrets
from app.settings import DEFAULT_LOCALE
from app.storage import Datastore, Dynamodb, Redis
from app.submitter import (
GCSFeedbackSubmitter,
Expand Down Expand Up @@ -479,7 +480,11 @@ def get_minimized_asset(filename):


def get_locale():
return cookie_session.get("language_code")
return (
DEFAULT_LOCALE
if cookie_session.get("language_code") == "en"
else cookie_session.get("language_code")
)


def get_timezone():
Expand Down
3 changes: 2 additions & 1 deletion app/views/contexts/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(
progress_store: ProgressStore,
metadata: MetadataProxy | None,
response_metadata: MutableMapping,
placeholder_preview_mode: bool = False,
) -> None:
self._language = language
self._schema = schema
Expand All @@ -28,7 +29,7 @@ def __init__(
self._progress_store = progress_store
self._metadata = metadata
self._response_metadata = response_metadata
self._placeholder_preview_mode = self._schema.preview_enabled
self._placeholder_preview_mode = placeholder_preview_mode

self._router = Router(
schema=self._schema,
Expand Down
1 change: 1 addition & 0 deletions app/views/contexts/preview_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(
progress_store,
metadata,
response_metadata,
placeholder_preview_mode=True,
)

def __call__(self) -> dict[str, Union[str, list, bool]]:
Expand Down
1 change: 1 addition & 0 deletions app/views/contexts/section_preview_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
progress_store,
metadata,
response_metadata,
placeholder_preview_mode=True,
)
self._section_id = section_id

Expand Down
44 changes: 42 additions & 2 deletions schemas/test/en/test_calculated_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
]
},
{
"text": "Total unit values: <em>{unit_total}</em>",
"text": "Total unformatted unit values: <em>{unit_total}</em>",
"placeholders": [
{
"placeholder": "unit_total",
Expand All @@ -364,7 +364,28 @@
]
},
{
"text": "Total percentage values: <em>{percentage_total}</em>",
"text": "Total formatted unit values: <em>{unit_total}</em>",
"placeholders": [
{
"placeholder": "unit_total",
"transforms": [
{
"transform": "format_unit",
"arguments": {
"value": {
"source": "calculated_summary",
"identifier": "unit-total-playback"
},
"unit": "length-centimeter",
"unit_length": "short"
}
}
]
}
]
},
{
"text": "Total unformatted percentage values: <em>{percentage_total}</em>",
"placeholders": [
{
"placeholder": "percentage_total",
Expand All @@ -382,6 +403,25 @@
}
]
},
{
"text": "Total formatted percentage values: <em>{percentage_total}</em>",
"placeholders": [
{
"placeholder": "percentage_total",
"transforms": [
{
"transform": "format_percentage",
"arguments": {
"value": {
"source": "calculated_summary",
"identifier": "percentage-total-playback"
}
}
}
]
}
]
},
{
"text": "Total number values: <em>{number_total}</em>",
"placeholders": [
Expand Down
5 changes: 5 additions & 0 deletions schemas/test/en/test_list_collector_list_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"data_version": "0.0.3",
"survey_id": "0",
"title": "Test ListCollector",
"preview_questions": true,
"theme": "default",
"description": "A questionnaire to test ListCollector",
"metadata": [
Expand Down Expand Up @@ -111,6 +112,10 @@
"id": "group",
"title": "Questions",
"blocks": [
{
"id": "introduction",
"type": "Introduction"
},
{
"id": "primary-person-list-collector",
"type": "PrimaryPersonListCollector",
Expand Down
44 changes: 42 additions & 2 deletions schemas/test/en/test_new_calculated_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
]
},
{
"text": "Total unit values: <em>{unit_total}</em>",
"text": "Total unformatted unit values: <em>{unit_total}</em>",
"placeholders": [
{
"placeholder": "unit_total",
Expand All @@ -413,7 +413,28 @@
]
},
{
"text": "Total percentage values: <em>{percentage_total}</em>",
"text": "Total formatted unit values: <em>{unit_total}</em>",
"placeholders": [
{
"placeholder": "unit_total",
"transforms": [
{
"transform": "format_unit",
"arguments": {
"value": {
"source": "calculated_summary",
"identifier": "unit-total-playback"
},
"unit": "length-centimeter",
"unit_length": "short"
}
}
]
}
]
},
{
"text": "Total unformatted percentage values: <em>{percentage_total}</em>",
"placeholders": [
{
"placeholder": "percentage_total",
Expand All @@ -431,6 +452,25 @@
}
]
},
{
"text": "Total formatted percentage values: <em>{percentage_total}</em>",
"placeholders": [
{
"placeholder": "percentage_total",
"transforms": [
{
"transform": "format_percentage",
"arguments": {
"value": {
"source": "calculated_summary",
"identifier": "percentage-total-playback"
}
}
}
]
}
]
},
{
"text": "Total number values: <em>{number_total}</em>",
"placeholders": [
Expand Down
19 changes: 19 additions & 0 deletions schemas/test/en/test_unit_patterns.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@
"title": "Volume Units",
"type": "General"
}
},
{
"type": "Question",
"id": "set-weight-units-block",
"question": {
"answers": [
{
"id": "mass-metric-ton",
"label": "Mass tonnes",
"mandatory": false,
"type": "Unit",
"unit": "mass-metric-ton",
"unit_length": "short"
}
],
"id": "set-weight-unit-questions",
"title": "Weight Units",
"type": "General"
}
}
],
"id": "test"
Expand Down
5 changes: 5 additions & 0 deletions tests/app/test_jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def test_format_percentage(percentage, formatted_percentage):
("duration-year", 100, "short", "100 bl", "cy"),
("duration-hour", 100, "long", "100 awr", "cy"),
("duration-year", 100, "long", "100 mlynedd", "cy"),
("mass-metric-ton", 100, "long", "100 tonnes", "en_GB"),
("mass-metric-ton", 1, "long", "1 tonne", "en_GB"),
("mass-metric-ton", 100, "short", "100 t", "en_GB"),
),
)
def test_format_unit(unit, value, length, formatted_unit, language, mocker):
Expand Down Expand Up @@ -204,6 +207,8 @@ def test_format_unit(unit, value, length, formatted_unit, language, mocker):
("duration-hour", "long", "awr", "cy"),
("duration-year", "short", "bl", "cy"),
("duration-year", "long", "flynedd", "cy"),
("mass-metric-ton", "long", "tonnes", "en_GB"),
("mass-metric-ton", "short", "t", "en_GB"),
),
)
def test_format_unit_input_label(unit, length, formatted_unit, language, mocker):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,14 @@ class TestCase {
await browser.url(CalculatedSummaryTotalConfirmation.url());
await expect(await browser.getUrl()).to.contain(CalculatedSummaryTotalConfirmation.pageName);
const content = await $("h1 + ul").getText();
const textsToAssert = ["Total currency values: £25.92", "Total unit values: 1,467", "Total percentage values: 79", "Total number values: 124.58"];
const textsToAssert = [
"Total currency values: £25.92",
"Total unformatted unit values: 1,467",
"Total formatted unit values: 1,467 cm",
"Total unformatted percentage values: 79",
"Total formatted percentage values: 79%",
"Total number values: 124.58",
];

textsToAssert.forEach((text) => expect(content).to.contain(text));
await browser.url(SubmitPage.url());
Expand Down
19 changes: 16 additions & 3 deletions tests/functional/spec/features/units.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SetLengthUnitsBlockPage from "../../generated_pages/unit_patterns/set-len
import SetDurationUnitsBlockPage from "../../generated_pages/unit_patterns/set-duration-units-block.page.js";
import SetAreaUnitsBlockPage from "../../generated_pages/unit_patterns/set-area-units-block.page.js";
import SetVolumeUnitsBlockPage from "../../generated_pages/unit_patterns/set-volume-units-block.page.js";
import SetWeightUnitsBlockPage from "../../generated_pages/unit_patterns/set-weight-units-block.page.js";
import SubmitPage from "../../generated_pages/unit_patterns/submit.page.js";

describe("Units", () => {
Expand All @@ -15,6 +16,7 @@ describe("Units", () => {
await $(SetDurationUnitsBlockPage.submit()).click();
await $(SetAreaUnitsBlockPage.submit()).click();
await $(SetVolumeUnitsBlockPage.submit()).click();
await $(SetWeightUnitsBlockPage.submit()).click();
await expect(await $(SubmitPage.durationHour()).getText()).to.equal("6 hours");
await expect(await $(SubmitPage.durationYear()).getText()).to.equal("20 years");
});
Expand All @@ -31,15 +33,26 @@ describe("Units", () => {
await $(SetDurationUnitsBlockPage.submit()).click();
await $(SetAreaUnitsBlockPage.submit()).click();
await $(SetVolumeUnitsBlockPage.submit()).click();
await $(SetWeightUnitsBlockPage.submit()).click();
await expect(await $(SubmitPage.durationHour()).getText()).to.equal("6 awr");
await expect(await $(SubmitPage.durationYear()).getText()).to.equal("20 mlynedd");
});

it("Given we open a questionnaire with unit labels, when the label is highlighted by the tooltip, then the long unit label should be displayed.", async () => {
await browser.openQuestionnaire("test_unit_patterns.json", { language: "en" });
await expect(await $(SetLengthUnitsBlockPage.centimetresUnit()).getAttribute("title")).to.equal("centimeters");
await expect(await $(SetLengthUnitsBlockPage.metresUnit()).getAttribute("title")).to.equal("meters");
await expect(await $(SetLengthUnitsBlockPage.kilometresUnit()).getAttribute("title")).to.equal("kilometers");
await expect(await $(SetLengthUnitsBlockPage.centimetresUnit()).getAttribute("title")).to.equal("centimetres");
await expect(await $(SetLengthUnitsBlockPage.metresUnit()).getAttribute("title")).to.equal("metres");
await expect(await $(SetLengthUnitsBlockPage.kilometresUnit()).getAttribute("title")).to.equal("kilometres");
await expect(await $(SetLengthUnitsBlockPage.milesUnit()).getAttribute("title")).to.equal("miles");
});

it("Given we open a questionnaire with unit labels, when the weight unit label is highlighted by the tooltip, then the correct unit label should be displayed.", async () => {
await browser.openQuestionnaire("test_unit_patterns.json", { language: "en" });
await $(SetLengthUnitsBlockPage.submit()).click();
await $(SetDurationUnitsBlockPage.submit()).click();
await $(SetAreaUnitsBlockPage.submit()).click();
await $(SetVolumeUnitsBlockPage.submit()).click();
await expect(await $("body").getText()).to.have.string("tonnes");
await expect(await $("body").getText()).to.not.have.string("metric tons");
});
});
Loading