Skip to content

Commit 2f009f2

Browse files
committed
Implement external links diffing in stop change history
1 parent 4173849 commit 2f009f2

6 files changed

Lines changed: 121 additions & 0 deletions

File tree

cypress/e2e/stop-registry/stopChangeHistory.cy.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { DateTime } from 'luxon';
2020
import { Tag } from '../../enums';
2121
import {
2222
BasicDetailsForm,
23+
ExternalLinksForm,
24+
ExternalLinksSection,
2325
InfoSpotViewCard,
2426
InfoSpotsForm,
2527
LocationDetailsForm,
@@ -38,8 +40,23 @@ import { UUID } from '../../types';
3840
import { SupportedResources, insertToDbHelper } from '../../utils';
3941
import { expectGraphQLCallToSucceed } from '../../utils/assertions';
4042
import { InsertedStopRegistryIds } from '../utils';
43+
import {
44+
ExternalLinkData,
45+
assertExternalLinksChanged,
46+
} from './externalLinksUtils';
4147
import { InfoSpotData, assertInfoSpot } from './infoSpotUtils';
4248

49+
const externalLinksTestData = {
50+
initialLink: {
51+
name: 'Pysäkin Testilinkki',
52+
location: 'https://stoptest.fi',
53+
},
54+
addedLink: {
55+
name: 'Test Link',
56+
location: 'http://www.example.com',
57+
},
58+
} as const satisfies Readonly<Record<string, ExternalLinkData>>;
59+
4360
const testInfraLinks = [
4461
{
4562
externalId: '7d29bd61-6cf7-4d2c-8bd8-b8e835fe90b7:1',
@@ -125,6 +142,12 @@ const stopAreaInput: StopAreaInput = {
125142
organisations: quayH2003.organisations as
126143
| StopRegistryStopPlaceOrganisationRefInput[]
127144
| null,
145+
externalLinks: [
146+
{
147+
name: externalLinksTestData.initialLink.name,
148+
location: externalLinksTestData.initialLink.location,
149+
},
150+
],
128151
},
129152
],
130153
},
@@ -1201,6 +1224,52 @@ describe('Stop Change History', { tags }, () => {
12011224
);
12021225
});
12031226
});
1227+
1228+
it('Should diff external links', () => {
1229+
StopDetailsPage.visit('H2003');
1230+
1231+
cy.section('Add external link', () => {
1232+
ExternalLinksSection.getEditButton().click();
1233+
ExternalLinksForm.getAddNewButton().click();
1234+
ExternalLinksForm.getNthExternalLink(1).within(() => {
1235+
ExternalLinksForm.externalLinks
1236+
.getNameInput()
1237+
.clearAndType(externalLinksTestData.addedLink.name);
1238+
ExternalLinksForm.externalLinks
1239+
.getLocationInput()
1240+
.clearAndType(externalLinksTestData.addedLink.location);
1241+
});
1242+
ExternalLinksForm.getSaveButton().click();
1243+
});
1244+
1245+
StopDetailsPage.changeHistoryLink().click();
1246+
1247+
cy.section('Check changed details', () => {
1248+
StopChangeHistoryPage.changeHistoryTable.group
1249+
.getAllGroupElements()
1250+
.eq(0)
1251+
.within(() => {
1252+
StopChangeHistoryPage.changeHistoryTable.sectionHeader
1253+
.getExternalLinksDetails()
1254+
.shouldBeVisible();
1255+
StopChangeHistoryPage.changeHistoryTable.changedValues.externalLinksDetails
1256+
.getLinks()
1257+
.within(() => {
1258+
assertExternalLinksChanged(
1259+
() =>
1260+
StopChangeHistoryPage.changeHistoryTable.changedValues.getOldValue(),
1261+
() =>
1262+
StopChangeHistoryPage.changeHistoryTable.changedValues.getNewValue(),
1263+
[externalLinksTestData.initialLink],
1264+
[
1265+
externalLinksTestData.initialLink,
1266+
externalLinksTestData.addedLink,
1267+
],
1268+
);
1269+
});
1270+
});
1271+
});
1272+
});
12041273
});
12051274

