diff --git a/frontend/src/__tests__/components/molecules/MessageTemplates.test.tsx b/frontend/src/__tests__/components/molecules/MessageTemplates.test.tsx index f26be0d95..e57f52eba 100644 --- a/frontend/src/__tests__/components/molecules/MessageTemplates.test.tsx +++ b/frontend/src/__tests__/components/molecules/MessageTemplates.test.tsx @@ -24,8 +24,8 @@ const messageTemplatesProps: { templateStatus: 'SUBMITTED', name: 'Template 2', message: 'Message', - createdAt: '2021-02-01T00:00:00.000Z', - updatedAt: '2021-02-01T00:00:00.000Z', + createdAt: '2021-01-01T00:00:00.000Z', + updatedAt: '2021-03-01T00:00:00.000Z', }, { id: '3', @@ -120,7 +120,7 @@ describe('MessageTemplates component', () => { ).toBeInTheDocument(); expect( screen.getByTestId('manage-template-table-header-template-date-created') - ).toHaveTextContent(messageTemplatesContent.tableHeadings.dateCreated); + ).toHaveTextContent(messageTemplatesContent.tableHeadings.lastEdited); expect( screen.getByTestId('manage-template-table-header-action') ).toBeInTheDocument(); diff --git a/frontend/src/__tests__/components/molecules/__snapshots__/MessageTemplates.test.tsx.snap b/frontend/src/__tests__/components/molecules/__snapshots__/MessageTemplates.test.tsx.snap index 439e34840..f58f008d7 100644 --- a/frontend/src/__tests__/components/molecules/__snapshots__/MessageTemplates.test.tsx.snap +++ b/frontend/src/__tests__/components/molecules/__snapshots__/MessageTemplates.test.tsx.snap @@ -58,7 +58,7 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1 data-testid="manage-template-table-header-template-date-created" scope="col" > - Date created + Last edited - Date created + Last edited 1st Jan 2021
@@ -251,9 +251,9 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1 aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited - 1st Feb 2021 + 1st Mar 2021
00:00 @@ -352,7 +352,7 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1 aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited 1st Feb 2021
@@ -440,7 +440,7 @@ exports[`MessageTemplates component matches snapshot with not submitted status 1 aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited 1st Feb 2021
@@ -538,7 +538,7 @@ exports[`MessageTemplates component matches snapshot with pending proof request data-testid="manage-template-table-header-template-date-created" scope="col" > - Date created + Last edited - Date created + Last edited 1st Jan 2021
@@ -731,9 +731,9 @@ exports[`MessageTemplates component matches snapshot with pending proof request aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited - 1st Feb 2021 + 1st Mar 2021
00:00 @@ -832,7 +832,7 @@ exports[`MessageTemplates component matches snapshot with pending proof request aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited 1st Feb 2021
@@ -920,7 +920,7 @@ exports[`MessageTemplates component matches snapshot with pending proof request aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited 1st Feb 2021
@@ -1018,7 +1018,7 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] = data-testid="manage-template-table-header-template-date-created" scope="col" > - Date created + Last edited - Date created + Last edited 1st Jan 2021
@@ -1200,9 +1200,9 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] = aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited - 1st Feb 2021 + 1st Mar 2021
00:00 @@ -1301,7 +1301,7 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] = aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited 1st Feb 2021
@@ -1389,7 +1389,7 @@ exports[`MessageTemplates component matches snapshot with submitted status 1`] = aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited 1st Feb 2021
@@ -1487,7 +1487,7 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat data-testid="manage-template-table-header-template-date-created" scope="col" > - Date created + Last edited - Date created + Last edited 1st Jan 2021
@@ -1656,9 +1656,9 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited - 1st Feb 2021 + 1st Mar 2021
00:00 @@ -1757,7 +1757,7 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited 1st Feb 2021
@@ -1845,7 +1845,7 @@ exports[`MessageTemplates component matches snapshot with waiting for proof stat aria-hidden="true" class="nhsuk-table-responsive__heading" > - Date created + Last edited 1st Feb 2021
diff --git a/frontend/src/__tests__/utils/form-actions.test.ts b/frontend/src/__tests__/utils/form-actions.test.ts index d1cd76bca..e33854f24 100644 --- a/frontend/src/__tests__/utils/form-actions.test.ts +++ b/frontend/src/__tests__/utils/form-actions.test.ts @@ -490,23 +490,23 @@ describe('form-actions', () => { await expect(getTemplates()).rejects.toThrow('Failed to get access token'); }); - test('getTemplates - order by createdAt and then id', async () => { + test('getTemplates - order by updatedAt and then id', async () => { const baseTemplate = { templateType: 'SMS', templateStatus: 'NOT_YET_SUBMITTED', name: 'Template', message: 'Message', - updatedAt: '2021-01-01T00:00:00.000Z', + createdAt: '2020-01-01T00:00:00.000Z', } satisfies Partial; const templates = [ - { ...baseTemplate, id: '06', createdAt: '2022-01-01T00:00:00.000Z' }, - { ...baseTemplate, id: '08', createdAt: '2020-01-01T00:00:00.000Z' }, - { ...baseTemplate, id: '05', createdAt: '2021-01-01T00:00:00.000Z' }, - { ...baseTemplate, id: '02', createdAt: '2021-01-01T00:00:00.000Z' }, - { ...baseTemplate, id: '01', createdAt: '2021-01-01T00:00:00.000Z' }, - { ...baseTemplate, id: '03', createdAt: '2021-01-01T00:00:00.000Z' }, - { ...baseTemplate, id: '04', createdAt: '2021-01-01T00:00:00.000Z' }, + { ...baseTemplate, id: '06', updatedAt: '2022-01-01T00:00:00.000Z' }, + { ...baseTemplate, id: '08', updatedAt: '2020-01-01T00:00:00.000Z' }, + { ...baseTemplate, id: '05', updatedAt: '2021-01-01T00:00:00.000Z' }, + { ...baseTemplate, id: '02', updatedAt: '2021-01-01T00:00:00.000Z' }, + { ...baseTemplate, id: '01', updatedAt: '2021-01-01T00:00:00.000Z' }, + { ...baseTemplate, id: '03', updatedAt: '2021-01-01T00:00:00.000Z' }, + { ...baseTemplate, id: '04', updatedAt: '2021-01-01T00:00:00.000Z' }, ]; // 06 is the newest, 08 is the oldest. diff --git a/frontend/src/__tests__/utils/message-plans.test.ts b/frontend/src/__tests__/utils/message-plans.test.ts index 5fd3074cb..8f3f1dd97 100644 --- a/frontend/src/__tests__/utils/message-plans.test.ts +++ b/frontend/src/__tests__/utils/message-plans.test.ts @@ -53,7 +53,7 @@ describe('Message plans actions', () => { const fields = { status: 'DRAFT', name: 'Routing config', - updatedAt: '2021-01-01T00:00:00.000Z', + createdAt: '2020-01-01T00:00:00.000Z', campaignId: 'campaignId', clientId: 'clientId', cascade: [ @@ -65,48 +65,48 @@ describe('Message plans actions', () => { }, ], cascadeGroupOverrides: [{ name: 'standard' }], - } satisfies Omit; + } satisfies Omit; const routingConfigs = [ { ...fields, id: 'a487ed49-e2f7-4871-ac8d-0c6c682c71f5', - createdAt: '2022-01-01T00:00:00.000Z', + updatedAt: '2022-01-01T00:00:00.000Z', }, { ...fields, id: '8f5157fe-72d7-4a9c-818f-77c128ec8197', - createdAt: '2020-01-01T00:00:00.000Z', + updatedAt: '2020-01-01T00:00:00.000Z', }, { ...fields, id: '9be9d25f-81d8-422a-a85c-2fa9019cde1e', - createdAt: '2021-01-01T00:00:00.000Z', + updatedAt: '2021-01-01T00:00:00.000Z', }, { ...fields, id: '1cfdd62d-9eca-4f15-9772-1937d4524c37', - createdAt: '2021-01-01T00:00:00.000Z', + updatedAt: '2021-01-01T00:00:00.000Z', }, { ...fields, id: '18da6158-07ef-455c-9c31-1a4d78a133cf', - createdAt: '2021-01-01T00:00:00.000Z', + updatedAt: '2021-01-01T00:00:00.000Z', }, { ...fields, id: '87fb5cbf-708d-49c3-9360-3e37efdc5278', - createdAt: '2021-01-01T00:00:00.000Z', + updatedAt: '2021-01-01T00:00:00.000Z', }, { ...fields, id: '0d6408fd-57ea-42f2-aae1-ed9614b67068', - createdAt: '2021-01-01T00:00:00.000Z', + updatedAt: '2021-01-01T00:00:00.000Z', }, ]; // a48... is the newest, 8f5... is the oldest. - // the others all have the same createdAt. + // the others all have the same updatedAt. const expectedOrder = [ 'a487ed49-e2f7-4871-ac8d-0c6c682c71f5', '0d6408fd-57ea-42f2-aae1-ed9614b67068', diff --git a/frontend/src/components/molecules/MessageTemplates/MessageTemplates.tsx b/frontend/src/components/molecules/MessageTemplates/MessageTemplates.tsx index e8383ee79..f1136e962 100644 --- a/frontend/src/components/molecules/MessageTemplates/MessageTemplates.tsx +++ b/frontend/src/components/molecules/MessageTemplates/MessageTemplates.tsx @@ -67,7 +67,7 @@ export function MessageTemplates({ {messageTemplatesContent.tableHeadings.status} - {messageTemplatesContent.tableHeadings.dateCreated} + {messageTemplatesContent.tableHeadings.lastEdited} {messageTemplatesContent.tableHeadings.action.text} @@ -90,9 +90,9 @@ export function MessageTemplates({ - {format(`${template.createdAt}`, 'do MMM yyyy')} + {format(`${template.updatedAt}`, 'do MMM yyyy')}
- {format(`${template.createdAt}`, 'HH:mm')} + {format(`${template.updatedAt}`, 'HH:mm')}
diff --git a/frontend/src/content/content.ts b/frontend/src/content/content.ts index 25840c00c..a66048e68 100644 --- a/frontend/src/content/content.ts +++ b/frontend/src/content/content.ts @@ -446,7 +446,7 @@ const messageTemplates = { id: 'ID', type: 'Type', status: 'Status', - dateCreated: 'Date created', + lastEdited: 'Last edited', action: { text: 'Action', copy: 'Copy', delete: 'Delete' }, }, createTemplateButton: { diff --git a/frontend/src/utils/form-actions.ts b/frontend/src/utils/form-actions.ts index 8dc22bcf1..207fd90d8 100644 --- a/frontend/src/utils/form-actions.ts +++ b/frontend/src/utils/form-actions.ts @@ -11,7 +11,7 @@ import { import { logger } from 'nhs-notify-web-template-management-utils/logger'; import { templateApiClient } from 'nhs-notify-backend-client/src/template-api-client'; import { routingConfigurationApiClient } from 'nhs-notify-backend-client/src/routing-config-api-client'; -import { sortAscByCreatedAt } from './sort'; +import { sortAscByUpdatedAt } from './sort'; export async function createTemplate( template: CreateUpdateTemplate @@ -188,7 +188,7 @@ export async function getTemplates(): Promise { (template): template is ValidatedTemplateDto => template !== undefined ); - return sortAscByCreatedAt(sortedData); + return sortAscByUpdatedAt(sortedData); } export async function createRoutingConfig( diff --git a/frontend/src/utils/message-plans.ts b/frontend/src/utils/message-plans.ts index 5b573f81b..375f60158 100644 --- a/frontend/src/utils/message-plans.ts +++ b/frontend/src/utils/message-plans.ts @@ -6,7 +6,7 @@ import { import { routingConfigurationApiClient } from 'nhs-notify-backend-client/src/routing-config-api-client'; import { logger } from 'nhs-notify-web-template-management-utils/logger'; import { getSessionServer } from './amplify-utils'; -import { sortAscByCreatedAt } from './sort'; +import { sortAscByUpdatedAt } from './sort'; export async function getRoutingConfigs(): Promise { const { accessToken } = await getSessionServer(); @@ -32,7 +32,7 @@ export async function getRoutingConfigs(): Promise { return success; }); - return sortAscByCreatedAt(valid); + return sortAscByUpdatedAt(valid); } export async function countRoutingConfigs( diff --git a/frontend/src/utils/sort.ts b/frontend/src/utils/sort.ts index c68ce39f5..3580daecd 100644 --- a/frontend/src/utils/sort.ts +++ b/frontend/src/utils/sort.ts @@ -1,12 +1,12 @@ -export const sortAscByCreatedAt = ( - items: T & { createdAt: string; id: string }[] +export const sortAscByUpdatedAt = ( + items: T & { updatedAt: string; id: string }[] ) => items.sort((a, b) => { - const aCreatedAt = a.createdAt; - const bCreatedAt = b.createdAt; + const aUpdatedAt = a.updatedAt; + const bUpdatedAt = b.updatedAt; - if (aCreatedAt === bCreatedAt) { + if (aUpdatedAt === bUpdatedAt) { return a.id.localeCompare(b.id); } - return aCreatedAt < bCreatedAt ? 1 : -1; + return aUpdatedAt < bUpdatedAt ? 1 : -1; }); diff --git a/tests/test-team/template-mgmt-component-tests/template-mgmt-message-templates-page.component.spec.ts b/tests/test-team/template-mgmt-component-tests/template-mgmt-message-templates-page.component.spec.ts index e63af0506..3e3376ad5 100644 --- a/tests/test-team/template-mgmt-component-tests/template-mgmt-message-templates-page.component.spec.ts +++ b/tests/test-team/template-mgmt-component-tests/template-mgmt-message-templates-page.component.spec.ts @@ -27,7 +27,8 @@ function createTemplates(owner: string) { subject: 'test example subject', templateType: 'EMAIL', templateStatus: 'SUBMITTED', - createdAt: '2010-10-11T11:11:11.111Z', + createdAt: '2010-10-10T11:11:11.111Z', + updatedAt: '2010-10-11T11:11:11.111Z', }), emailNotYetSubmitted: TemplateFactory.create({ id: randomUUID(), @@ -39,6 +40,7 @@ function createTemplates(owner: string) { templateType: 'EMAIL', templateStatus: 'NOT_YET_SUBMITTED', createdAt: '2010-10-11T10:10:10.100Z', + updatedAt: '2010-10-11T10:10:10.100Z', }), smsSubmitted: TemplateFactory.create({ id: randomUUID(), @@ -47,7 +49,8 @@ function createTemplates(owner: string) { message: 'test example message', templateType: 'SMS', templateStatus: 'SUBMITTED', - createdAt: '2010-10-10T11:11:11.111Z', + createdAt: '2010-10-09T11:11:11.111Z', + updatedAt: '2010-10-10T11:11:11.111Z', }), smsNotYetSubmitted: TemplateFactory.create({ id: randomUUID(), @@ -56,7 +59,8 @@ function createTemplates(owner: string) { message: 'test example message', templateType: 'SMS', templateStatus: 'NOT_YET_SUBMITTED', - createdAt: '2010-10-10T10:10:10.100Z', + createdAt: '2010-10-09T10:10:10.100Z', + updatedAt: '2010-10-10T10:10:10.100Z', }), nhsAppSubmitted: TemplateFactory.create({ id: randomUUID(), @@ -65,7 +69,8 @@ function createTemplates(owner: string) { message: 'test example message', templateType: 'NHS_APP', templateStatus: 'SUBMITTED', - createdAt: '2010-10-09T11:11:11.111Z', + createdAt: '2010-10-08T11:11:11.111Z', + updatedAt: '2010-10-09T11:11:11.111Z', }), nhsAppNotYetSubmitted: TemplateFactory.create({ id: randomUUID(), @@ -74,7 +79,8 @@ function createTemplates(owner: string) { message: 'test example message', templateType: 'NHS_APP', templateStatus: 'NOT_YET_SUBMITTED', - createdAt: '2010-10-09T10:10:10.100Z', + createdAt: '2010-10-08T10:10:10.100Z', + updatedAt: '2010-10-09T10:10:10.100Z', }), }; } @@ -290,7 +296,7 @@ test.describe('Manage templates page', () => { await expect(templateDeleteLink).toBeHidden(); }); - test('templates are ordered by createdAt descending', async ({ + test('templates are ordered by updatedAt descending', async ({ page, baseURL, }) => {