Skip to content

Commit 2b93bfe

Browse files
committed
[CHORE] Add cypress
1 parent 7053e9f commit 2b93bfe

File tree

11 files changed

+987
-33
lines changed

11 files changed

+987
-33
lines changed

.eslintrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ module.exports = {
5252
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
5353
// add your custom rules and overrides for node files here
5454
})
55+
}, { // cypress
56+
files: ['cypress/integration/**/*.js'],
57+
env: {
58+
'cypress/globals': true,
59+
},
60+
extends: ['plugin:cypress/recommended']
5561
}
5662
]
5763
};

cypress.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cypress/integration/drag_drop.spec.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
describe('Ember SortableJS ', function() {
2+
it('renders a list', function() {
3+
const initial = ['one', 'two', 'three', 'four', 'five'];
4+
5+
cy.visit('http://localhost:4200/simple');
6+
7+
cy
8+
.get('div[data-list-item]')
9+
.should(($divs) => {
10+
expect($divs).to.have.length(5);
11+
12+
const renderedList = $divs.map((i, el) => el.innerText);
13+
14+
expect(renderedList.get()).to.deep.eq(initial);
15+
});
16+
});
17+
18+
it('reorders as list from top to bottom', function() {
19+
const sorted = ['two', 'three', 'four', 'five', 'one'];
20+
21+
cy.visit('http://localhost:4200/simple');
22+
cy.get('div[data-list-item="0"').drag('div[data-list-item="4"', { force: true, position: 'bottom' })
23+
24+
cy
25+
.get('div[data-list-item]')
26+
.should(($divs) => {
27+
expect($divs).to.have.length(5);
28+
29+
const renderedList = $divs.map((i, el) => el.innerText);
30+
31+
expect(renderedList.get()).to.deep.eq(sorted);
32+
});
33+
});
34+
35+
it('reorders a list bottom to top', function() {
36+
const sorted = ['five', 'one', 'two', 'three', 'four'];
37+
38+
cy.visit('http://localhost:4200/simple');
39+
cy.get('div[data-list-item="4"').drag('div[data-list-item="0"', { force: true, position: 'center' })
40+
41+
cy
42+
.get('div[data-list-item]')
43+
.should(($divs) => {
44+
expect($divs).to.have.length(5);
45+
46+
const renderedList = $divs.map((i, el) => el.innerText);
47+
48+
expect(renderedList.get()).to.deep.eq(sorted);
49+
});
50+
});
51+
52+
it('adds an item from one list to another', function() {
53+
cy.visit('http://localhost:4200/shared');
54+
cy.get('.list-a > div[data-list-item="0"').drag('.list-b > div[data-list-item="1"', { force: true, position: 'top' });
55+
56+
const listA = ['Jaden', 'Gustavo'];
57+
const listB = ['Lance', 'Luis', 'Britni', 'Kelly'];
58+
59+
cy
60+
.get('.list-a > div[data-list-item]')
61+
.should(($divs) => {
62+
expect($divs).to.have.length(2);
63+
64+
const renderedList = $divs.map((i, el) => el.innerText);
65+
66+
expect(renderedList.get()).to.deep.eq(listA);
67+
});
68+
69+
cy
70+
.get('.list-b > div[data-list-item]')
71+
.should(($divs) => {
72+
expect($divs).to.have.length(4);
73+
74+
const renderedList = $divs.map((i, el) => el.innerText);
75+
76+
expect(renderedList.get()).to.deep.eq(listB);
77+
});
78+
});
79+
});

cypress/plugins/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
module.exports = (on, config) => {
19+
// `on` is used to hook into various events Cypress emits
20+
// `config` is the resolved Cypress config
21+
}

cypress/support/commands.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
26+
27+
require('@4tw/cypress-drag-drop')

cypress/support/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)