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

Cypress tests #69

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
61 changes: 61 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Bump version in PR

on: [pull_request]

jobs:
# If pull request was merged then we should check for a package version update
check-version-update:
runs-on: ubuntu-latest
steps:
# Checkout to target branch
- uses: actions/checkout@v2
with:
fetch-depth: 0

# Get package new version name
- name: Get package info
id: packageNew
uses: codex-team/action-nodejs-package-info@v1

# Checkout to the base commit before merge
- name: Checkout to the base commit before merge
run: git checkout ${{ github.event.pull_request.base.sha }}

# Get package old version name
- name: Get package info
id: packageOld
uses: codex-team/action-nodejs-package-info@v1

# Stop workflow and do not bump version if it was changed already
- name: Stop workflow and do not bump version if it was changed already
uses: andymckay/cancel-action@0.2
if: steps.packageOld.outputs.version != steps.packageNew.outputs.version

bump-version:
needs: check-version-update
runs-on: ubuntu-latest
steps:
# Checkout to target branch
- uses: actions/checkout@v2

# Setup node environment
- uses: actions/setup-node@v1
with:
node-version: 15
registry-url: https://registry.npmjs.org/

# Bump version to the next prerelease (patch) with rc suffix
- name: Suggest the new version
run: yarn version --patch --no-git-tag-version

# Get package new version name
- name: Get package info
id: package
uses: codex-team/action-nodejs-package-info@v1

# Commit version upgrade
- uses: EndBug/add-and-commit@v7
with:
author_name: github-actions
author_email: 41898282+github-actions[bot]@users.noreply.github.com
message: "Bump version up to ${{ steps.package.outputs.version }}"
37 changes: 37 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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
- uses: cypress-io/github-action@v2
with:
config: video=false
browser: firefox
build: yarn build

chrome:
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v2
- uses: cypress-io/github-action@v2
with:
config: video=false
browser: chrome
build: yarn build

edge:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: cypress-io/github-action@v2
with:
config: video=false
browser: edge
build: yarn build
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions cypress/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
10 changes: 10 additions & 0 deletions cypress/fixtures/editor-config-empty-block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"blocks": [
{
"type": "header",
"data": {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"data": {}
"data": {
"text": "",
"level": 2
}

}
]
}
}
13 changes: 13 additions & 0 deletions cypress/fixtures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Header Tool</title>
</head>
<body>
<div id="editorjs" data-cy="editorjs"></div>

<script src="../../node_modules/@editorjs/editorjs/dist/editor.js"></script>
<script src="../../dist/bundle.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions cypress/integration/header.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {EditorConfig} from "@editorjs/editorjs";

describe('Header', () => {
beforeEach(function () {
/**
* Init editor with an empty header block
*/
cy.fixture('editor-config-empty-block')
.then(editorConfig => {
cy.initEditor(editorConfig).as('EditorJS');
})
})

it('should type into block', () => {
const headerContent = 'CodeX Team';

cy.getBlock()
.type(headerContent)
.should('contain', headerContent);
});
});
61 changes: 61 additions & 0 deletions cypress/integration/saving.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import EditorJS, {OutputData} from "@editorjs/editorjs";

describe('Saving', () => {
beforeEach(function () {
/**
* Init editor with an empty header block
*/
cy.fixture('editor-config-empty-block')
.then(editorConfig => {
cy.initEditor(editorConfig).as('EditorJS');
});
})

it('should save correct type', function () {
const headerContent = 'CodeX Team';

cy.getBlock()
.type(headerContent);

cy.get<EditorJS>('@EditorJS')
.then(editor => {
editor.save()
.then((data: OutputData) => {
console.log(data);
expect(data.blocks[0].type).to.eq('header');
});
})
});

it('should save correct data', function () {
const headerContent = 'CodeX Team';

cy.getBlock()
.type(headerContent);

cy.get<EditorJS>('@EditorJS')
.then(editor => {
editor.save()
.then((data: OutputData) => {
console.log(data);
expect(data.blocks[0].data.text).to.eq(headerContent);
});
})
});

it('should save correct level', function () {
const headerContent = 'CodeX Team';

cy.getBlock()
.type(headerContent);

cy.get<EditorJS>('@EditorJS')
.then(editor => {
editor.save()
.then((data: OutputData) => {
console.log(data);
expect(data.blocks[0].data.level).to.eq(2);
});
})
});
});
33 changes: 33 additions & 0 deletions cypress/integration/toolbox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe('Toolbox icon', () => {
beforeEach(function () {
cy.initEditor().as('EditorJS');
})

it('should render default icon', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

this test is not related to the Header tool, but to the Editor core

cy.getBlock();

cy.getEditor()
.find('div.ce-toolbar__plus')
.click();

cy.getEditor()
.find('li.ce-toolbox__button[data-tool=header]')
.should('exist');
});

it('should render block on click on toolbox icon', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

same

cy.getBlock();

cy.getEditor()
.find('div.ce-toolbar__plus')
.click();

cy.getEditor()
.find('li.ce-toolbox__button[data-tool=header]')
.click()

cy.getEditor()
.find('.ce-header')
.should('exist');
});
});
28 changes: 28 additions & 0 deletions cypress/integration/tunes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {EditorConfig} from "@editorjs/editorjs";

describe('Tunes', () => {
context('with default configuration', function () {
beforeEach(function () {
/**
* Init editor with an empty header block
*/
cy.fixture('editor-config-empty-block')
.then(editorConfig => {
cy.initEditor(editorConfig).as('EditorJS');
})

cy.getBlock()
.openTunes();
})

it('render default items');

it('tune click updates header level');

it('tune click updates header level and tune icon highlights');
})

context('with user configuration', function () {

})
});
19 changes: 19 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.test.ts can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

// eslint-disable-next-line no-unused-vars
module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfig) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Loading