|
| 1 | +import test, { expect } from '@playwright/test'; |
| 2 | +import { getWorkspacesUrl } from '../../src/utilities/routes.js'; |
| 3 | +import { Dictionaries } from '../fixtures/Dictionaries.js'; |
| 4 | +import { Parcels } from '../fixtures/Parcels.js'; |
| 5 | +import { Workspace } from '../fixtures/Workspace.js'; |
| 6 | +import { Workspaces } from '../fixtures/Workspaces.js'; |
| 7 | +import { setupTest, teardownTest, type BrowserSetupResult } from '../utilities/api.js'; |
| 8 | +import { generateRandomName } from '../utilities/helpers.js'; |
| 9 | + |
| 10 | +// Load the CommonJS module dynamically |
| 11 | +const adaptationModule = await import('../data/sequence-adaptation-multiple-output.cjs'); |
| 12 | +const adaptation = adaptationModule.default.adaptation; |
| 13 | + |
| 14 | +// Main setup (uses default 'test' user) |
| 15 | +let setup: BrowserSetupResult; |
| 16 | +let dictionaries: Dictionaries; |
| 17 | +let parcels: Parcels; |
| 18 | +let sequence: { sequenceName: string; sequencePath: string }; |
| 19 | +let workspace: Workspace; |
| 20 | +let workspaces: Workspaces; |
| 21 | +let workspaceId: string; |
| 22 | +let workspaceName: string; |
| 23 | + |
| 24 | +test.beforeAll(async ({ baseURL, browser }) => { |
| 25 | + // Increase global timeout to prevent early test termination |
| 26 | + test.setTimeout(60000); // 60 seconds |
| 27 | + |
| 28 | + setup = await setupTest(browser, { model: false }); |
| 29 | + |
| 30 | + dictionaries = new Dictionaries(setup.page); |
| 31 | + parcels = new Parcels(setup.page); |
| 32 | + workspaces = new Workspaces(setup.page, parcels, baseURL); |
| 33 | + |
| 34 | + // Setup dependencies: dictionary and parcel |
| 35 | + await dictionaries.goto(); |
| 36 | + await dictionaries.createCommandDictionary(); |
| 37 | + await dictionaries.createSequenceAdaptation(undefined, 'e2e-tests/data/sequence-adaptation-multiple-output.cjs'); |
| 38 | + await parcels.goto(); |
| 39 | + await parcels.createParcel(dictionaries.commandDictionaryName, baseURL); |
| 40 | + await parcels.updateDictionarySelections({ |
| 41 | + sequenceAdaptationName: dictionaries.sequenceAdaptationName, |
| 42 | + }); |
| 43 | + |
| 44 | + // Create a workspace for testing |
| 45 | + await workspaces.goto(); |
| 46 | + workspaceId = await workspaces.createWorkspace(); |
| 47 | + workspaceName = workspaces.workspaceName; |
| 48 | + |
| 49 | + // Initialize workspace fixture |
| 50 | + workspace = new Workspace(setup.page, workspaceId, workspaceName, baseURL); |
| 51 | + workspace.updatePage(setup.page); |
| 52 | + await workspace.goto(); |
| 53 | + |
| 54 | + // Setup workspace |
| 55 | + sequence = await workspace.createSequence(undefined, `${generateRandomName()}${adaptation.input.fileExtension}`); |
| 56 | + await workspace.searchForFileAndWait(sequence.sequenceName); |
| 57 | + await workspace.clickFile(sequence.sequenceName); |
| 58 | + |
| 59 | + await expect(setup.page).toHaveURL( |
| 60 | + getWorkspacesUrl( |
| 61 | + workspace.baseURL, |
| 62 | + parseInt(workspace.workspaceId), |
| 63 | + `${sequence.sequencePath}/${sequence.sequenceName}`, |
| 64 | + ), |
| 65 | + ); |
| 66 | + |
| 67 | + // Make changes |
| 68 | + await workspace.fillSequenceContent('// New content'); |
| 69 | + |
| 70 | + // Verify save button is now enabled (unsaved changes detected) |
| 71 | + await expect(workspace.saveSequenceButton).toBeEnabled(); |
| 72 | + |
| 73 | + // Save and verify button is disabled again |
| 74 | + await workspace.saveSequence(); |
| 75 | + |
| 76 | + await workspace.openOutputPanel(); |
| 77 | +}); |
| 78 | + |
| 79 | +test.afterAll(async () => { |
| 80 | + // Cleanup: delete workspace, parcel, and dictionary |
| 81 | + await workspaces.goto(); |
| 82 | + await workspaces.deleteWorkspace(workspaceName); |
| 83 | + await parcels.goto(); |
| 84 | + await parcels.deleteParcel(); |
| 85 | + |
| 86 | + await teardownTest(setup); |
| 87 | +}); |
| 88 | + |
| 89 | +for (let i = 0; i < adaptation.outputs.length; i++) { |
| 90 | + const output = adaptation.outputs[i]; |
| 91 | + const languageOutput = output.toOutputFormat(); |
| 92 | + |
| 93 | + test.describe.serial('Workspace with sequence adaptation with multiple output languages', () => { |
| 94 | + test(`Convert input to ${output.name}`, async () => { |
| 95 | + const outputEditor = workspace.page.getByTestId('output-editor'); |
| 96 | + |
| 97 | + await workspace.page.getByRole('combobox', { name: 'Output Format' }).selectOption({ index: i }); |
| 98 | + |
| 99 | + // Validate that the output editor contains the correct output for the selected adaptation output language |
| 100 | + await expect(outputEditor).toContainText(languageOutput); |
| 101 | + }); |
| 102 | + |
| 103 | + test(`Copy the output for ${output.name}`, async () => { |
| 104 | + // Grant clipboard permissions for this test |
| 105 | + await setup.context.grantPermissions(['clipboard-read', 'clipboard-write']); |
| 106 | + |
| 107 | + await workspace.page.getByRole('button', { name: 'Copy as' }).click(); |
| 108 | + |
| 109 | + // Read from clipboard and verify |
| 110 | + const clipboardText = await setup.page.evaluate(() => navigator.clipboard.readText()); |
| 111 | + |
| 112 | + // Validate that the clipboard contains the correct output for the selected adaptation output language |
| 113 | + expect(clipboardText).toContain(languageOutput); |
| 114 | + }); |
| 115 | + }); |
| 116 | +} |
0 commit comments