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

Basic initialisation test for Editor.js #1410

Merged
merged 28 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Temporary suppress some errors. We need to fix them partially in next patches
*/
"import/no-duplicates": ["warn"],
"@typescript-eslint/triple-slash-reference": ["off"]
},
"settings": {
"jsdoc": {
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ node_modules/*

npm-debug.log
yarn-error.log

test/cypress/screenshots
test/cypress/videos
11 changes: 11 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"projectId": "tivr7e",
"env": {
},
"fixturesFolder": "test/cypress/fixtures",
"integrationFolder": "test/cypress/tests",
"pluginsFile": "test/cypress/plugins/index.ts",
"screenshotsFolder": "test/cypress/screenshots",
"videosFolder": "test/cypress/videos",
"supportFile": "test/cypress/support/index.ts"
}
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### 2.19.1

- `Improvements` - The [Cypress](https://www.cypress.io) was integrated as the end-to-end testing framework
- `Fix` - The problem with destroy() method [#1380](https://github.com/codex-team/editor.js/issues/1380).
- `Fix` - add getter keyword to `block.mergeable` method [#1415](https://github.com/codex-team/editor.js/issues/1415).
- `Fix` — Fix problem with entering to Editor.js by Tab key [#1393](https://github.com/codex-team/editor.js/issues/1393)
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"build:win": "rimraf dist && yarn svg:win && yarn build:prod",
"build:dev": "webpack --mode development --progress --display-error-details --display-entrypoints --watch",
"build:prod": "webpack --mode production",
"lint": "eslint src/ --ext .ts",
"lint": "eslint src/ --ext .ts && yarn lint:tests",
"lint:errors": "eslint src/ --ext .ts --quiet",
"lint:fix": "eslint src/ --ext .ts --fix",
"lint:tests": "eslint test/ --ext .ts",
"svg:win": "if not exist dist md dist && yarn svg",
"svg": "svg-sprite-generate -d src/assets/ -o dist/sprite.svg",
"pull_tools": "git submodule update --init --recursive",
"checkout_tools": "git submodule foreach git pull origin master"
"checkout_tools": "git submodule foreach git pull origin master",
"test:e2e": "cypress open"
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
"test:e2e": "cypress open"
"test:e2e": "cypress run",
"cypress:open": "cypress open"

cypress open: Open cypress GUI window.
cypress run: Run cypress test in CUI.

},
"author": "CodeX",
"license": "Apache-2.0",
Expand All @@ -46,9 +48,11 @@
"core-js": "3.6.5",
"css-loader": "^3.5.3",
"cssnano": "^4.1.10",
"cypress": "^5.5.0",
"eslint": "^6.8.0",
"eslint-config-codex": "^1.3.3",
"eslint-loader": "^4.0.2",
"eslint-plugin-cypress": "^2.11.2",
"extract-text-webpack-plugin": "^3.0.2",
"html-janitor": "^2.0.4",
"license-webpack-plugin": "^2.1.4",
Expand Down
17 changes: 17 additions & 0 deletions test/cypress/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"plugins": [
"cypress"
],
"env": {
"cypress/globals": true
},
"extends": [
"plugin:cypress/recommended"
],
"rules": {
"cypress/require-data-selectors": 2
},
"globals": {
"EditorJS": true
}
}
8 changes: 8 additions & 0 deletions test/cypress/fixtures/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<body>
<!-- Load Editor.js's Core -->
<script src="./../../../dist/editor.js"></script>
<h1>Editor.js test page</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions test/cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* This file contains connection of Cypres plugins
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
export default function(on, config): void {}
38 changes: 38 additions & 0 deletions test/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* This file contains custom commands for Cypress.
* Also it can override the existing commands.
*
* --------------------------------------------------
*/

import type { EditorConfig } from './../../../types/index';
import type EditorJS from '../../../types/index';
import Chainable = Cypress.Chainable;

/**
* Create a wrapper and initialize the new instance of editor.js
* Then return the instance
*
* @param editorConfig - config to pass to the editor
* @returns EditorJS - created instance
*/
Cypress.Commands.add('createEditor', (editorConfig: EditorConfig = {}): Chainable<EditorJS> => {
return cy.window()
.then((window) => {
return new Promise((resolve: (instance: EditorJS) => void) => {
const editorContainer = window.document.createElement('div');

editorContainer.setAttribute('id', 'editorjs');
editorContainer.dataset.cy = 'editorjs';
editorContainer.style.border = '1px dotted #388AE5';

window.document.body.appendChild(editorContainer);

const editorInstance: EditorJS = new window.EditorJS(editorConfig);

editorInstance.isReady.then(() => {
resolve(editorInstance);
});
});
});
});
23 changes: 23 additions & 0 deletions test/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// in cypress/support/index.d.ts
// load type definitions that come with Cypress module
/// <reference types="cypress" />

import type { EditorConfig } from './../../../types/index';
import type EditorJS from '../../../types/index'

declare global {
namespace Cypress {
interface Chainable<Subject = any> {
/**
* Custom command to select DOM element by data-cy attribute.
* @param editorConfig - config to pass to the editor
* @example cy.createEditor({})
*/
createEditor(editorConfig: EditorConfig): Chainable<EditorJS>
}

interface ApplicationWindow {
EditorJS: typeof EditorJS
}
}
}
19 changes: 19 additions & 0 deletions test/cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This file is processed and
* loaded automatically before the test files.
*
* This is a great place to put global configuration and
* behavior that modifies Cypress.
*/

/**
* File with the helpful commands
*/
import './commands';

/**
* Before-each hook for the cypress tests
*/
beforeEach((): void => {
cy.visit('test/cypress/fixtures/test.html');
});
30 changes: 30 additions & 0 deletions test/cypress/tests/initialization.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// eslint-disable-next-line spaced-comment
/// <reference path="../support/index.d.ts" />

describe('Editor basic initialization', () => {
describe('Zero-config initialization', () => {
/**
* In this test suite we use zero (omitted) configuration
*/
const editorConfig = {};

beforeEach(() => {
if (this.editorInstance) {
this.editorInstance.destroy();
} else {
cy.createEditor(editorConfig).as('editorInstance');
}
});

it('should create a visible UI', () => {
cy.window().then((window) => {
/**
* Assert if created instance is visible or not.
*/
cy.get('[data-cy=editorjs]')
.get('div.codex-editor')
.should('be.visible');
});
});
});
});
10 changes: 10 additions & 0 deletions test/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2017",
"lib": ["es2017", "dom"],
"types": ["cypress"]
},
"include": [
"**/*.ts"
]
}
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"no-string-literal": false,
"no-empty": false,
"no-namespace": false,
"variable-name": [true, "allow-leading-underscore", "allow-pascal-case"]
"variable-name": [true, "allow-leading-underscore", "allow-pascal-case"],
"no-reference": false
},
"globals": {
"require": true
Expand Down
Loading