Skip to content

Commit

Permalink
Merge branch 'develop' into format-date-time
Browse files Browse the repository at this point in the history
  • Loading branch information
dzonidoo committed Aug 14, 2024
2 parents ab5721c + fffbc6c commit 1e8cb3a
Show file tree
Hide file tree
Showing 59 changed files with 656 additions and 311 deletions.
84 changes: 84 additions & 0 deletions e2e/client/playwright/multiedit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {test, expect} from '@playwright/test';
import {Monitoring} from './page-object-models/monitoring';
import {Authoring} from './page-object-models/authoring';
import {MultiEdit} from './page-object-models/multiedit';
import {restoreDatabaseSnapshot, s} from './utils';

test.describe('Multiedit', async () => {
test('editing articles in multi-edit mode', async ({page}) => {
const monitoring = new Monitoring(page);
const multiedit = new MultiEdit(page);

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

await monitoring.executeBulkAction('Multi-edit', ['test sports story', 'story 2']);

await page
.locator(s('multiedit-screen', 'multiedit-article=test sports story', 'field--headline'))
.getByRole('textbox')
.clear();
await page
.locator(s('multiedit-screen', 'multiedit-article=test sports story', 'field--headline'))
.getByRole('textbox')
.fill('test sports story 1.1');

await multiedit.save('test sports story');

await page
.locator(s('multiedit-screen', 'multiedit-article=story 2', 'field--headline'))
.getByRole('textbox')
.clear();
await page
.locator(s('multiedit-screen', 'multiedit-article=story 2', 'field--headline'))
.getByRole('textbox')
.fill('story 2.1');

await multiedit.save('story 2');

await page.locator(s('multiedit-subnav')).getByRole('button', {name: 'exit'}).click();

await monitoring.executeActionOnMonitoringItem(
page.locator(s('article-item=test sports story 1.1')),
'Edit',
);
await expect(
page.locator(s('authoring', 'field--headline')).getByRole('textbox'),
).toHaveText('test sports story 1.1');

await monitoring.executeActionOnMonitoringItem(
page.locator(s('article-item=story 2.1')),
'Edit',
);
await expect(
page.locator(s('authoring', 'field--headline')).getByRole('textbox'),
).toHaveText('story 2.1');
});

test('removing an article from multi-edit view', async ({page}) => {
const monitoring = new Monitoring(page);
const authoring = new Authoring(page);

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

await monitoring.selectDeskOrWorkspace('Sports');

await monitoring.executeActionOnMonitoringItem(
page.locator(s('article-item=test sports story')),
'Edit',
);
await authoring.executeActionInEditor(
'Multiedit',
'OK',
);

await page.locator(s('multiedit-screen', 'multiedit-article=test sports story')).hover();
await page
.locator(s('multiedit-screen', 'multiedit-article=test sports story'))
.getByRole('button', {name: 'remove item'})
.click();
await expect(page.locator(s('multiedit-screen', 'multiedit-article=test sports story'))).not.toBeVisible();
});
});
9 changes: 9 additions & 0 deletions e2e/client/playwright/page-object-models/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export class Monitoring {
.click();
}

async executeBulkAction(action: string, articleNames: Array<string>): Promise<void> {
for (const selectedArticle of articleNames) {
await this.page.locator(s(`article-item=${selectedArticle}`, 'item-type-and-multi-select')).hover();
await this.page.locator(s(`article-item=${selectedArticle}`, 'multi-select-checkbox')).check();
}

await this.page.locator(s('multi-action-bar', 'multi-actions-inline', action)).click();
}

async createArticleFromTemplate(template: string, options?: {slugline?:string, body_html?: string}): Promise<void> {
await this.page.locator(s('content-create')).click();
await this.page.locator(s('content-create-dropdown')).getByRole('button', {name: 'More Templates...'}).click();
Expand Down
19 changes: 19 additions & 0 deletions e2e/client/playwright/page-object-models/multiedit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Page} from '@playwright/test';
import {s} from '../utils';

