-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic initialisation test for Editor.js (#1410)
* Initial commit * Fixed test.html file * Create editor instance in the test * Assert paragraph data in editor instance * Moving cypress folder to test folder * Minor Fixes * Removed config test for now * Fixed example.html * Fixed editor.js dist path * Minor Fixes * Stored Host in a const * Add nodemon and Fix commands * Add and configure cypress eslint plugin * Updated Tests according to best practices * Minor FIxes * Minor FIxes * adjust eslint and ts * Update .eslintrc * improve config * debug tests * fix tests * Fix declarations * descrease debounce * rm timeout * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Peter Savchenko <[email protected]> Co-authored-by: George Berezhnoy <[email protected]>
- Loading branch information
1 parent
f440a60
commit 585e01b
Showing
15 changed files
with
1,152 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ node_modules/* | |
|
||
npm-debug.log | ||
yarn-error.log | ||
|
||
test/cypress/screenshots | ||
test/cypress/videos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"lib": ["es2017", "dom"], | ||
"types": ["cypress"] | ||
}, | ||
"include": [ | ||
"**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.