Skip to content

Commit

Permalink
EES-4389 - added Next.js page caching for public Release pages. Updat…
Browse files Browse the repository at this point in the history
…ed UI tests to expect stale pages and refreshes for this feature, and cache expiry for Publication list on Find Stats page.
  • Loading branch information
duncan-at-hiveit committed Jul 7, 2023
1 parent 7f0ab67 commit 27246d0
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using GovUk.Education.ExploreEducationStatistics.Common.Model;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace GovUk.Education.ExploreEducationStatistics.Common.ViewModels;

Expand All @@ -19,6 +20,13 @@ public PaginatedListViewModel(List<T> results, int totalResults, int page, int p
Paging = new PagingViewModel(page: page, pageSize: pageSize, totalResults: totalResults);
}

[JsonConstructor]
public PaginatedListViewModel(List<T> results, PagingViewModel paging)
{
Results = results;
Paging = paging;
}

/// <summary>
/// Paginate some results (in memory) that have not been paginated yet.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import FormFieldSelect from '@common/components/form/FormFieldSelect';
import FormFieldTextInput from '@common/components/form/FormFieldTextInput';
import FormSelect, { SelectOption } from '@common/components/form/FormSelect';
import Tooltip from '@common/components/Tooltip';
import VisuallyHidden from '@common/components/VisuallyHidden';
import {
AxisType,
ChartDefinitionAxis,
Expand Down
3 changes: 2 additions & 1 deletion src/explore-education-statistics-frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ CONTENT_API_BASE_URL=http://localhost:5010/api
DATA_API_BASE_URL=http://localhost:5000/api
NOTIFICATION_API_BASE_URL=http://localhost:7073/api
GA_TRACKING_ID=
PUBLIC_URL=http://localhost:3000/
PUBLIC_URL=http://localhost:3000/
APP_ENV=Local
1 change: 1 addition & 0 deletions src/explore-education-statistics-frontend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if (process.env.APPINSIGHTS_INSTRUMENTATIONKEY) {
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true)
.setUseDiskRetryCaching(true)
.setSendLiveMetrics(true)
.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { logEvent } from '@frontend/services/googleAnalyticsService';
import glossaryService from '@frontend/services/glossaryService';
import classNames from 'classnames';
import orderBy from 'lodash/orderBy';
import { GetServerSideProps, NextPage } from 'next';
import { GetStaticPaths, GetStaticProps, NextPage } from 'next';
import React from 'react';
import VisuallyHidden from '@common/components/VisuallyHidden';
import ScrollableContainer from '@common/components/ScrollableContainer';
Expand Down Expand Up @@ -571,13 +571,11 @@ const PublicationReleasePage: NextPage<Props> = ({ release }) => {
);
};

