Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port embed test to playwright #4440

Merged
merged 20 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions e2e/client/playwright/editor3.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {test, expect} from '@playwright/test';
import {Monitoring} from './page-object-models/monitoring';
import {restoreDatabaseSnapshot, s} from './utils';
import {appConfig} from 'scripts/appConfig';

test('can add embeds', async ({page}) => {
await restoreDatabaseSnapshot();

const monitoring = new Monitoring(page);

const requestRoute = 'https://sourcefabric.org';

await page.route(
`https://iframe.ly/api/oembed?callback=?&url=
${requestRoute}
&api_key=${appConfig.iframely.key}
&omit_script=true&iframe=true`,
(route) => {
route.fulfill({
body: JSON.stringify([{
title: 'Open Source Software for Journalism',
// eslint-disable-next-line max-len
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
description: 'Sourcefabric is Europe\'s largest developer of '
+ 'open source tools for news media, powering news and media organisations around the world.',
}]),
});
},
);
await page.goto('/#/workspace/monitoring');

await monitoring.selectDesk('Sports');

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

await page.getByRole('button', {name: 'Embed'}).click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a more specific selector


await page.getByPlaceholder('Enter URL or code to embed').type('https://sourcefabric.org');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a more specific selector


await page.locator(s('embed-controls', 'submit')).click();
await expect(
page.locator(s('authoring', 'authoring-field=body_html')).getByText('https://sourcefabric.org'),
).toBeDefined();
});
90 changes: 18 additions & 72 deletions package-lock.json

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

14 changes: 9 additions & 5 deletions scripts/core/editor3/components/embeds/EmbedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ export class EmbedInputComponent extends React.Component<IProps, any> {
}

getEmbedObject(value)
.then((data) => data.type === 'link' ? $.Deferred().reject() : data)
.then(this.processSuccess, this.processError);
.then((data) => {
this.processSuccess(data);
})
.catch((error) => {
this.processError(error);
});
}

/**
Expand Down Expand Up @@ -154,11 +158,11 @@ export class EmbedInputComponent extends React.Component<IProps, any> {
}}
placeholder={gettext('Enter URL or code to embed')}
/>
<div className="input-controls">
<a className="icn-btn" onClick={this.onSubmit}>
<div data-test-id="embed-controls" className="input-controls">
<a role="button" data-test-id="submit" className="icn-btn" onClick={this.onSubmit}>
<i className="icon-ok" />
</a>
<a className="icn-btn" onClick={this.onCancel}>
<a role="button" data-test-id="cancel" className="icn-btn" onClick={this.onCancel}>
<i className="icon-close-small" />
</a>
</div>
Expand Down
22 changes: 0 additions & 22 deletions scripts/core/editor3/components/tests/embeds.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,4 @@ describe('editor3.components.embed-input', () => {
expect(wrapper.state('error')).toBe('this is the error');
expect(wrapper.find('.embed-dialog__error').text()).toBe('this is the error');
}));

it('should call onSubmit and reset error on success', inject(($q, $rootScope) => {
const {options} = mockStore();
const onCancel = jasmine.createSpy();
const onSubmit = jasmine.createSpy();
const wrapper = mount(<EmbedInput embed={onSubmit} hidePopups={onCancel} />, options);

spyOn($, 'ajax').and.returnValue($q.resolve({html: 'foo'}));

wrapper.setState({error: 'some error'});

const instance: any = wrapper.find('input').instance();

instance.value = 'http://will.fail';
wrapper.simulate('submit');

$rootScope.$apply();

expect(onSubmit).toHaveBeenCalledWith({html: 'foo'});
expect(onCancel).toHaveBeenCalled();
expect(wrapper.state('error')).toBe('');
}));
});
4 changes: 3 additions & 1 deletion scripts/core/editor3/components/toolbar/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ interface IProps {
export const IconButton: React.FunctionComponent<IProps> = ({onClick, iconName, tooltip, uiTheme}) => (
<div
data-flow={'down'}
data-test-id="icon-button"
data-test-value={tooltip}
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
data-sd-tooltip={tooltip}
className="Editor3-styleButton"
style={uiTheme == null ? undefined : {color: uiTheme.textColor}}
>
<span onClick={onClick}><i className={`icon-${iconName}`} /></span>
<span role="button" onClick={onClick}><i className={`icon-${iconName}`} /></span>
</div>
);