|
| 1 | +import {expect, test} from '@repo/e2e' |
| 2 | + |
| 3 | +test.describe('Multi Resource Route', () => { |
| 4 | + test('can view and edit documents from multiple resources', async ({ |
| 5 | + page, |
| 6 | + getClient, |
| 7 | + createDocuments, |
| 8 | + getPageContext, |
| 9 | + }) => { |
| 10 | + // create an author document in dataset 0 |
| 11 | + const { |
| 12 | + documentIds: [authorId], |
| 13 | + } = await createDocuments( |
| 14 | + [ |
| 15 | + { |
| 16 | + _type: 'author', |
| 17 | + name: 'Test Author Multi Resource', |
| 18 | + role: 'developer', |
| 19 | + awards: ['Best Code Award', 'Innovation Prize'], |
| 20 | + }, |
| 21 | + ], |
| 22 | + {asDraft: false}, // Create as published document |
| 23 | + process.env['SDK_E2E_DATASET_0'], // First dataset |
| 24 | + ) |
| 25 | + |
| 26 | + // Create a player document in dataset 1 |
| 27 | + const { |
| 28 | + documentIds: [playerId], |
| 29 | + } = await createDocuments( |
| 30 | + [ |
| 31 | + { |
| 32 | + _type: 'player', |
| 33 | + name: 'Test Player Multi Resource', |
| 34 | + slackUserId: 'U1234567890', |
| 35 | + }, |
| 36 | + ], |
| 37 | + {asDraft: false}, // Create as published document |
| 38 | + process.env['SDK_E2E_DATASET_1'], // Second dataset |
| 39 | + ) |
| 40 | + |
| 41 | + await page.goto('./multi-resource') |
| 42 | + |
| 43 | + // get the page context for iframe/page detection |
| 44 | + const pageContext = await getPageContext(page) |
| 45 | + |
| 46 | + // Wait for both document cards to be visible |
| 47 | + await expect(pageContext.getByTestId(/^author-document-/)).toBeVisible() |
| 48 | + await expect(pageContext.getByTestId(/^player-document-/)).toBeVisible() |
| 49 | + |
| 50 | + // Verify author document content is displayed |
| 51 | + await expect(pageContext.getByTestId('author-name-display')).toHaveText( |
| 52 | + 'Test Author Multi Resource', |
| 53 | + ) |
| 54 | + |
| 55 | + // Verify player document content is displayed |
| 56 | + await expect(pageContext.getByTestId('player-name-display')).toHaveText( |
| 57 | + 'Test Player Multi Resource', |
| 58 | + ) |
| 59 | + |
| 60 | + // Test author projection data |
| 61 | + await expect(pageContext.getByTestId('author-projection-name')).toContainText( |
| 62 | + 'Test Author Multi Resource', |
| 63 | + ) |
| 64 | + await expect(pageContext.getByTestId('author-projection-role')).toContainText('developer') |
| 65 | + await expect(pageContext.getByTestId('author-projection-award-count')).toContainText('2') |
| 66 | + await expect(pageContext.getByTestId('author-projection-first-award')).toContainText( |
| 67 | + 'Best Code Award', |
| 68 | + ) |
| 69 | + |
| 70 | + // Test player projection data |
| 71 | + await expect(pageContext.getByTestId('player-projection-name')).toContainText( |
| 72 | + 'Test Player Multi Resource', |
| 73 | + ) |
| 74 | + await expect(pageContext.getByTestId('player-projection-slack-id')).toContainText('U1234567890') |
| 75 | + await expect(pageContext.getByTestId('player-projection-has-slack')).toContainText('Yes') |
| 76 | + |
| 77 | + // Test editing the author document |
| 78 | + const authorNameInput = pageContext.getByTestId('author-name-input') |
| 79 | + await authorNameInput.fill('Updated Author Name') |
| 80 | + await authorNameInput.press('Enter') |
| 81 | + |
| 82 | + // Verify the change is reflected in the display |
| 83 | + await expect(pageContext.getByTestId('author-name-display')).toHaveText('Updated Author Name') |
| 84 | + |
| 85 | + // Verify the change is also reflected in the projection |
| 86 | + await expect(pageContext.getByTestId('author-projection-name')).toContainText( |
| 87 | + 'Updated Author Name', |
| 88 | + ) |
| 89 | + |
| 90 | + // Test editing the player document |
| 91 | + const playerNameInput = pageContext.getByTestId('player-name-input') |
| 92 | + await playerNameInput.fill('Updated Player Name') |
| 93 | + await playerNameInput.press('Enter') |
| 94 | + |
| 95 | + // Verify the change is reflected in the display |
| 96 | + await expect(pageContext.getByTestId('player-name-display')).toHaveText('Updated Player Name') |
| 97 | + |
| 98 | + // Verify the change is also reflected in the projection |
| 99 | + await expect(pageContext.getByTestId('player-projection-name')).toContainText( |
| 100 | + 'Updated Player Name', |
| 101 | + ) |
| 102 | + |
| 103 | + // Test that external changes are reflected (simulating real-time updates) |
| 104 | + const authorClient = getClient(process.env['SDK_E2E_DATASET_0']) |
| 105 | + await authorClient.patch(`drafts.${authorId}`).set({name: 'Externally Updated Author'}).commit() |
| 106 | + |
| 107 | + // Test external change for player |
| 108 | + const playerClient = getClient(process.env['SDK_E2E_DATASET_1']) |
| 109 | + await playerClient.patch(`drafts.${playerId}`).set({name: 'Externally Updated Player'}).commit() |
| 110 | + |
| 111 | + // Verify external change is reflected |
| 112 | + await expect(async () => { |
| 113 | + const authorDisplay = await pageContext.getByTestId('author-name-display').textContent() |
| 114 | + const authorProjection = await pageContext.getByTestId('author-projection-name').textContent() |
| 115 | + expect(authorDisplay).toBe('Externally Updated Author') |
| 116 | + expect(authorProjection).toContain('Externally Updated Author') |
| 117 | + }).toPass({timeout: 5000}) |
| 118 | + |
| 119 | + // Verify external change is reflected |
| 120 | + await expect(async () => { |
| 121 | + const playerDisplay = await pageContext.getByTestId('player-name-display').textContent() |
| 122 | + const playerProjection = await pageContext.getByTestId('player-projection-name').textContent() |
| 123 | + expect(playerDisplay).toBe('Externally Updated Player') |
| 124 | + expect(playerProjection).toContain('Externally Updated Player') |
| 125 | + }).toPass({timeout: 5000}) |
| 126 | + }) |
| 127 | +}) |
0 commit comments