export const getServerSideProps: GetServerSideProps<Props> = async ({
query,
}) => {
export const getStaticProps: GetStaticProps<Props> = async ({ params }) => {
const {
publication: publicationSlug,
release: releaseSlug,
} = query as Dictionary<string>;
} = params as Dictionary<string>;

const release = await (releaseSlug
? publicationService.getPublicationRelease(publicationSlug, releaseSlug)
Expand All @@ -587,6 +585,14 @@ export const getServerSideProps: GetServerSideProps<Props> = async ({
props: {
release,
},
revalidate: process.env.APP_ENV === 'Local' ? 2 : 10,
};
};

export const getStaticPaths: GetStaticPaths = async () => {
return {
paths: [],
fallback: 'blocking',
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
default,
getServerSideProps,
getStaticProps,
getStaticPaths,
} from '@frontend/modules/find-statistics/PublicationReleasePage';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
default,
getServerSideProps,
getStaticProps,
getStaticPaths,
} from '@frontend/modules/find-statistics/PublicationReleasePage';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare namespace NodeJS {
interface ProcessEnv {
APP_ENV: 'Production' | 'Pre-Production' | 'Test' | 'Development';
APP_ENV: 'Production' | 'Pre-Production' | 'Test' | 'Development' | 'Local';
APPINSIGHTS_INSTRUMENTATIONKEY: string;
BUILD_NUMBER: string;
GA_TRACKING_ID: string;
Expand Down
2 changes: 1 addition & 1 deletion tests/robot-tests/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ANALYST_PASSWORD=ANALYST_PASSWORD # Analyst1 user password
EXPIRED_INVITE_USER_EMAIL= # Expired Invite user email
EXPIRED_INVITE_USER_PASSWORD= # Expired Invite user password
RELEASE_COMPLETE_WAIT=120 # Time to wait for a release to publish (in seconds)
WAIT_MEMORY_CACHE_EXPIRY=2 # Time to wait for the memory cache to expire (in seconds. Local = 2, Dev = 10)
WAIT_CACHE_EXPIRY=2 # Time to wait for the environment's various caches to expire (in seconds. Local = 2, Dev = 10)
WAIT_MEDIUM=120 # Variable used throughout tests (in seconds)
WAIT_SMALL=45 # Variable used throughout tests (in seconds)
WAIT_LONG=180 # Variable used throughout tests (in seconds)
Expand Down
2 changes: 1 addition & 1 deletion tests/robot-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
"WAIT_SMALL",
"FAIL_TEST_SUITES_FAST",
"IDENTITY_PROVIDER",
"WAIT_MEMORY_CACHE_EXPIRY",
"WAIT_CACHE_EXPIRY",
"EXPIRED_INVITE_USER_EMAIL",
"PUBLISHER_FUNCTIONS_URL",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,14 @@ Check public superseding-publication release page displays correctly
user waits until page contains This is the latest data

Check public archive-publication release page displays correctly
user waits for caches to expire

user navigates to public frontend ${PUBLICATION_ARCHIVE_URL}
user waits until h1 is visible ${PUBLICATION_NAME_ARCHIVE} %{WAIT_MEDIUM}

user reloads the stale cached page
user waits until h1 is visible ${PUBLICATION_NAME_ARCHIVE} %{WAIT_MEDIUM}

user checks page does not contain This is the latest data

Check public archive-publication release page displays superseded warning
Expand Down Expand Up @@ -386,7 +392,7 @@ Set archive-publication to be no longer be superseded
user clicks button Confirm ${modal}
user waits until modal is not visible Confirm publication changes

sleep %{WAIT_MEMORY_CACHE_EXPIRY}
user waits for caches to expire

Check can create a release for archive-publication which is no longer archived
[Documentation] Failing due to https://dfedigital.atlassian.net/browse/EES-4269
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*** Settings ***
Resource ../../libs/public-common.robot
Resource ../../libs/admin-common.robot
Resource ../../libs/admin/manage-content-common.robot
Library ../../libs/admin_api.py
Expand Down Expand Up @@ -88,7 +89,6 @@ Update legacy release
user enters text into element id:legacyReleaseForm-description ${UPDATED_DESCRIPTION}
user enters text into element id:legacyReleaseForm-url http://test2.com
user clicks button Save legacy release
sleep %{WAIT_MEMORY_CACHE_EXPIRY}

Validate updated legacy release
user waits until h2 is visible Legacy releases
Expand All @@ -98,7 +98,13 @@ Validate updated legacy release
user checks table cell contains 1 3 http://test2.com

Validate public frontend shows changes made to legacy release after saving publication
user waits for caches to expire

user navigates to public frontend ${PUBLIC_RELEASE_LINK}
user waits until h1 is visible ${PUBLICATION_NAME} %{WAIT_MEDIUM}

user reloads the stale cached page
user waits until h1 is visible ${PUBLICATION_NAME} %{WAIT_MEDIUM}

user opens details dropdown View releases (1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ Approve release
user approves original release for immediate publication

Verify newly published release is on Find Statistics page
user waits for caches to expire

user checks publication is on find statistics page ${PUBLICATION_NAME}

Navigate to published release page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,16 @@ Approve amendment for scheduled release
set suite variable ${EXPECTED_PUBLISHED_DATE}

Verify amendment is on Find Statistics page again
user waits for caches to expire
user checks publication is on find statistics page ${PUBLICATION_NAME}

Navigate to amendment release page
user clicks link ${PUBLICATION_NAME}
user waits until h1 is visible ${PUBLICATION_NAME} %{WAIT_MEDIUM}

user reloads the stale cached page
user waits until h1 is visible ${PUBLICATION_NAME} %{WAIT_MEDIUM}

user waits until page contains title caption ${RELEASE_NAME}

user checks url contains %{PUBLIC_URL}/find-statistics/ui-tests-publish-release-and-amend-%{RUN_IDENTIFIER}
Expand Down Expand Up @@ -948,8 +953,12 @@ Verify published date on publication page has been updated
user checks element contains ${row} ${EXPECTED_PUBLISHED_DATE}

Navigate to amended public release
user waits for caches to expire
user navigates to public frontend ${PUBLIC_RELEASE_LINK}
user waits until h1 is visible ${PUBLICATION_NAME}
user waits until h1 is visible ${PUBLICATION_NAME} %{WAIT_MEDIUM}

user reloads the stale cached page
user waits until h1 is visible ${PUBLICATION_NAME} %{WAIT_MEDIUM}

Verify public published date has been updated
user checks summary list contains Published ${EXPECTED_PUBLISHED_DATE}
Expand Down
3 changes: 3 additions & 0 deletions tests/robot-tests/tests/libs/common.robot
Original file line number Diff line number Diff line change
Expand Up @@ -982,3 +982,6 @@ user takes html snapshot of element
${element}= lookup or return webelement ${selector_or_webelement}
${filepath}= take html snapshot of element ${element} ${filename}
[Return] ${filepath}

user waits for caches to expire
sleep %{WAIT_CACHE_EXPIRY}
7 changes: 7 additions & 0 deletions tests/robot-tests/tests/libs/public-common.robot
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@ user checks methodology note
[Arguments] ${number} ${displayDate} ${content}
user waits until element contains css:#methodologyNotes li:nth-of-type(${number}) time ${displayDate}
user waits until element contains css:#methodologyNotes li:nth-of-type(${number}) p ${content}

# Next.js will have returned a stale cached page for the last request and will have created a new cached page in
# the background in the meantime, so request the page again.

user reloads the stale cached page
sleep 3
user reloads page

0 comments on commit 27246d0

Please sign in to comment.