export class MultiEdit {
private page: Page;

constructor(page: Page) {
this.page = page;
}

async save(article: string): Promise<void> {
await this.page.locator(s('multiedit-screen', `multiedit-article=${article}`)).hover();

await this.page
.locator(s('multiedit-screen', `multiedit-article=${article}`))
.getByRole('button', {name: 'save'})
.click();
}
}
24 changes: 9 additions & 15 deletions e2e/client/specs/authoring_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ describe('authoring', () => {

it('authoring operations', () => {
// allows to create a new empty package
el(['content-create']).click();
el(['content-create-dropdown', 'create-package']).click();
monitoring.createItem('Create package');

expect(element(by.className('packaging-screen')).isDisplayed()).toBe(true);
authoring.close();
Expand Down Expand Up @@ -615,8 +614,8 @@ describe('authoring', () => {

it('Not modifying crops will not trigger an article change', () => {
workspace.selectDesk('XEditor3 Desk'); // has media gallery in content profile
el(['content-create']).click();
el(['content-create-dropdown']).element(by.buttonText('editor3 template')).click();
monitoring.createItem('editor3 template');

browser.wait(ECE.visibilityOf(
element(by.css(s('authoring-field=Image gallery 33', 'media-gallery--upload-placeholder'))),
));
Expand Down Expand Up @@ -645,15 +644,16 @@ describe('authoring', () => {

it('Can add an image with default crops to media gallery', () => {
workspace.selectDesk('XEditor3 Desk'); // has media gallery in content profile
el(['content-create']).click();
el(['content-create-dropdown']).element(by.buttonText('editor3 template')).click();
monitoring.createItem('editor3 template');

browser.wait(ECE.visibilityOf(
element(by.css(s('authoring-field=Image gallery 33', 'media-gallery--upload-placeholder'))),
));
expect(ECE.hasElementCount(

browser.wait(ECE.hasElementCount(
element.all(by.css(s('authoring-field=Image gallery 33', 'media-gallery-image'))),
0,
)()).toBe(true);
));

uploadMedia(getAbsoluteFilePath('test-files/image-big.jpg'));

Expand All @@ -666,13 +666,7 @@ describe('authoring', () => {
it('Can remove an image from media gallery', () => {
workspace.selectDesk('XEditor3 Desk'); // has media gallery in content profile

el(['content-create']).click();

const templateBtn = el(['content-create-dropdown']).element(by.buttonText('editor3 template'));

browser.wait(ECE.elementToBeClickable(templateBtn));

templateBtn.click();
monitoring.createItem('editor3 template');

browser.wait(ECE.visibilityOf(
element(by.css(s('authoring-field=Image gallery 33', 'media-gallery--upload-placeholder'))),
Expand Down
4 changes: 2 additions & 2 deletions e2e/client/specs/content_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {element, browser, protractor, by} from 'protractor';
import {workspace} from './helpers/workspace';
import {content} from './helpers/content';
import {authoring} from './helpers/authoring';
import {monitoring} from './helpers/monitoring';
import {multiAction} from './helpers/actions';
import {ECE, el} from '@superdesk/end-to-end-testing-helpers';
import {TreeSelectDriver} from './helpers/tree-select-driver';
Expand Down Expand Up @@ -164,8 +165,7 @@ describe('content', () => {
workspace.switchToDesk('SPORTS DESK');
content.setListView();

el(['content-create']).click();
el(['content-create-dropdown', 'create-package']).click();
monitoring.createItem('Create package');

element.all(by.model('item.headline')).first().sendKeys('Empty Package');
authoring.save();
Expand Down
2 changes: 1 addition & 1 deletion e2e/client/specs/editor3_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('editor3', () => {
monitoring.openMonitoring();
monitoring.selectDesk('xeditor3');
monitoring.createFromDeskTemplate();
browser.wait(ECE.presenceOf(editors.get(0)));
browser.wait(ECE.presenceOf(editors.get(0)), 2000);
});

it('can edit headline', () => {
Expand Down
8 changes: 5 additions & 3 deletions e2e/client/specs/helpers/authoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {waitHidden, waitFor, click} from './utils';
import {ECE, els, el} from '@superdesk/end-to-end-testing-helpers';
import {PLAIN_TEXT_TEMPLATE_NAME} from './constants';
import {TreeSelectDriver} from './tree-select-driver';
import {monitoring} from './monitoring';

class Authoring {
lock: any;
Expand Down Expand Up @@ -337,11 +338,12 @@ class Authoring {
* @param {String} name
*/
this.createTextItemFromTemplate = (name) => {
el(['content-create']).click();
el(['content-create-dropdown'], by.buttonText('More templates...')).click();
monitoring.createItem('More templates...');

el(['content-create-dropdown', 'search']).sendKeys(name);
el(['content-create-dropdown'], by.buttonText(name)).click();
browser.wait(ECE.presenceOf(el(['authoring'])));

browser.wait(ECE.presenceOf(el(['authoring'])), 2000);
};

this.close = function() {
Expand Down
22 changes: 20 additions & 2 deletions e2e/client/specs/helpers/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Monitoring {
showSpiked: () => void;
showPersonal: () => void;
showSearch: () => void;
createItem: (template: string) => void;
createFromDeskTemplate: () => any;
getGroup: (group: number) => any;
getGroups: () => any;
Expand Down Expand Up @@ -171,8 +172,14 @@ class Monitoring {
* Create new item using desk template
*/
this.createFromDeskTemplate = () => {
el(['content-create']).click();
el(['content-create-dropdown', 'default-desk-template']).click();
const createButton = el(['content-create']);
const templateButton = el(['content-create-dropdown', 'default-desk-template']);

browser.wait(ECE.elementToBeClickable(createButton), 1000);
createButton.click();

browser.wait(ECE.elementToBeClickable(templateButton), 1000);
templateButton.click();
};

this.getGroup = function(group: number) {
Expand Down Expand Up @@ -992,6 +999,17 @@ class Monitoring {
this.getPackageItemLabel = function(index) {
return element.all(by.id('package-item-label')).get(index);
};

this.createItem = (buttonText: string) => {
const plusButton = el(['content-create']);
const itemButton = el(['content-create-dropdown']).element(by.buttonText(buttonText));

browser.wait(ECE.elementToBeClickable(plusButton), 2000);
plusButton.click();

browser.wait(ECE.elementToBeClickable(itemButton), 2000, `Button '${buttonText}' is not clickable`);
itemButton.click();
};
}
}

Expand Down
2 changes: 2 additions & 0 deletions e2e/client/specs/helpers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class GlobalSearch {
this.itemClick = function(index) {
var itemElem = this.getItem(index);

browser.wait(ECE.elementToBeClickable(itemElem), 1000);

itemElem.click();

browser.wait(ECE.attributeContains(itemElem, 'class', 'active'), 2000);
Expand Down
3 changes: 1 addition & 2 deletions e2e/client/specs/monitoring_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ describe('monitoring', () => {
it('can start content upload', () => {
monitoring.openMonitoring();

el(['content-create']).click();
el(['content-create-dropdown', 'upload-media']).click();
monitoring.createItem('Upload media');

expect(monitoring.uploadModal.isDisplayed()).toBeTruthy();
});
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"sass-loader": "6.0.6",
"shortid": "2.2.8",
"style-loader": "0.20.2",
"superdesk-ui-framework": "^3.1.15",
"superdesk-ui-framework": "^3.1.17",
"ts-loader": "3.5.0",
"typescript": "4.9.5",
"uuid": "8.3.1",
Expand Down Expand Up @@ -163,7 +163,7 @@
"test": "npm run lint && npm run unit && node tasks/verify-client-api-changes.js",
"debug-unit-tests": "karma start --reporters=progress --browsers=Chrome",
"unit": "karma start --single-run",
"lint": "tsc -p scripts --noEmit && eslint --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks",
"lint": "tsc -p scripts --noEmit && eslint --quiet --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks",
"lint-fix": "eslint --fix --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts e2e/client tasks",
"server": "grunt server",
"dev": "npm run server"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/* eslint-disable react/no-multi-comp */
import React from 'react';
import {IArticleSideWidget, IComment, IExtensionActivationResult, IRestApiResponse} from 'superdesk-api';
import {IArticleSideWidget, IArticleSideWidgetComponentType, IComment, IRestApiResponse} from 'superdesk-api';
import {gettext} from 'core/utils';
import CommentsWidget from '../../generic-widgets/comments/CommentsWidget';
import {httpRequestJsonLocal} from 'core/helpers/network';
// Can't call `gettext` in the top level
const getLabel = () => gettext('Comments');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

class Component extends React.PureComponent<IProps> {
class Component extends React.PureComponent<IArticleSideWidgetComponentType> {
render() {
return (
<CommentsWidget
initialState={this.props.initialState}
entityId={this.props.article._id}
readOnly={this.props.readOnly}
contentProfile={this.props.contentProfile}
Expand Down
12 changes: 5 additions & 7 deletions scripts/apps/authoring-react/article-widgets/demo-widget.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {IArticleSideWidget, IArticle, IExtensionActivationResult} from 'superdesk-api';
import {IArticleSideWidget, IArticleSideWidgetComponentType} from 'superdesk-api';
import {Button} from 'superdesk-ui-framework';
import {sdApi} from 'api';
import {gettext} from 'core/utils';
Expand All @@ -8,17 +8,15 @@ import {AuthoringWidgetLayout} from 'apps/dashboard/widget-layout';

// Can't call `gettext` in the top level
const getLabel = () => gettext('Demo widget');
const DEMO_WIDGET_ID = 'demo-widget';

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

class DemoWidget extends React.PureComponent<IProps> {
class DemoWidget extends React.PureComponent<IArticleSideWidgetComponentType> {
render() {
return (
<AuthoringWidgetLayout
header={(
<AuthoringWidgetHeading
widgetId={DEMO_WIDGET_ID}
widgetName={getLabel()}
editMode={false}
/>
Expand Down Expand Up @@ -47,7 +45,7 @@ class DemoWidget extends React.PureComponent<IProps> {

export function getDemoWidget() {
const metadataWidget: IArticleSideWidget = {
_id: 'demo-widget',
_id: DEMO_WIDGET_ID,
label: getLabel(),
order: 2,
icon: 'info',
Expand Down
Loading

0 comments on commit 1e8cb3a

Please sign in to comment.