Skip to content

Commit 56532f9

Browse files
committed
Add cypress tests
1 parent 722fb61 commit 56532f9

File tree

13 files changed

+3327
-574
lines changed

13 files changed

+3327
-574
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"root": true,
23
"rules": {
34
"strict": 0,
45
"no-console": 0,

.github/workflows/cd.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ jobs:
3737
- name: Test
3838
run: npm test
3939

40+
- uses: actions/upload-artifact@v2
41+
if: failure()
42+
with:
43+
name: cypress-screenshots
44+
path: cypress/screenshots
45+
retention-days: 7
46+
47+
- uses: actions/upload-artifact@v2
48+
if: always()
49+
with:
50+
name: cypress-videos
51+
path: cypress/videos
52+
retention-days: 7
53+
4054
deploy:
4155

4256
needs: [ test ]

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ node_modules/
1111
.idea/
1212
.vscode/
1313
dev_test/
14+
15+
# Test artifacts
16+
cypress/screenshots
17+
cypress/videos

cypress.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ignoreTestFiles": [
3+
"**/*.html"
4+
]
5+
}

cypress/.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"plugins": [
3+
"cypress"
4+
],
5+
"env": {
6+
"node": true,
7+
"es6": true,
8+
"cypress/globals": true
9+
},
10+
"extends": [
11+
"../.eslintrc",
12+
"plugin:cypress/recommended"
13+
]
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Default</title>
7+
<link rel="stylesheet" href="../../../dist/easymde.min.css">
8+
<script src="../../../dist/easymde.min.js"></script>
9+
</head>
10+
11+
<body>
12+
<textarea id="textarea"></textarea>
13+
<script>
14+
const easyMDE = new EasyMDE();
15+
</script>
16+
</body>
17+
18+
</html>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Default statusbar', () => {
4+
beforeEach(() => {
5+
cy.visit(__dirname + '/default.html');
6+
});
7+
8+
it('loads the editor with default statusbar', () => {
9+
cy.get('.EasyMDEContainer').should('be.visible');
10+
cy.get('.EasyMDEContainer .editor-statusbar').should('be.visible');
11+
12+
cy.get('.EasyMDEContainer .editor-statusbar .autosave').should('be.empty');
13+
14+
cy.get('.EasyMDEContainer .editor-statusbar .lines').before('content').should('contain', 'lines: ');
15+
cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '1');
16+
17+
cy.get('.EasyMDEContainer .editor-statusbar .words').before('content').should('contain', 'words: ');
18+
cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '0');
19+
20+
cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '1:1');
21+
});
22+
23+
it('updates the statusbar when typing', () => {
24+
cy.get('.EasyMDEContainer').should('be.visible');
25+
cy.get('.EasyMDEContainer .editor-statusbar').should('be.visible');
26+
27+
cy.get('.EasyMDEContainer .CodeMirror').type('Hello');
28+
29+
cy.get('.EasyMDEContainer .editor-statusbar .autosave').should('be.empty');
30+
31+
cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '1');
32+
cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '1');
33+
cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '1:6');
34+
35+
cy.get('.EasyMDEContainer .CodeMirror').type(' World');
36+
37+
cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '1');
38+
cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '2');
39+
cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '1:12');
40+
41+
cy.get('.EasyMDEContainer .CodeMirror').type('{enter}');
42+
43+
cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '2');
44+
cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '2');
45+
cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '2:1');
46+
47+
cy.get('.EasyMDEContainer .CodeMirror').type('This is a sample text.{enter}We\'re testing the statusbar.{enter}Did it work?');
48+
49+
cy.get('.EasyMDEContainer .editor-statusbar .autosave').should('be.empty');
50+
cy.get('.EasyMDEContainer .editor-statusbar .lines').before('content').should('contain', 'lines: ');
51+
cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '4');
52+
cy.get('.EasyMDEContainer .editor-statusbar .words').before('content').should('contain', 'words: ');
53+
cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '15');
54+
cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '4:13');
55+
});
56+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Default editor', () => {
4+
beforeEach(() => {
5+
cy.visit(__dirname + '/default.html');
6+
});
7+
8+
it('Loads the editor with default settings', () => {
9+
cy.get('.EasyMDEContainer').should('be.visible');
10+
cy.get('#textarea').should('not.be.visible');
11+
12+
cy.get('.EasyMDEContainer .editor-toolbar').should('be.visible');
13+
cy.get('.EasyMDEContainer .CodeMirror').should('be.visible');
14+
cy.get('.EasyMDEContainer .editor-preview').should('not.be.visible');
15+
cy.get('.EasyMDEContainer .editor-statusbar').should('be.visible');
16+
});
17+
});

cypress/plugins/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference types="cypress" />
2+
3+
/**
4+
* @type {Cypress.PluginConfig}
5+
*/
6+
// eslint-disable-next-line no-unused-vars
7+
module.exports = (on, config) => {
8+
// `on` is used to hook into various events Cypress emits
9+
// `config` is the resolved Cypress config
10+
};

cypress/support/commands.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types="cypress" />
2+
3+
const unquote = (str) => str.replace(/(^")|("$)/g, '');
4+
5+
Cypress.Commands.add(
6+
'before',
7+
{
8+
prevSubject: 'element',
9+
},
10+
(element, property) => {
11+
const win = element[0].ownerDocument.defaultView;
12+
const before = win.getComputedStyle(element[0], 'before');
13+
return unquote(before.getPropertyValue(property));
14+
},
15+
);

0 commit comments

Comments
 (0)