Further improved the testing suit + test now give links to the front and back

This commit is contained in:
DrMint 2022-03-03 22:50:19 +01:00
parent a085a8b95c
commit d0af42e40b
10 changed files with 643 additions and 148 deletions

View File

@ -1,2 +1,4 @@
NODE_ENV=test NODE_ENV=test
npx next build |& tee ./testing_logs/$(date +"%Y-%m-%d---%H-%M-%S").log # npx next build | tee ./testing_logs/$(date +"%Y-%m-%d---%H-%M-%S").log
npx next build 2> >(tee ./testing_logs/$(date +"%Y-%m-%d---%H-%M-%S").stderr.tsv) 1> >(tee ./testing_logs/$(date +"%Y-%m-%d---%H-%M-%S").stdout.tsv)

View File

@ -7,6 +7,7 @@ type ScenBreakProps = {
}; };
export default function Markdawn(props: ScenBreakProps): JSX.Element { export default function Markdawn(props: ScenBreakProps): JSX.Element {
if (props.text) {
return ( return (
<Markdown <Markdown
className={`prose prose-p:text-justify text-black ${props.className}`} className={`prose prose-p:text-justify text-black ${props.className}`}
@ -15,10 +16,15 @@ export default function Markdawn(props: ScenBreakProps): JSX.Element {
hr: { hr: {
component: SceneBreak, component: SceneBreak,
}, },
player: {
component: () => {return <span className="text-dark opacity-70">{"<player>"}</span>}
},
}, },
}} }}
> >
{props.text} {props.text}
</Markdown> </Markdown>
); );
}
return <></>;
} }

View File

