From cf842409b4011d2f508930f79be53564d79fc3f2 Mon Sep 17 00:00:00 2001 From: Philipp Melab Date: Thu, 27 Jun 2024 12:59:59 +0200 Subject: [PATCH] chore: update schema tests --- tests/schema/specs/blocks.spec.ts | 10 +++- tests/schema/specs/content.spec.ts | 4 +- tests/schema/specs/links.spec.ts | 2 +- tests/schema/specs/media.spec.ts | 44 ----------------- tests/schema/specs/ssg-pages.spec.ts | 48 +++++++++++++++++++ .../schema/specs/string-translations.spec.ts | 27 +++++++++++ 6 files changed, 86 insertions(+), 49 deletions(-) delete mode 100644 tests/schema/specs/media.spec.ts create mode 100644 tests/schema/specs/ssg-pages.spec.ts create mode 100644 tests/schema/specs/string-translations.spec.ts diff --git a/tests/schema/specs/blocks.spec.ts b/tests/schema/specs/blocks.spec.ts index 6ac6df879..b22c72a55 100644 --- a/tests/schema/specs/blocks.spec.ts +++ b/tests/schema/specs/blocks.spec.ts @@ -28,9 +28,12 @@ test('Blocks', async () => { __typename ... on MediaImage { __typename + source + alt } ... on MediaVideo { __typename + url } } } @@ -92,10 +95,10 @@ test('Blocks', async () => { } } { - complete: _loadDrupalPage(id: "a397ca48-8fad-411e-8901-0eba2feb989c") { + complete: viewPage(path: "/en/blocks-complete") { ...Blocks } - minimal: _loadDrupalPage(id: "ceb9b2a7-4c4c-4084-ada9-d5f6505d466b") { + minimal: viewPage(path: "/en/blocks-minimal") { ...Blocks } } @@ -132,6 +135,8 @@ test('Blocks', async () => { "caption": "Media image", "media": { "__typename": "MediaImage", + "alt": "A beautiful landscape.", + "source": "{"src":"http:\\/\\/127.0.0.1:8000\\/sites\\/default\\/files\\/2023-04\\/landscape.jpg","width":2200,"height":1414,"originalSrc":"http:\\/\\/127.0.0.1:8000\\/sites\\/default\\/files\\/2023-04\\/landscape.jpg"}", }, }, { @@ -139,6 +144,7 @@ test('Blocks', async () => { "caption": "Media video", "media": { "__typename": "MediaVideo", + "url": "http://127.0.0.1:8000/sites/default/files/2023-06/video_mp4_belt.mp4", }, }, { diff --git a/tests/schema/specs/content.spec.ts b/tests/schema/specs/content.spec.ts index af6297fa9..e41b33fa7 100644 --- a/tests/schema/specs/content.spec.ts +++ b/tests/schema/specs/content.spec.ts @@ -30,10 +30,10 @@ test('Page', async () => { } } { - complete: _loadDrupalPage(id: "ef80e284-154b-41fd-9317-154b0a175299") { + complete: viewPage(path: "/en/page-complete") { ...Page } - minimal: _loadDrupalPage(id: "17626bb4-557f-48fc-b869-ae566f4ceae6") { + minimal: viewPage(path: "/en/page-minimal") { ...Page } } diff --git a/tests/schema/specs/links.spec.ts b/tests/schema/specs/links.spec.ts index 2262cb2b1..3762e585e 100644 --- a/tests/schema/specs/links.spec.ts +++ b/tests/schema/specs/links.spec.ts @@ -6,7 +6,7 @@ import { fetch } from '../lib.js'; test('Links', async () => { const result = await fetch(gql` { - page: _loadDrupalPage(id: "25086be7-ca5f-4ff8-9695-b9c71a676d4e") { + page: viewPage(path: "/en/page-links") { content { __typename ... on BlockMarkup { diff --git a/tests/schema/specs/media.spec.ts b/tests/schema/specs/media.spec.ts deleted file mode 100644 index 3fdb2ea28..000000000 --- a/tests/schema/specs/media.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -import gql from 'noop-tag'; -import { expect, test } from 'vitest'; - -import { fetch } from '../lib.js'; - -test('Image', async () => { - const result = await fetch(gql` - { - _loadMediaImage(id: "3a0fe860-a6d6-428a-9474-365bd57509aa") { - source - alt - } - } - `); - expect(result).toMatchInlineSnapshot(` - { - "data": { - "_loadMediaImage": { - "alt": "A beautiful landscape.", - "source": "{"src":"http:\\/\\/127.0.0.1:8000\\/sites\\/default\\/files\\/2023-04\\/landscape.jpg","width":2200,"height":1414,"originalSrc":"http:\\/\\/127.0.0.1:8000\\/sites\\/default\\/files\\/2023-04\\/landscape.jpg"}", - }, - }, - } - `); -}); - -test('Video', async () => { - const result = await fetch(gql` - { - _loadMediaVideo(id: "478c4289-961d-4ce8-85d6-578ae05f3019") { - url - } - } - `); - expect(result).toMatchInlineSnapshot(` - { - "data": { - "_loadMediaVideo": { - "url": "http://127.0.0.1:8000/sites/default/files/2023-06/video_mp4_belt.mp4", - }, - }, - } - `); -}); diff --git a/tests/schema/specs/ssg-pages.spec.ts b/tests/schema/specs/ssg-pages.spec.ts new file mode 100644 index 000000000..1569038cb --- /dev/null +++ b/tests/schema/specs/ssg-pages.spec.ts @@ -0,0 +1,48 @@ +import gql from 'noop-tag'; +import { describe, expect, it } from 'vitest'; + +import { fetch } from '../lib.js'; + +describe('SSG pages', () => { + it('returns limited results', async () => { + const result = await fetch(gql` + { + ssgPages(args: "pageSize=2&type=page") { + rows { + path + } + total + } + } + `); + expect(result.data.ssgPages.total).toBeGreaterThan(2); + expect(result.data.ssgPages.rows.length).toBe(2); + }); + + it('respects pagination', async () => { + const resultA = await fetch(gql` + { + ssgPages(args: "pageSize=1&page=2&type=page") { + rows { + path + } + } + } + `); + const resultB = await fetch(gql` + { + ssgPages(args: "pageSize=2&type=page") { + rows { + path + } + } + } + `); + + expect(resultA.data.ssgPages.rows.length).toBe(1); + expect(resultB.data.ssgPages.rows.length).toBe(2); + expect(resultA.data.ssgPages.rows[0].path).toBe( + resultB.data.ssgPages.rows[1].path, + ); + }); +}); diff --git a/tests/schema/specs/string-translations.spec.ts b/tests/schema/specs/string-translations.spec.ts new file mode 100644 index 000000000..26a2ca44d --- /dev/null +++ b/tests/schema/specs/string-translations.spec.ts @@ -0,0 +1,27 @@ +import gql from 'noop-tag'; +import { expect, test } from 'vitest'; + +import { fetch } from '../lib.js'; + +test('string translations', async () => { + const result = await fetch(gql` + { + stringTranslations { + source + translation + language + } + } + `); + expect(result.data).toMatchInlineSnapshot(` + { + "stringTranslations": [ + { + "language": "de", + "source": "Company name", + "translation": "Drupal Company", + }, + ], + } + `); +});