Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/csm/createEditUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
if (dataset) {
searchParams.set('dataset', dataset)
}
// @TODO what is going on here?

Check warning on line 59 in src/csm/createEditUrl.ts

View workflow job for this annotation

GitHub Actions / Build, lint and benchmark

Unexpected '@todo' comment: '@todo what is going on here?'.
if (isPublishedId(_id)) {
searchParams.set('perspective', 'published')
} else if (isVersionId(_id)) {
Expand Down
156 changes: 156 additions & 0 deletions test/stega/__snapshots__/stegaEncodeSourceMap.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,162 @@ exports[`GraphQL API > logger.table 1`] = `
]
`;

exports[`Handles Content Releases > decode all 1`] = `
[
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=18c9ae1a-5c14-4ffe-b32e-8e488f043718;type=author;path=name",
Map {
"baseUrl" => "https://test.sanity.studio",
"id" => "18c9ae1a-5c14-4ffe-b32e-8e488f043718",
"type" => "author",
"path" => "name",
"perspective" => "published",
},
],
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=18c9ae1a-5c14-4ffe-b32e-8e488f043718;type=author;path=picture.alt",
Map {
"baseUrl" => "https://test.sanity.studio",
"id" => "18c9ae1a-5c14-4ffe-b32e-8e488f043718",
"type" => "author",
"path" => "picture.alt",
"perspective" => "published",
},
],
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=e1674ab7-5f96-49b0-8291-7608e087ef0a;type=author;path=name",
Map {
"baseUrl" => "https://test.sanity.studio",
"id" => "e1674ab7-5f96-49b0-8291-7608e087ef0a",
"type" => "author",
"path" => "name",
"perspective" => "rrRHoDGSr",
},
],
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=e1674ab7-5f96-49b0-8291-7608e087ef0a;type=author;path=picture.alt",
Map {
"baseUrl" => "https://test.sanity.studio",
"id" => "e1674ab7-5f96-49b0-8291-7608e087ef0a",
"type" => "author",
"path" => "picture.alt",
"perspective" => "rrRHoDGSr",
},
],
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=f99b873f-85c2-41c4-ac65-807b1d72c084;type=author;path=name",
Map {
"baseUrl" => "https://test.sanity.studio",
"id" => "f99b873f-85c2-41c4-ac65-807b1d72c084",
"type" => "author",
"path" => "name",
},
],
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=f99b873f-85c2-41c4-ac65-807b1d72c084;type=author;path=picture.alt",
Map {
"baseUrl" => "https://test.sanity.studio",
"id" => "f99b873f-85c2-41c4-ac65-807b1d72c084",
"type" => "author",
"path" => "picture.alt",
},
],
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=f99b873f-85c2-41c4-ac65-807b1d72c084;type=author;path=name",
Map {
"baseUrl" => "https://test.sanity.studio",
"id" => "f99b873f-85c2-41c4-ac65-807b1d72c084",
"type" => "author",
"path" => "name",
},
],
[
"https://test.sanity.studio/intent/edit/mode=presentation;id=f99b873f-85c2-41c4-ac65-807b1d72c084;type=author;path=picture.alt",
Map {
"baseUrl" => "https://test.sanity.studio",
"id" => "f99b873f-85c2-41c4-ac65-807b1d72c084",
"type" => "author",
"path" => "picture.alt",
},
],
]
`;

exports[`Handles Content Releases > logger.error 1`] = `[]`;

exports[`Handles Content Releases > logger.log 1`] = `
[
[
"[@sanity/client]: Encoding source map into result",
],
[
"[@sanity/client]: Paths encoded: 8, skipped: 20",
],
[
"[@sanity/client]: Table of encoded paths",
],
[
"[@sanity/client]: List of skipped paths",
[
"_id",
"_originalId",
"picture._type",
"picture.asset._ref",
"picture.asset._type",
],
],
]
`;

exports[`Handles Content Releases > logger.table 1`] = `
[
[
[
{
"length": 11,
"path": "name",
"value": "Test Author",
},
{
"length": 65,
"path": "picture.alt",
"value": "a computer generated...",
},
{
"length": 26,
"path": "name",
"value": "Another One!! BLACK ...",
},
{
"length": 37,
"path": "picture.alt",
"value": "the letter a is lit ...",
},
{
"length": 8,
"path": "name",
"value": "John Doe",
},
{
"length": 37,
"path": "picture.alt",
"value": "the letter a is lit ...",
},
{
"length": 8,
"path": "name",
"value": "John Doe",
},
{
"length": 37,
"path": "picture.alt",
"value": "the letter a is lit ...",
},
],
],
]
`;

exports[`resolveEditUrl '/' > decode all 1`] = `
[
"/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[_key=="d8fa6d59e49b"].children[_key=="6a057cf2fb310"].text",
Expand Down
28 changes: 28 additions & 0 deletions test/stega/stegaEncodeSourceMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {expect, test, vi} from 'vitest'

import {stegaEncodeSourceMap} from '../../src/stega/stegaEncodeSourceMap'
import type {ContentSourceMap, Logger} from '../../src/stega/types'
import stegaSnapshotContentReleases from './stegaSnapshotContentReleases.json' with {type: 'json'}

const mock = {
query:
Expand Down Expand Up @@ -622,3 +623,30 @@ test('GraphQL API', () => {
expect(logger.log.mock.calls).toMatchSnapshot('logger.log')
expect(logger.table.mock.calls).toMatchSnapshot('logger.table')
})

test('Handles Content Releases', () => {
const logger = {
error: vi.fn(),
log: vi.fn(),
table: vi.fn(),
} satisfies Logger
const studioUrl = 'https://test.sanity.studio'
const encoded = stegaEncodeSourceMap(
stegaSnapshotContentReleases.result,
stegaSnapshotContentReleases.resultSourceMap as ContentSourceMap,
{
enabled: true,
studioUrl,
logger,
},
)
expect(
vercelStegaDecodeAll(JSON.stringify(encoded)).map(({href}: any) => {
const [url, search] = decodeURIComponent(href).split('?')
return [url, new Map(new URLSearchParams(search).entries())]
}),
).toMatchSnapshot('decode all')
expect(logger.error.mock.calls).toMatchSnapshot('logger.error')
expect(logger.log.mock.calls).toMatchSnapshot('logger.log')
expect(logger.table.mock.calls).toMatchSnapshot('logger.table')
})
Loading
Loading