Skip to content

Commit

Permalink
implement ability for e2e tests to patch appConfig (#4548)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis authored Jun 20, 2024
1 parent 4bd4239 commit afb63b3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
34 changes: 34 additions & 0 deletions e2e/client/playwright/authoring.publish.embargo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {test, expect} from '@playwright/test';
import {Monitoring} from './page-object-models/monitoring';
import {restoreDatabaseSnapshot, s} from './utils';
import {getStorageState} from './utils/storage-state';

test.use({
storageState: getStorageState({ui: {publishEmbargo: false}}),
});

test('disabling publish embargo by adjusting instance configuration', async ({page}) => {
await restoreDatabaseSnapshot();

const monitoring = new Monitoring(page);

await page.goto('/#/workspace/monitoring');

await monitoring.selectDeskOrWorkspace('Sports');

await page.locator(
s('monitoring-group=Sports / Working Stage', 'article-item=test sports story'),
).dblclick();

await page.locator(s('authoring', 'open-send-publish-pane')).click();

// "target" section is not relevant for this test
// but is used as a control to make sure panel content has finished loading
await expect(
page.locator(s('authoring', 'interactive-actions-panel')).getByRole('button', {name: 'Target'}),
).toBeVisible();

await expect(
page.locator(s('authoring', 'interactive-actions-panel')).getByRole('button', {name: 'Embargo'}),
).not.toBeVisible();
});
16 changes: 16 additions & 0 deletions e2e/client/playwright/utils/storage-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {BrowserContextOptions} from '@playwright/test';
import {ISuperdeskGlobalConfig} from 'superdesk-api';
import storageState from '../.auth/user.json';

type StorageState = BrowserContextOptions['storageState'];

/**
* Allows to set custom application configs while preserving values defined in .auth/user.json
*/
export function getStorageState(appConfigPatch: Partial<ISuperdeskGlobalConfig>): StorageState {
const storageStateCopy = JSON.parse(JSON.stringify(storageState));

storageStateCopy['origins'][0].localStorage.push({name: 'TEST_APP_CONFIG', value: JSON.stringify(appConfigPatch)});

return storageStateCopy;
}
4 changes: 4 additions & 0 deletions scripts/appConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {merge} from 'lodash';
import {ISuperdeskGlobalConfig, IExtensions, IUser} from 'superdesk-api';

/* globals __SUPERDESK_CONFIG__: true */
Expand Down Expand Up @@ -27,6 +28,9 @@ if (appConfig.features.autorefreshContent == null) {
appConfig.features.autorefreshContent = true; // default to true
}

// allow e2e tests to overwrite appConfig via local storage
Object.assign(appConfig, merge(appConfig, JSON.parse(localStorage.getItem('TEST_APP_CONFIG') ?? '{}')));

export const dashboardRoute = '/workspace';
export const IDENTITY_KEY = 'sess:user';
export const extensions: IExtensions = {};
Expand Down

0 comments on commit afb63b3

Please sign in to comment.