12061275
describe('Sorting', () => {

cypress/pageObjects/stop-registry/StopChangeHistoryPage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ const StopChangeHistoryTable = createSimplePageObject(
120120
// ChangedValue sections need more complex logic.
121121
'ChangeHistory::SectionHeader::ShelterDetails',
122122
'ChangeHistory::SectionHeader::InfoSpotDetails',
123+
124+
'ChangeHistory::SectionHeader::ExternalLinksDetails',
125+
'ChangeHistory::ChangedValues::ExternalLinksDetails::Links',
123126
],
124127
(base) => ({
125128
...BaseChangeHistoryTable,

ui/src/components/stop-registry/stops/change-history/components/DataDiffSections.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
diffSignageDetails,
2121
diffStopAreaAndTerminal,
2222
} from '../utils';
23+
import { diffStopExternalLinks } from '../utils/dataDiffers/diffExternalLinks';
2324
import {
2425
useHistoricalStopVersion,
2526
useRefetchFailedHistoricalStopVersions,
@@ -173,6 +174,16 @@ export const DataDiffSections: FC<DataDiffSectionsProps> = ({
173174
),
174175
testId: 'InfoSpotDetails',
175176
},
177+
{
178+
diffVersions: diffStopExternalLinks,
179+
sectionTitle: (
180+
<SectionTitle
181+
historyItem={historyItem}
182+
section={t(($) => $.changeHistory.externalLinks.title)}
183+
/>
184+
),
185+
testId: 'ExternalLinksDetails',
186+
},
176187
]}
177188
/>
178189
);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { TFunction } from 'i18next';
2+
import compact from 'lodash/compact';
3+
import {
4+
ChangedValue,
5+
diffKeyedValues,
6+
} from '../../../../../common/ChangeHistory';
7+
import {
8+
ExternalLinksList,
9+
formatLinks,
10+
} from '../../../../../common/ChangeHistory/utils/externalLinks';
11+
import { HistoricalStopData } from '../../types';
12+
13+
export function diffStopExternalLinks(
14+
t: TFunction,
15+
previous: HistoricalStopData,
16+
current: HistoricalStopData,
17+
): Array<ChangedValue> {
18+
return compact([
19+
diffKeyedValues({
20+
key: 'Links',
21+
field: null,
22+
oldValue: formatLinks(previous.quay.externalLinks, t),
23+
newValue: formatLinks(current.quay.externalLinks, t),
24+
mapper: (links) =>
25+
typeof links === 'string' ? (
26+
links
27+
) : (
28+
<ExternalLinksList links={links} id={current.quay.id ?? undefined} />
29+
),
30+
}),
31+
]);
32+
}

ui/src/components/stop-registry/stops/change-history/utils/dataDiffers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './diffOwnerDetails';
66
export * from './diffShelters';
77
export * from './diffSignageDetails';
88
export * from './diffStopAreaAndTerminal';
9+
export * from './diffExternalLinks';

ui/src/components/stop-registry/stops/change-history/utils/latestStopChangeSections.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
diffShelters,
1111
diffSignageDetails,
1212
diffStopAreaAndTerminal,
13+
diffStopExternalLinks,
1314
} from '.';
1415

1516
type StopChangeSection = {
@@ -55,5 +56,9 @@ export function latestStopChangeSections(
5556
title: t(($) => $.stopChangeHistory.infoSpots.title),
5657
changes: diffInfoSpots(t, prev, curr),
5758
},
59+
{
60+
title: t(($) => $.changeHistory.externalLinks.title),
61+
changes: diffStopExternalLinks(t, prev, curr),
62+
},
5863
].filter((s) => s.changes.length > 0);
5964
}

0 commit comments

Comments
 (0)