Skip to content

Commit

Permalink
Add cypress workflow (#1638)
Browse files Browse the repository at this point in the history
* Add cypress workflow

* Setup different browsers

* Pull tools

* Update ff image

* Fix test

* Adopt tests

* Fix eslint
  • Loading branch information
gohabereg authored Apr 8, 2021
1 parent 3b20c4a commit 2c77edb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Tests
on: [pull_request]
jobs:
firefox:
runs-on: ubuntu-latest
container:
image: cypress/browsers:node14.16.0-chrome89-ff86
options: --user 1001
steps:
- uses: actions/checkout@v2
- run: yarn pull_tools
- uses: cypress-io/github-action@v2
with:
browser: firefox
build: yarn build
chrome:
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v2
- run: yarn pull_tools
- uses: cypress-io/github-action@v2
with:
browser: chrome
build: yarn build
edge:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- run: yarn pull_tools
- uses: cypress-io/github-action@v2
with:
browser: edge
build: yarn build
14 changes: 8 additions & 6 deletions test/cypress/tests/copy-paste.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ describe('Copy pasting from Editor', () => {

context('pasting', () => {
it('should paste plain text', () => {
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.get('[data-cy=editorjs]')
.get('div.ce-block')
.click()
.paste({
'text/plain': 'Some plain text',
})
.wait(0)
.should('contain', 'Some plain text');
});

Expand Down Expand Up @@ -161,7 +163,7 @@ describe('Copy pasting from Editor', () => {
})
.copy()
.then(clipboardData => {
expect(clipboardData['text/html']).to.eq('<p>First block</p><p>Second block</p>');
expect(clipboardData['text/html']).to.match(/<p>First block(<br>)?<\/p><p>Second block(<br>)?<\/p>/);
expect(clipboardData['text/plain']).to.eq(`First block\n\nSecond block`);

/**
Expand All @@ -174,9 +176,9 @@ describe('Copy pasting from Editor', () => {
const data = JSON.parse(clipboardData['application/x-editor-js']);

expect(data[0].tool).to.eq('paragraph');
expect(data[0].data).to.deep.eq({ text: 'First block' });
expect(data[0].data.text).to.match(/First block(<br>)?/);
expect(data[1].tool).to.eq('paragraph');
expect(data[1].data).to.deep.eq({ text: 'Second block' });
expect(data[1].data.text).to.match(/Second block(<br>)?/);
});
});
});
Expand Down Expand Up @@ -214,7 +216,7 @@ describe('Copy pasting from Editor', () => {
})
.cut()
.then(clipboardData => {
expect(clipboardData['text/html']).to.eq('<p>First block</p><p>Second block</p>');
expect(clipboardData['text/html']).to.match(/<p>First block(<br>)?<\/p><p>Second block(<br>)?<\/p>/);
expect(clipboardData['text/plain']).to.eq(`First block\n\nSecond block`);

/**
Expand All @@ -227,9 +229,9 @@ describe('Copy pasting from Editor', () => {
const data = JSON.parse(clipboardData['application/x-editor-js']);

expect(data[0].tool).to.eq('paragraph');
expect(data[0].data).to.deep.eq({ text: 'First block' });
expect(data[0].data.text).to.match(/First block(<br>)?/);
expect(data[1].tool).to.eq('paragraph');
expect(data[1].data).to.deep.eq({ text: 'Second block' });
expect(data[1].data.text).to.match(/Second block(<br>)?/);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/cypress/tests/sanitisation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Output sanitisation', () => {

const text = output.blocks[0].data.text;

expect(text).to.eq('<b>This text should be bold.</b>');
expect(text).to.match(/<b>This text should be bold\.(<br>)?<\/b>/);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/cypress/tests/tools/BlockTool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BlockTool from '../../../../src/components/tools/block';
import InlineTool from '../../../../src/components/tools/inline';
import ToolsCollection from '../../../../src/components/tools/collection';

describe.only('BlockTool', () => {
describe('BlockTool', () => {
/**
* Mock for BlockTool constructor options
*/
Expand Down

0 comments on commit 2c77edb

Please sign in to comment.