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

UHF-9214 Visual regression tests for Events list paragraph #995

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 9 additions & 0 deletions backstop/backstop_dynamic_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ function getConfig(hostname, protocol, type) {
],
'selectorExpansion': expandComponents,
},
{
'label': 'DC: Event list',
'url': `${protocol}://${hostname}/en/dc-components/dc-event-list`,
'removeSelectors': removeDefault,
'selectors': [
'.component--event-list'
],
'selectorExpansion': expandComponents,
},
{
'label': 'DC: Image',
'url': `${protocol}://${hostname}/en/dc-components/dc-image`,
Expand Down
2 changes: 1 addition & 1 deletion dist/js/linkedevents.min.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1637,14 +1637,18 @@ function hdbt_preprocess_paragraph__event_list(&$variables): void {
], $paragraph->getFilterKeywords($langcode));

if ($paragraph->hasField('field_api_url') && !$paragraph->get('field_api_url')->isEmpty()) {
$linkedEvents = Drupal::service('helfi_react_search_linked_events');
/** @var \Drupal\helfi_react_search\LinkedEvents $linkedEvents */
$linkedEvents = Drupal::service(LinkedEvents::class);
$link_field = $events_public_url = $paragraph->get('field_api_url')->first();
assert($link_field instanceof LinkItemInterface);
$events_public_url = $link_field->getUrl()->toString();
$settings['events_public_url'] = $events_public_url;
$params = $linkedEvents->parseParams($events_public_url);
$eventUrl = $linkedEvents->getEventsRequest($params, $settings['field_event_count']);
$settings['events_api_url'] = $eventUrl;
// @todo Remove this once the UHF-9214 has been merged to platform config.
// @phpstan-ignore-next-line
$settings['use_fixtures'] = $linkedEvents->getFixture();
if (!empty($paragraph->get('field_event_location')->getValue()) && $paragraph->get('field_event_location')->first()->getValue()['value']) {
$settings['places'] = $linkedEvents->getPlaceslist($eventUrl);
}
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ parameters:
excludePaths:
- vendor
level: 3
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
scanFiles:
- ../../../core/themes/engines/twig/twig.engine
13 changes: 12 additions & 1 deletion src/js/react/apps/linkedevents/containers/SearchContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAtomValue, useAtom } from 'jotai';
import ResultsContainer from './ResultsContainer';
import FormContainer from './FormContainer';
import type Event from '../types/Event';
import { initialUrlAtom, urlAtom, initialParamsAtom, paramsAtom } from '../store';
import { initialUrlAtom, urlAtom, initialParamsAtom, paramsAtom, useFixturesAtom } from '../store';

type ResponseType = {
data: Event[];
Expand All @@ -29,6 +29,17 @@ const SearchContainer = () => {
const initialParams = useAtomValue(initialParamsAtom);
const [params, setParams] = useAtom(paramsAtom);
const url = useAtomValue(urlAtom) || initialUrl;
const fixtureData = useAtomValue(useFixturesAtom) as ResponseType;

// If we have fixture data set, return that instead of an API call.
if (fixtureData) {
return (
<>
<FormContainer />
<ResultsContainer countNumber={fixtureData?.meta.count || 0} loading={false} events={fixtureData?.data || []} />
</>
);
}

if (!params.toString()) {
setParams(new URLSearchParams(initialParams.toString()));
Expand Down
7 changes: 7 additions & 0 deletions src/js/react/apps/linkedevents/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import OptionType from './types/OptionType';
import FormErrors from './types/FormErrors';
import ApiKeys from './enum/ApiKeys';
import Topic from './types/Topic';
import type Event from './types/Event';

interface Options {
[key: string]: string
Expand Down Expand Up @@ -46,6 +47,7 @@ const createBaseAtom = () => {
}

const settings = drupalSettings.helfi_events?.data?.[paragraphId];
const useFixtures = settings?.use_fixtures;
const eventsApiUrl = settings?.events_api_url;
const eventListTitle = settings?.field_event_list_title;
const eventsPublicUrl = settings?.events_public_url;
Expand Down Expand Up @@ -85,6 +87,7 @@ const createBaseAtom = () => {
topics,
eventListTitle,
eventsPublicUrl,
useFixtures,
};
};

Expand Down Expand Up @@ -132,6 +135,10 @@ export const settingsAtom = atom(
}
);

export const useFixturesAtom = atom<object|false>(
(get) => get(baseAtom)?.useFixtures
);

export const pageAtom = atom<number>(1);

export const urlAtom = atom<string|undefined>(undefined);
Expand Down
3 changes: 2 additions & 1 deletion src/js/types/drupalSettings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ declare namespace drupalSettings {
[key: string]: string
}
}
}
},
use_fixtures: boolean
}
}
};
Expand Down