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
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,18 +7,24 @@ type ScenBreakProps = {
};
export default function Markdawn(props: ScenBreakProps): JSX.Element {
return (
<Markdown
className={`prose prose-p:text-justify text-black ${props.className}`}
options={{
overrides: {
hr: {
component: SceneBreak,
if (props.text) {
return (
<Markdown
className={`prose prose-p:text-justify text-black ${props.className}`}
options={{
overrides: {
hr: {
component: SceneBreak,
},
player: {
component: () => {return <span className="text-dark opacity-70">{"<player>"}</span>}
},
},
},
}}
>
{props.text}
</Markdown>
);
}
}}
>
{props.text}
</Markdown>
);
}
return <></>;
}

View File

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

View File

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

View File

@ -311,15 +311,16 @@ export type GetLibraryItemsPreviewQuery = {
}
| {
__typename: "ComponentMetadataGame";
platform: {
__typename: "GamePlatformEntityResponse";
data: {
platforms: {
__typename: "GamePlatformRelationResponseCollection";
data: Array<{
__typename: "GamePlatformEntity";
id: string;
attributes: {
__typename: "GamePlatform";
short: string;
};
};
}>;
};
}
| {
@ -395,6 +396,9 @@ export type GetLibraryItemQuery = {
title: string;
subtitle: string;
slug: string;
root_item: boolean;
primary: boolean;
digital: boolean;
thumbnail: {
__typename: "UploadFileEntityResponse";
data: {
@ -507,15 +511,16 @@ export type GetLibraryItemQuery = {
}
| {
__typename: "ComponentMetadataGame";
platform: {
__typename: "GamePlatformEntityResponse";
data: {
platforms: {
__typename: "GamePlatformRelationResponseCollection";
data: Array<{
__typename: "GamePlatformEntity";
id: string;
attributes: {
__typename: "GamePlatform";
short: string;
};
};
}>;
};
audio_languages: {
__typename: "LanguageRelationResponseCollection";
@ -683,15 +688,16 @@ export type GetLibraryItemQuery = {
}
| {
__typename: "ComponentMetadataGame";
platform: {
__typename: "GamePlatformEntityResponse";
data: {
platforms: {
__typename: "GamePlatformRelationResponseCollection";
data: Array<{
__typename: "GamePlatformEntity";
id: string;
attributes: {
__typename: "GamePlatform";
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<{
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 = {
__typename: "Query";
contents: {
@ -1109,6 +1115,7 @@ export type GetContentTextQuery = {
__typename: "ContentEntityResponseCollection";
data: Array<{
__typename: "ContentEntity";
id: string;
attributes: {
__typename: "Content";
slug: string;

View File

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

View File

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

View File

@ -21,6 +21,9 @@ import {
prettyItemSubType,
prettyPrice,
prettySlug,
prettyTestError,
prettyTestWarning,
sortContent,
} from "queries/helpers";
import SubPanel from "components/Panels/SubPanel";
import ReturnButton from "components/PanelComponents/ReturnButton";
@ -33,13 +36,15 @@ import LibraryItemsPreview from "components/Library/LibraryItemsPreview";
import InsetBox from "components/InsetBox";
import Img, { ImageQuality } from "components/Img";
import { useAppLayout } from "contexts/AppLayoutContext";
import { useRouter } from "next/router";
type LibrarySlugProps = {
interface LibrarySlugProps {
libraryItem: GetLibraryItemQuery;
langui: GetWebsiteInterfaceQuery;
};
}
export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
useTesting(props);
const item = props.libraryItem.libraryItems.data[0].attributes;
const langui = props.langui.websiteInterfaces.data[0].attributes;
const appLayout = useAppLayout();
@ -49,6 +54,8 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
item.metadata[0].__typename === "ComponentMetadataOther" &&
item.metadata[0].subtype.data.attributes.slug === "variant-set";
sortContent(item.contents);
const subPanel = (
<SubPanel>
<ReturnButton
@ -465,20 +472,6 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
</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 (
<AppLayout
navTitle={langui.main_library}
@ -486,7 +479,7 @@ export default function LibrarySlug(props: LibrarySlugProps): JSX.Element {
langui={langui}
contentPanel={contentPanel}
subPanel={subPanel}
thumbnail={item.thumbnail.data.attributes}
thumbnail={item.thumbnail.data?.attributes}
description={
item.descriptions.length > 0
? item.descriptions[0].description
@ -539,3 +532,394 @@ export const getStaticPaths: GetStaticPaths = async (context) => {
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(
props: DataChronologyProps
): JSX.Element {
useTesting(props);
const langui = props.langui.websiteInterfaces.data[0].attributes;
const chronologyItems = props.chronologyItems.chronologyItems;
const chronologyEras = props.chronologyEras.chronologyEras;
useTesting(props.chronologyItems, props.chronologyEras);
// Group by year the Chronology items
let chronologyItemYearGroups: GetChronologyItemsQuery["chronologyItems"]["data"][number][][][] =
@ -162,59 +162,76 @@ export const getStaticProps: GetStaticProps = async (context) => {
return { props: {} };
};
export function useTesting(
chronologyItems: GetChronologyItemsQuery,
chronologyEras: GetErasQuery
) {
function useTesting({ chronologyItems, chronologyEras }: DataChronologyProps) {
const router = useRouter();
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) {
prettyTestError(
router,
"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) {
prettyTestError(router, "More than one title and description", [
"chronologyEras",
era.attributes.slug,
]);
prettyTestError(
router,
"More than one title and description",
["chronologyEras", era.attributes.slug],
chronologyErasURL
);
} else {
if (!era.attributes.title[0].title)
prettyTestError(router, "Missing title, using slug instead", [
"chronologyEras",
era.attributes.slug,
]);
prettyTestError(
router,
"Missing title, using slug instead",
["chronologyEras", era.attributes.slug],
chronologyErasURL
);
if (!era.attributes.title[0].description)
prettyTestError(router, "Missing description", [
"chronologyEras",
era.attributes.slug,
]);
prettyTestError(
router,
"Missing description",
["chronologyEras", era.attributes.slug],
chronologyErasURL
);
}
});
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}`;
if (!(item.attributes.events.length > 0)) {
prettyTestError(router, "No events for this date", [
"chronologyItems",
date,
]);
prettyTestError(
router,
"No events for this date",
["chronologyItems", date],
chronologyItemsURL
);
} else {
item.attributes.events.map((event) => {
if (!event.source.data) {
prettyTestError(router, "No source for this event", [
"chronologyItems",
date,
event.id,
]);
prettyTestError(
router,
"No source for this event",
["chronologyItems", date, event.id],
chronologyItemsURL
);
}
if (!(event.translations.length > 0)) {
prettyTestWarning(router, "No translation for this event", [
"chronologyItems",
date,
event.id,
]);
prettyTestWarning(
router,
"No translation for this event",
["chronologyItems", date, event.id],
chronologyItemsURL
);
}
});
}

View File

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