@ -1,6 +1,6 @@
import useDarkMode from "hooks/useDarkMode"; import useDarkMode from "hooks/useDarkMode";
import useStateWithLocalStorage from "hooks/useStateWithLocalStorage"; import useStateWithLocalStorage from "hooks/useStateWithLocalStorage";
import React, { ReactNode, useContext, useEffect } from "react"; import React, { ReactNode, useContext } from "react";
export interface AppLayoutState { export interface AppLayoutState {
subPanelOpen: boolean | undefined; subPanelOpen: boolean | undefined;

View File

@ -181,8 +181,9 @@ query getLibraryItemsPreview($language_code: String) {
} }
} }
... on ComponentMetadataGame { ... on ComponentMetadataGame {
platform { platforms {
data { data {
id
attributes { attributes {
short short
} }
@ -255,6 +256,9 @@ query getLibraryItem($slug: String, $language_code: String) {
title title
subtitle subtitle
slug slug
root_item
primary
digital
thumbnail { thumbnail {
data { data {
attributes { attributes {
@ -345,8 +349,9 @@ query getLibraryItem($slug: String, $language_code: String) {
} }
} }
... on ComponentMetadataGame { ... on ComponentMetadataGame {
platform { platforms {
data { data {
id
attributes { attributes {
short short
} }
@ -470,8 +475,9 @@ query getLibraryItem($slug: String, $language_code: String) {
} }
} }
... on ComponentMetadataGame { ... on ComponentMetadataGame {
platform { platforms {
data { data {
id
attributes { attributes {
short short
} }
@ -812,6 +818,7 @@ query getContent($slug: String, $language_code: String) {
query getContentText($slug: String, $language_code: String) { query getContentText($slug: String, $language_code: String) {
contents(filters: { slug: { eq: $slug } }) { contents(filters: { slug: { eq: $slug } }) {
data { data {
id
attributes { attributes {
slug slug
titles(filters: { language: { code: { eq: $language_code } } }) { titles(filters: { language: { code: { eq: $language_code } } }) {

View File

@ -311,15 +311,16 @@ export type GetLibraryItemsPreviewQuery = {
} }
| { | {
__typename: "ComponentMetadataGame"; __typename: "ComponentMetadataGame";
platform: { platforms: {
__typename: "GamePlatformEntityResponse"; __typename: "GamePlatformRelationResponseCollection";
data: { data: Array<{
__typename: "GamePlatformEntity"; __typename: "GamePlatformEntity";
id: string;
attributes: { attributes: {
__typename: "GamePlatform"; __typename: "GamePlatform";
short: string; short: string;
}; };
}; }>;
}; };
} }
| { | {
@ -395,6 +396,9 @@ export type GetLibraryItemQuery = {
title: string; title: string;
subtitle: string; subtitle: string;
slug: string; slug: string;
root_item: boolean;
primary: boolean;
digital: boolean;
thumbnail: { thumbnail: {
__typename: "UploadFileEntityResponse"; __typename: "UploadFileEntityResponse";
data: { data: {
@ -507,15 +511,16 @@ export type GetLibraryItemQuery = {
} }
| { | {
__typename: "ComponentMetadataGame"; __typename: "ComponentMetadataGame";
platform: { platforms: {
__typename: "GamePlatformEntityResponse"; __typename: "GamePlatformRelationResponseCollection";
data: { data: Array<{
__typename: "GamePlatformEntity"; __typename: "GamePlatformEntity";
id: string;
attributes: { attributes: {
__typename: "GamePlatform"; __typename: "GamePlatform";
short: string; short: string;
}; };
}; }>;
}; };
audio_languages: { audio_languages: {
__typename: "LanguageRelationResponseCollection"; __typename: "LanguageRelationResponseCollection";
@ -683,15 +688,16 @@ export type GetLibraryItemQuery = {
} }
| { | {
__typename: "ComponentMetadataGame"; __typename: "ComponentMetadataGame";
platform: { platforms: {
__typename: "GamePlatformEntityResponse"; __typename: "GamePlatformRelationResponseCollection";
data: { data: Array<{
__typename: "GamePlatformEntity"; __typename: "GamePlatformEntity";
id: string;
attributes: { attributes: {
__typename: "GamePlatform"; __typename: "GamePlatform";
short: string; short: string;
}; };
}; }>;
}; };
} }
| { | {
@ -861,11 +867,6 @@ export type GetContentsSlugsQuery = {
}; };
}; };
export type GetContentQueryVariables = Exact<{
slug: InputMaybe<Scalars["String"]>;
language_code: InputMaybe<Scalars["String"]>;
}>;
export type GetContentsQueryVariables = Exact<{ export type GetContentsQueryVariables = Exact<{
language_code: InputMaybe<Scalars["String"]>; language_code: InputMaybe<Scalars["String"]>;
}>; }>;
@ -982,6 +983,11 @@ export type GetContentsQuery = {
}; };
}; };
export type GetContentQueryVariables = Exact<{
slug: InputMaybe<Scalars["String"]>;
language_code: InputMaybe<Scalars["String"]>;
}>;
export type GetContentQuery = { export type GetContentQuery = {
__typename: "Query"; __typename: "Query";
contents: { contents: {
@ -1109,6 +1115,7 @@ export type GetContentTextQuery = {
__typename: "ContentEntityResponseCollection"; __typename: "ContentEntityResponseCollection";
data: Array<{ data: Array<{
__typename: "ContentEntity"; __typename: "ContentEntity";
id: string;
attributes: { attributes: {
__typename: "Content"; __typename: "Content";
slug: string; slug: string;

View File

@ -486,7 +486,11 @@ type ComponentMetadataBooks {
type ComponentMetadataGame { type ComponentMetadataGame {
id: ID! id: ID!
platform: GamePlatformEntityResponse platforms(
filters: GamePlatformFiltersInput
pagination: PaginationArg = {}
sort: [String] = []
): GamePlatformRelationResponseCollection
demo: Boolean! demo: Boolean!
audio_languages( audio_languages(
filters: LanguageFiltersInput filters: LanguageFiltersInput
@ -589,8 +593,8 @@ type ComponentRangeOther {
type ComponentRangePageRange { type ComponentRangePageRange {
id: ID! id: ID!
starting_page: Int starting_page: Int!
ending_page: Int ending_page: Int!
} }
type ComponentRangeTimeRange { type ComponentRangeTimeRange {
@ -1708,6 +1712,10 @@ type GamePlatformEntityResponseCollection {
meta: ResponseCollectionMeta! meta: ResponseCollectionMeta!
} }
type GamePlatformRelationResponseCollection {
data: [GamePlatformEntity!]!
}
input GlossaryItemFiltersInput { input GlossaryItemFiltersInput {
id: IDFilterInput id: IDFilterInput
slug: StringFilterInput slug: StringFilterInput
@ -2132,7 +2140,7 @@ input RangedContentInput {
type RangedContent { type RangedContent {
slug: String! slug: String!
range: [RangedContentRangeDynamicZone] range: [RangedContentRangeDynamicZone]!
scan_set( scan_set(
filters: ComponentSetsScanSetFiltersInput filters: ComponentSetsScanSetFiltersInput
pagination: PaginationArg = {} pagination: PaginationArg = {}

View File

@ -29,18 +29,17 @@ import Chip from "components/Chip";
import ReactTooltip from "react-tooltip"; import ReactTooltip from "react-tooltip";
import RecorderChip from "components/RecorderChip"; import RecorderChip from "components/RecorderChip";
type ContentReadProps = { interface ContentReadProps {
content: GetContentTextQuery; content: GetContentTextQuery;
langui: GetWebsiteInterfaceQuery; langui: GetWebsiteInterfaceQuery;
}; }
export default function ContentRead(props: ContentReadProps): JSX.Element { export default function ContentRead(props: ContentReadProps): JSX.Element {
useTesting(props);
const content = props.content.contents.data[0].attributes; const content = props.content.contents.data[0].attributes;
const langui = props.langui.websiteInterfaces.data[0].attributes; const langui = props.langui.websiteInterfaces.data[0].attributes;
const router = useRouter(); const router = useRouter();
useTesting(props.content);
const subPanel = ( const subPanel = (
<SubPanel> <SubPanel>
<ReturnButton <ReturnButton
@ -191,7 +190,7 @@ export default function ContentRead(props: ContentReadProps): JSX.Element {
) )
: prettySlug(content.slug) : prettySlug(content.slug)
} }
thumbnail={content.thumbnail.data.attributes} thumbnail={content.thumbnail.data?.attributes}
langui={langui} langui={langui}
contentPanel={contentPanel} contentPanel={contentPanel}
subPanel={subPanel} subPanel={subPanel}
@ -244,70 +243,102 @@ export const getStaticPaths: GetStaticPaths = async (context) => {
}; };
}; };
export function useTesting(content: GetContentTextQuery) { export function useTesting(props: ContentReadProps) {
const router = useRouter(); const router = useRouter();
const contentAtr = content.contents.data[0].attributes; const content = props.content.contents.data[0].attributes;
if (contentAtr.categories.data.length === 0) {
prettyTestError(router, "Missing categories", ["content"]); const contentURL =
"/admin/content-manager/collectionType/api::content.content/" +
props.content.contents.data[0].id;
if (router.locale === "en") {
if (content.categories.data.length === 0) {
prettyTestError(router, "Missing categories", ["content"], contentURL);
}
} }
if (contentAtr.ranged_contents.data.length === 0) { if (content.ranged_contents.data.length === 0) {
prettyTestWarning(router, "Unconnected to any source", ["content"]); prettyTestWarning(
} router,
"Unconnected to any source",
if (contentAtr.text_set.length === 0) { ["content"],
prettyTestWarning(router, "Has no textset, nor audioset, nor videoset", [ contentURL
"content",
]);
}
if (contentAtr.text_set.length > 1) {
console.warn(
prettyTestError(router, "More than one textset for this language", [
"content",
"text_set",
])
); );
} }
if (contentAtr.text_set.length === 1) { if (content.text_set.length === 0) {
const textset = contentAtr.text_set[0]; prettyTestWarning(
router,
"Has no textset, nor audioset, nor videoset",
["content"],
contentURL
);
}
if (content.text_set.length > 1) {
console.warn(
prettyTestError(
router,
"More than one textset for this language",
["content", "text_set"],
contentURL
)
);
}
if (content.text_set.length === 1) {
const textset = content.text_set[0];
if (!textset.text) { if (!textset.text) {
prettyTestError(router, "Missing text", ["content", "text_set"]); prettyTestError(
router,
"Missing text",
["content", "text_set"],
contentURL
);
} }
if (!textset.source_language.data) { if (!textset.source_language.data) {
prettyTestError(router, "Missing source language", [ prettyTestError(
"content", router,
"text_set", "Missing source language",
]); ["content", "text_set"],
contentURL
);
} }
if (textset.source_language.data.attributes.code === router.locale) { if (textset.source_language.data.attributes.code === router.locale) {
// This is a transcript // This is a transcript
if (textset.transcribers.data.length === 0) { if (textset.transcribers.data.length === 0) {
prettyTestError(router, "Missing transcribers attribution", [ prettyTestError(
"content", router,
"text_set", "Missing transcribers attribution",
]); ["content", "text_set"],
contentURL
);
} }
if (textset.translators.data.length > 0) { if (textset.translators.data.length > 0) {
prettyTestError(router, "Transcripts shouldn't have translators", [ prettyTestError(
"content", router,
"text_set", "Transcripts shouldn't have translators",
]); ["content", "text_set"],
contentURL
);
} }
} else { } else {
// This is a translation // This is a translation
if (textset.translators.data.length === 0) { if (textset.translators.data.length === 0) {
prettyTestError(router, "Missing translators attribution", [ prettyTestError(
"content", router,
"text_set", "Missing translators attribution",
]); ["content", "text_set"],
contentURL
);
} }
if (textset.transcribers.data.length > 0) { if (textset.transcribers.data.length > 0) {
prettyTestError(router, "Translations shouldn't have transcribers", [ prettyTestError(
"content", router,
"text_set", "Translations shouldn't have transcribers",
]); ["content", "text_set"],
contentURL
);
} }
} }
} }

View File

@ -21,6 +21,9 @@ import {
prettyItemSubType, prettyItemSubType,
prettyPrice, prettyPrice,
prettySlug, prettySlug,
prettyTestError,
prettyTestWarning,
sortContent,
} from "queries/helpers"; } from "queries/helpers";
import SubPanel from "components/Panels/SubPanel"; import SubPanel from "components/Panels/SubPanel";
import ReturnButton from "components/PanelComponents/ReturnButton"; import ReturnButton from "components/PanelComponents/ReturnButton";
@ -33,13 +36,15 @@ import LibraryItemsPreview from "components/Library/LibraryItemsPreview";
import InsetBox from "components/InsetBox"; import InsetBox from "components/InsetBox";
import Img, { ImageQuality } from "components/Img"; import Img, { ImageQuality } from "components/Img";
import { useAppLayout } from "contexts/AppLayoutContext"; import { useAppLayout } from "contexts/AppLayoutContext";
import { useRouter } from "next/router";
type LibrarySlugProps = { interface LibrarySlugProps {
libraryItem: GetLibraryItemQuery; libraryItem: GetLibraryItemQuery;
langui: GetWebsiteInterfaceQuery; langui: GetWebsiteInterfaceQuery;
}; }
export default function LibrarySlug(props: LibrarySlugProps): JSX.Element { export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
useTesting(props);
const item = props.libraryItem.libraryItems.data[0].attributes; const item = props.libraryItem.libraryItems.data[0].attributes;
const langui = props.langui.websiteInterfaces.data[0].attributes; const langui = props.langui.websiteInterfaces.data[0].attributes;
const appLayout = useAppLayout(); const appLayout = useAppLayout();
@ -49,6 +54,8 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
item.metadata[0].__typename === "ComponentMetadataOther" && item.metadata[0].__typename === "ComponentMetadataOther" &&
item.metadata[0].subtype.data.attributes.slug === "variant-set"; item.metadata[0].subtype.data.attributes.slug === "variant-set";
sortContent(item.contents);
const subPanel = ( const subPanel = (
<SubPanel> <SubPanel>
<ReturnButton <ReturnButton
@ -465,20 +472,6 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
</ContentPanel> </ContentPanel>
); );
// Sort content by range
item.contents.data.sort((a, b) => {
if (
a.attributes.range[0].__typename === "ComponentRangePageRange" &&
b.attributes.range[0].__typename === "ComponentRangePageRange"
) {
return (
a.attributes.range[0].starting_page -
b.attributes.range[0].starting_page
);
}
return 0;
});
return ( return (
<AppLayout <AppLayout
navTitle={langui.main_library} navTitle={langui.main_library}
@ -486,7 +479,7 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
langui={langui} langui={langui}
contentPanel={contentPanel} contentPanel={contentPanel}
subPanel={subPanel} subPanel={subPanel}
thumbnail={item.thumbnail.data.attributes} thumbnail={item.thumbnail.data?.attributes}
description={ description={
item.descriptions.length > 0 item.descriptions.length > 0
? item.descriptions[0].description ? item.descriptions[0].description
@ -539,3 +532,394 @@ export const getStaticPaths: GetStaticPaths = async (context) => {
fallback: false, fallback: false,
}; };
}; };
function useTesting(props: LibrarySlugProps) {
const libraryItem = props.libraryItem.libraryItems.data[0].attributes;
const router = useRouter();
const libraryItemURL =
"/admin/content-manager/collectionType/api::library-item.library-item/" +
props.libraryItem.libraryItems.data[0].id;
sortContent(libraryItem.contents);
if (router.locale === "en") {
if (!libraryItem.thumbnail.data) {
prettyTestError(
router,
"Missing thumbnail",
["libraryItem"],
libraryItemURL
);
}
if (libraryItem.metadata.length === 0) {
prettyTestError(
router,
"Missing metadata",
["libraryItem"],
libraryItemURL
);
} else {
if (
libraryItem.metadata[0].__typename === "ComponentMetadataOther" &&
(libraryItem.metadata[0].subtype.data.attributes.slug ===
"relation-set" ||
libraryItem.metadata[0].subtype.data.attributes.slug ===
"variant-set")
) {
// This is a group type item
if (libraryItem.price) {
prettyTestError(
router,
"Group-type items shouldn't have price",
["libraryItem"],
libraryItemURL
);
}
if (libraryItem.size) {
prettyTestError(
router,
"Group-type items shouldn't have size",
["libraryItem"],
libraryItemURL
);
}
if (libraryItem.release_date) {
prettyTestError(
router,
"Group-type items shouldn't have release_date",
["libraryItem"],
libraryItemURL
);
}
if (libraryItem.contents.data.length > 0) {
prettyTestError(
router,
"Group-type items shouldn't have contents",
["libraryItem"],
libraryItemURL
);
}
if (libraryItem.subitems.data.length === 0) {
prettyTestError(
router,
"Group-type items should have subitems",
["libraryItem"],
libraryItemURL
);
}
} else {
// This is a normal item
if (libraryItem.metadata[0].__typename === "ComponentMetadataOther") {
if (
libraryItem.metadata[0].subtype.data.attributes.slug ===
"audio-case"
) {
let hasAudioSubItem = false;
libraryItem.subitems.data.map((subitem) => {
if (
subitem.attributes.metadata.length > 0 &&
subitem.attributes.metadata[0].__typename ===
"ComponentMetadataAudio"
)
hasAudioSubItem = true;
});
if (!hasAudioSubItem) {
prettyTestError(
router,
"Audio-case item doesn't have an audio-typed subitem",
["libraryItem"],
libraryItemURL
);
}
} else if (
libraryItem.metadata[0].subtype.data.attributes.slug === "game-case"
) {
let hasGameSubItem = false;
libraryItem.subitems.data.map((subitem) => {
if (
subitem.attributes.metadata.length > 0 &&
subitem.attributes.metadata[0].__typename ===
"ComponentMetadataGame"
)
hasGameSubItem = true;
});
if (!hasGameSubItem) {
prettyTestError(
router,
"Game-case item doesn't have an Game-typed subitem",
["libraryItem"],
libraryItemURL
);
}
} else if (
libraryItem.metadata[0].subtype.data.attributes.slug ===
"video-case"
) {
let hasVideoSubItem = false;
libraryItem.subitems.data.map((subitem) => {
if (
subitem.attributes.metadata.length > 0 &&
subitem.attributes.metadata[0].__typename ===
"ComponentMetadataVideo"
)
hasVideoSubItem = true;
});
if (!hasVideoSubItem) {
prettyTestError(
router,
"Video-case item doesn't have an Video-typed subitem",
["libraryItem"],
libraryItemURL
);
}
} else if (
libraryItem.metadata[0].subtype.data.attributes.slug === "item-set"
) {
if (libraryItem.subitems.data.length === 0) {
prettyTestError(
router,
"Item-set item should have subitems",
["libraryItem"],
libraryItemURL
);
}
}
}
if (!libraryItem.price) {
prettyTestWarning(
router,
"Missing price",
["libraryItem"],
libraryItemURL
);
} else {
if (!libraryItem.price.amount) {
prettyTestError(
router,
"Missing amount",
["libraryItem", "price"],
libraryItemURL
);
}
if (!libraryItem.price.currency) {
prettyTestError(
router,
"Missing currency",
["libraryItem", "price"],
libraryItemURL
);
}
}
if (!libraryItem.digital) {
if (!libraryItem.size) {
prettyTestWarning(
router,
"Missing size",
["libraryItem"],
libraryItemURL
);
} else {
if (!libraryItem.size.width) {
prettyTestWarning(
router,
"Missing width",
["libraryItem", "size"],
libraryItemURL
);
}
if (!libraryItem.size.height) {
prettyTestWarning(
router,
"Missing height",
["libraryItem", "size"],
libraryItemURL
);
}
if (!libraryItem.size.thickness) {
prettyTestWarning(
router,
"Missing thickness",
["libraryItem", "size"],
libraryItemURL
);
}
}
}
if (!libraryItem.release_date) {
prettyTestWarning(
router,
"Missing release_date",
["libraryItem"],
libraryItemURL
);
} else {
if (!libraryItem.release_date.year) {
prettyTestError(
router,
"Missing year",
["libraryItem", "release_date"],
libraryItemURL
);
}
if (!libraryItem.release_date.month) {
prettyTestError(
router,
"Missing month",
["libraryItem", "release_date"],
libraryItemURL
);
}
if (!libraryItem.release_date.day) {
prettyTestError(
router,
"Missing day",
["libraryItem", "release_date"],
libraryItemURL
);
}
}
if (libraryItem.contents.data.length === 0) {
prettyTestWarning(
router,
"Missing contents",
["libraryItem"],
libraryItemURL
);
} else {
let currentRangePage = 0;
libraryItem.contents.data.map((content) => {
const contentURL =
"/admin/content-manager/collectionType/api::content.content/" +
content.id;
if (content.attributes.scan_set.length === 0) {
prettyTestWarning(
router,
"Missing scan_set",
["libraryItem", "content", content.id],
contentURL
);
}
if (content.attributes.range.length === 0) {
prettyTestWarning(
router,
"Missing range",
["libraryItem", "content", content.id],
contentURL
);
} else if (
content.attributes.range[0].__typename ===
"ComponentRangePageRange"
) {
if (
content.attributes.range[0].starting_page <
currentRangePage + 1
) {
prettyTestError(
router,
`Overlapping pages ${content.attributes.range[0].starting_page} to ${currentRangePage}`,
["libraryItem", "content", content.id, "range"],
libraryItemURL
);
} else if (
content.attributes.range[0].starting_page >
currentRangePage + 1
) {
prettyTestError(
router,
`Missing pages ${currentRangePage + 1} to ${
content.attributes.range[0].starting_page - 1
}`,
["libraryItem", "content", content.id, "range"],
libraryItemURL
);
}
if (!content.attributes.content.data) {
prettyTestWarning(
router,
"Missing content",
["libraryItem", "content", content.id, "range"],
libraryItemURL
);
}
currentRangePage = content.attributes.range[0].ending_page;
}
});
if (libraryItem.metadata[0].__typename === "ComponentMetadataBooks") {
if (currentRangePage < libraryItem.metadata[0].page_count) {
prettyTestError(
router,
`Missing pages ${currentRangePage + 1} to ${
libraryItem.metadata[0].page_count
}`,
["libraryItem", "content"],
libraryItemURL
);
} else if (currentRangePage > libraryItem.metadata[0].page_count) {
prettyTestError(
router,
`Page overflow, content references pages up to ${currentRangePage} when the highest expected was ${libraryItem.metadata[0].page_count}`,
["libraryItem", "content"],
libraryItemURL
);
}
if (libraryItem.metadata[0].languages.data.length === 0) {
prettyTestWarning(
router,
"Missing language",
["libraryItem", "metadata"],
libraryItemURL
);
}
if (!libraryItem.metadata[0].page_count) {
prettyTestWarning(
router,
"Missing page_count",
["libraryItem", "metadata"],
libraryItemURL
);
}
}
}
}
}
if (!libraryItem.root_item && libraryItem.subitem_of.data.length === 0) {
prettyTestError(
router,
"This item is inaccessible (not root item and not subitem of another item)",
["libraryItem"],
libraryItemURL
);
}
if (libraryItem.gallery.data.length === 0) {
prettyTestWarning(
router,
"Missing gallery",
["libraryItem"],
libraryItemURL
);
}
}
if (libraryItem.descriptions.length === 0) {
prettyTestWarning(
router,
"Missing description",
["libraryItem"],
libraryItemURL
);
}
}

View File

@ -34,10 +34,10 @@ interface DataChronologyProps {
export default function DataChronology( export default function DataChronology(
props: DataChronologyProps props: DataChronologyProps
): JSX.Element { ): JSX.Element {
useTesting(props);
const langui = props.langui.websiteInterfaces.data[0].attributes; const langui = props.langui.websiteInterfaces.data[0].attributes;
const chronologyItems = props.chronologyItems.chronologyItems; const chronologyItems = props.chronologyItems.chronologyItems;
const chronologyEras = props.chronologyEras.chronologyEras; const chronologyEras = props.chronologyEras.chronologyEras;
useTesting(props.chronologyItems, props.chronologyEras);
// Group by year the Chronology items // Group by year the Chronology items
let chronologyItemYearGroups: GetChronologyItemsQuery["chronologyItems"]["data"][number][][][] = let chronologyItemYearGroups: GetChronologyItemsQuery["chronologyItems"]["data"][number][][][] =
@ -162,59 +162,76 @@ export const getStaticProps: GetStaticProps = async (context) => {
return { props: {} }; return { props: {} };
}; };
export function useTesting( function useTesting({ chronologyItems, chronologyEras }: DataChronologyProps) {
chronologyItems: GetChronologyItemsQuery,
chronologyEras: GetErasQuery
) {
const router = useRouter(); const router = useRouter();
chronologyEras.chronologyEras.data.map((era) => { chronologyEras.chronologyEras.data.map((era) => {
const chronologyErasURL =
"/admin/content-manager/collectionType/api::chronology-era.chronology-era/" +
chronologyItems.chronologyItems.data[0].id;
if (era.attributes.title.length === 0) { if (era.attributes.title.length === 0) {
prettyTestError( prettyTestError(
router, router,
"Missing translation for title and description, using slug instead", "Missing translation for title and description, using slug instead",
["chronologyEras", era.attributes.slug] ["chronologyEras", era.attributes.slug],
chronologyErasURL
); );
} else if (era.attributes.title.length > 1) { } else if (era.attributes.title.length > 1) {
prettyTestError(router, "More than one title and description", [ prettyTestError(
"chronologyEras", router,
era.attributes.slug, "More than one title and description",
]); ["chronologyEras", era.attributes.slug],
chronologyErasURL
);
} else { } else {
if (!era.attributes.title[0].title) if (!era.attributes.title[0].title)
prettyTestError(router, "Missing title, using slug instead", [ prettyTestError(
"chronologyEras", router,
era.attributes.slug, "Missing title, using slug instead",
]); ["chronologyEras", era.attributes.slug],
chronologyErasURL
);
if (!era.attributes.title[0].description) if (!era.attributes.title[0].description)
prettyTestError(router, "Missing description", [ prettyTestError(
"chronologyEras", router,
era.attributes.slug, "Missing description",
]); ["chronologyEras", era.attributes.slug],
chronologyErasURL
);
} }
}); });
chronologyItems.chronologyItems.data.map((item) => { chronologyItems.chronologyItems.data.map((item) => {
const chronologyItemsURL =
"/admin/content-manager/collectionType/api::chronology-item.chronology-item/" +
chronologyItems.chronologyItems.data[0].id;
const date = `${item.attributes.year}/${item.attributes.month}/${item.attributes.day}`; const date = `${item.attributes.year}/${item.attributes.month}/${item.attributes.day}`;
if (!(item.attributes.events.length > 0)) { if (!(item.attributes.events.length > 0)) {
prettyTestError(router, "No events for this date", [ prettyTestError(
"chronologyItems", router,
date, "No events for this date",
]); ["chronologyItems", date],
chronologyItemsURL
);
} else { } else {
item.attributes.events.map((event) => { item.attributes.events.map((event) => {
if (!event.source.data) { if (!event.source.data) {
prettyTestError(router, "No source for this event", [ prettyTestError(
"chronologyItems", router,
date, "No source for this event",
event.id, ["chronologyItems", date, event.id],
]); chronologyItemsURL
);
} }
if (!(event.translations.length > 0)) { if (!(event.translations.length > 0)) {
prettyTestWarning(router, "No translation for this event", [ prettyTestWarning(
"chronologyItems", router,
date, "No translation for this event",
event.id, ["chronologyItems", date, event.id],
]); chronologyItemsURL
);
} }
}); });
} }

View File

@ -4,6 +4,7 @@ import {
ImageQuality, ImageQuality,
} from "components/Img"; } from "components/Img";
import { import {
GetLibraryItemQuery,
GetLibraryItemsPreviewQuery, GetLibraryItemsPreviewQuery,
GetWebsiteInterfaceQuery, GetWebsiteInterfaceQuery,
StrapiImage, StrapiImage,
@ -80,7 +81,7 @@ export function prettyItemType(
export function prettyItemSubType(metadata: { export function prettyItemSubType(metadata: {
__typename: GetLibraryItemsPreviewQuery["libraryItems"]["data"][number]["attributes"]["metadata"][number]["__typename"]; __typename: GetLibraryItemsPreviewQuery["libraryItems"]["data"][number]["attributes"]["metadata"][number]["__typename"];
subtype?: any; subtype?: any;
platform?: any; platforms?: any;
}): string { }): string {
switch (metadata.__typename) { switch (metadata.__typename) {
case "ComponentMetadataAudio": case "ComponentMetadataAudio":
@ -92,7 +93,9 @@ export function prettyItemSubType(metadata: {
: prettySlug(metadata.subtype.data.attributes.slug); : prettySlug(metadata.subtype.data.attributes.slug);
} }
case "ComponentMetadataGame": case "ComponentMetadataGame":
return metadata.platform.data.attributes.short; return metadata.platforms.data.length > 0
? metadata.platforms.data[0].attributes.short
: "";
default: default:
return ""; return "";
@ -121,17 +124,19 @@ export function prettyLanguage(code: string): string {
export function prettyTestWarning( export function prettyTestWarning(
router: NextRouter, router: NextRouter,
message: string, message: string,
subCategory?: string[] subCategory: string[],
url: string
): void { ): void {
prettyTestWritter(TestingLevel.Warning, router, message, subCategory); prettyTestWritter(TestingLevel.Warning, router, message, subCategory, url);
} }
export function prettyTestError( export function prettyTestError(
router: NextRouter, router: NextRouter,
message: string, message: string,
subCategory?: string[] subCategory: string[],
url: string
): void { ): void {
prettyTestWritter(TestingLevel.Error, router, message, subCategory); prettyTestWritter(TestingLevel.Error, router, message, subCategory, url);
} }
enum TestingLevel { enum TestingLevel {
@ -143,12 +148,23 @@ function prettyTestWritter(
level: TestingLevel, level: TestingLevel,
{ asPath, locale }: NextRouter, { asPath, locale }: NextRouter,
message: string, message: string,
subCategory?: string[] subCategory: string[],
url: string
): void { ): void {
subCategory?.push(""); const line = [
console.warn( level,
`${level} - ${asPath} | ${locale} | ${subCategory?.join(" | ")}${message}` process.env.NEXT_PUBLIC_URL_SELF + "/" + locale + asPath,
); locale,
subCategory?.join(" -> "),
message,
process.env.NEXT_PUBLIC_URL_CMS + url,
];
if (level === TestingLevel.Warning) {
console.warn(line.join("\t"));
} else {
console.error(line.join("\t"));
}
} }
export function capitalizeString(string: string): string { export function capitalizeString(string: string): string {
@ -185,3 +201,20 @@ export function getOgImage(quality: ImageQuality, image: StrapiImage): OgImage {
alt: image.alternativeText, alt: image.alternativeText,
}; };
} }
export function sortContent(
contents: GetLibraryItemQuery["libraryItems"]["data"][number]["attributes"]["contents"]
) {
contents.data.sort((a, b) => {
if (
a.attributes.range[0].__typename === "ComponentRangePageRange" &&
b.attributes.range[0].__typename === "ComponentRangePageRange"
) {
return (
a.attributes.range[0].starting_page -
b.attributes.range[0].starting_page
);
}
return 0;
});
}