|
| 1 | +import {expect, test} from '@repo/e2e' |
| 2 | +import {getVersionId} from 'sanity' |
| 3 | + |
| 4 | +test.describe('Releases Route', () => { |
| 5 | + test('can create base documents and release versions', async ({ |
| 6 | + page, |
| 7 | + getClient, |
| 8 | + createDocuments, |
| 9 | + getPageContext, |
| 10 | + }) => { |
| 11 | + const client = getClient() |
| 12 | + |
| 13 | + // First create the bestFriend author document so we can test references across docs |
| 14 | + const { |
| 15 | + documentIds: [bestFriendId], |
| 16 | + } = await createDocuments( |
| 17 | + [ |
| 18 | + { |
| 19 | + _type: 'author', |
| 20 | + name: 'Base Best Friend', |
| 21 | + }, |
| 22 | + ], |
| 23 | + {asDraft: false}, |
| 24 | + ) |
| 25 | + |
| 26 | + // Create the main test document |
| 27 | + const { |
| 28 | + documentIds: [testDocId], |
| 29 | + } = await createDocuments( |
| 30 | + [ |
| 31 | + { |
| 32 | + _type: 'author', |
| 33 | + name: 'Base Test Author', |
| 34 | + bestFriend: {_type: 'reference', _ref: bestFriendId, _weak: true}, |
| 35 | + }, |
| 36 | + ], |
| 37 | + {asDraft: false}, |
| 38 | + ) |
| 39 | + |
| 40 | + await page.goto('./releases') |
| 41 | + const pageContext = await getPageContext(page) |
| 42 | + const heading = pageContext.getByText('Releases', {exact: true}).first() |
| 43 | + await expect(heading).toBeVisible({timeout: 30000}) |
| 44 | + |
| 45 | + // Create the release |
| 46 | + const {releaseId} = await client.releases.create({ |
| 47 | + metadata: { |
| 48 | + title: 'Test Release', |
| 49 | + releaseType: 'scheduled', |
| 50 | + }, |
| 51 | + }) |
| 52 | + |
| 53 | + // Create release version documents |
| 54 | + await createDocuments( |
| 55 | + [ |
| 56 | + { |
| 57 | + _id: getVersionId(bestFriendId, releaseId), |
| 58 | + _type: 'author', |
| 59 | + name: 'Release Best Friend', |
| 60 | + }, |
| 61 | + { |
| 62 | + _id: getVersionId(testDocId, releaseId), |
| 63 | + _type: 'author', |
| 64 | + name: 'Release Test Author', |
| 65 | + bestFriend: {_type: 'reference', _ref: bestFriendId, _weak: true}, |
| 66 | + }, |
| 67 | + ], |
| 68 | + {asDraft: false}, |
| 69 | + ) |
| 70 | + |
| 71 | + // Verify the release document exists and is being listened to live |
| 72 | + const autocompleteInput = pageContext.locator('input[placeholder="Type to find release …"]') |
| 73 | + await expect(autocompleteInput).toBeVisible() |
| 74 | + |
| 75 | + await autocompleteInput.click() |
| 76 | + await autocompleteInput.fill('Test') |
| 77 | + |
| 78 | + const releaseIdText = pageContext.getByText(`Release ID: ${releaseId}`) |
| 79 | + await expect(releaseIdText).toBeVisible({timeout: 10000}) |
| 80 | + |
| 81 | + const releaseButton = pageContext.getByRole('button', { |
| 82 | + name: new RegExp(`Test Release.*Release ID: ${releaseId}`), |
| 83 | + }) |
| 84 | + await expect(releaseButton).toBeVisible() |
| 85 | + await releaseButton.click() |
| 86 | + |
| 87 | + await expect(autocompleteInput).toHaveValue('Test Release', {timeout: 10000}) |
| 88 | + |
| 89 | + const selectedPerspectiveHeading = pageContext.getByText('Selected Perspective') |
| 90 | + await expect(selectedPerspectiveHeading).toBeVisible() |
| 91 | + |
| 92 | + const releaseIdInPerspective = pageContext.getByText(releaseId).first() |
| 93 | + await expect(releaseIdInPerspective).toBeVisible({timeout: 10000}) |
| 94 | + |
| 95 | + // Enter the test document ID in the "View Document across different perspectives" input |
| 96 | + const documentPerspectiveHeading = pageContext.getByText( |
| 97 | + 'View Document across different perspectives', |
| 98 | + ) |
| 99 | + await expect(documentPerspectiveHeading).toBeVisible() |
| 100 | + |
| 101 | + const documentIdInput = pageContext.locator('input[placeholder="Enter document ID"]') |
| 102 | + await expect(documentIdInput).toBeVisible() |
| 103 | + await documentIdInput.fill(testDocId) |
| 104 | + await page.waitForTimeout(2000) |
| 105 | + |
| 106 | + const projectionCard = pageContext.getByTestId('document-projection-card') |
| 107 | + await projectionCard.scrollIntoViewIfNeeded() |
| 108 | + |
| 109 | + // Verify the projection also shows the release version |
| 110 | + await expect(async () => { |
| 111 | + const projectionContent = await projectionCard.textContent() |
| 112 | + expect(projectionContent).toContain('"bestFriend": "Release Best Friend"') |
| 113 | + }).toPass({timeout: 15000}) |
| 114 | + |
| 115 | + await client.action([ |
| 116 | + { |
| 117 | + actionType: 'sanity.action.document.edit', |
| 118 | + draftId: getVersionId(bestFriendId, releaseId), |
| 119 | + publishedId: bestFriendId, |
| 120 | + patch: { |
| 121 | + set: { |
| 122 | + name: 'Updated Release Best Friend', |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + ]) |
| 127 | + |
| 128 | + await expect(async () => { |
| 129 | + const projectionContent = await projectionCard.textContent() |
| 130 | + expect(projectionContent).toContain('"bestFriend": "Updated Release Best Friend"') |
| 131 | + }).toPass({timeout: 20000, intervals: [2000, 3000, 5000]}) |
| 132 | + |
| 133 | + await client.action([ |
| 134 | + { |
| 135 | + actionType: 'sanity.action.document.edit', |
| 136 | + draftId: getVersionId(testDocId, releaseId), |
| 137 | + publishedId: testDocId, |
| 138 | + patch: { |
| 139 | + set: { |
| 140 | + name: 'Updated Release Test Author', |
| 141 | + }, |
| 142 | + }, |
| 143 | + }, |
| 144 | + ]) |
| 145 | + |
| 146 | + await expect(async () => { |
| 147 | + const projectionContent = await projectionCard.textContent() |
| 148 | + expect(projectionContent).toContain('"name": "Updated Release Test Author"') |
| 149 | + }).toPass({timeout: 20000, intervals: [2000, 3000, 5000]}) |
| 150 | + }) |
| 151 | +}) |
0 commit comments