Latest updates from IceHrmPro

This commit is contained in:
Thilina Pituwala
2020-05-20 18:47:29 +02:00
parent 60c92d7935
commit 7453a58aad
18012 changed files with 2089245 additions and 10173 deletions

5
test/frontend/.eslintrc Normal file
View File

@@ -0,0 +1,5 @@
// Use this file as a starting point for your project's .eslintrc.
// Copy this file, and add rule overrides as needed.
{
"extends": "airbnb"
}

View File

@@ -0,0 +1,4 @@
{
"viewportWidth": 1280,
"viewportHeight": 1024
}

View File

@@ -0,0 +1,112 @@
const config = require('../support/config');
class IceCypressTest {
constructor(moduleUrl, element, isRemoteTable) {
this.moduleUrl = moduleUrl;
this.element = element;
this.isRemoteTable = isRemoteTable;
this.titleDataAttributeName = 'data-original-title';
if (isRemoteTable) {
this.titleDataAttributeName = 'title';
}
}
loadTable(cy, count = config.DEFAULT_MAX_PAGE_SIZE) {
cy.get(`#${this.element} table tbody`).find('tr')
.its('length').should('eq', count);
}
viewElement(cy, viewButtonSelector = null) {
cy.server().route('GET', `/${config.URL_PREFIX}/service.php*`).as('getElement');
cy.get(`#${this.element} table tbody`).find('tr').first()
.find(viewButtonSelector || `.center div img[${this.titleDataAttributeName}='View']`)
.click();
cy.wait('@getElement').its('status').should('be', config.DEFAULT_WAIT_TIME);
}
viewElementValidate(cy, validation = []) {
validation.forEach((rule) => {
cy.get(rule[0]).then(element => expect(element.text()).eq(rule[1]));
});
}
editElement(cy, update, editButtonSelector = null) {
cy.server().route('POST', `/${config.URL_PREFIX}/service.php*`).as('getElement');
cy.get(`#${this.element} table tbody`).find('tr').first().find(editButtonSelector || `.center div img[${this.titleDataAttributeName}='Edit']`)
.click();
cy.wait('@getElement').its('status').should('be', config.DEFAULT_WAIT_TIME);
update.forEach((item) => {
cy.get(item[0]).clear().type(item[1]).should('have.value', item[1]);
});
}
select2Click(id, value) {
cy.get(`#s2id_${id}`).click();
cy.focused().clear().type(value).should('have.value', value);
cy.get('.select2-drop:visible').find('.select2-results li').first()
.click();
}
clickSave(cy) {
cy.get(`#${this.element}Form .saveBtn`).click();
}
editElementValidate(cy, validation = [], editButtonSelector) {
if (this.isRemoteTable) {
cy.server().route('GET', `/${config.URL_PREFIX}/data.php*`).as('getAfterSave');
} else {
cy.server().route('POST', `/${config.URL_PREFIX}/service.php*`).as('getAfterSave');
}
// Wait for data table response
cy.wait('@getAfterSave').its('status').should('be', config.DEFAULT_WAIT_TIME);
cy.server().route('POST', `/${config.URL_PREFIX}/service.php*`).as('getElementAfterSave');
// Click on edit and wait
cy.get(`#${this.element} table tbody`).find('tr').first().find(editButtonSelector || `.center div img[${this.titleDataAttributeName}='Edit']`)
.click();
cy.wait('@getElementAfterSave').its('status').should('be', config.DEFAULT_WAIT_TIME);
validation.forEach((item) => {
cy.get(item[0]).then(element => expect(element.val()).eq(item[1]));
});
}
canNotEditElement(cy, editButtonSelector = null) {
cy.get(`#${this.element} table tbody`).find('tr')
.first().find(editButtonSelector || ".center div img[title='Edit']")
.should('not.exist');
}
loadModule(cy) {
// Request to watch and wait
if (this.isRemoteTable) {
cy.server().route('GET', `/${config.URL_PREFIX}/data.php*`).as('get');
} else {
cy.server().route('POST', `/${config.URL_PREFIX}/service.php*`).as('get');
}
// Visit module
cy.visit(`${config.BASE_URL}?${this.moduleUrl}`);
// Wait for data table response
cy.wait('@get').its('status').should('be', config.DEFAULT_WAIT_TIME);
}
switchTab(cy, tabName = null) {
if (this.isRemoteTable) {
cy.server().route('GET', `/${config.URL_PREFIX}/data.php*`).as('getTab');
} else {
cy.server().route('POST', `/${config.URL_PREFIX}/service.php*`).as('getTab');
}
cy.get(tabName || `#tab${this.element}`).click();
cy.wait('@getTab').its('status').should('be', config.DEFAULT_WAIT_TIME);
}
}
module.exports = IceCypressTest;

View File

@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@@ -0,0 +1,5 @@
context('Reset DB', () => {
it('resets DB', () => {
cy.resetDatabase();
});
});

View File

@@ -0,0 +1,36 @@
const IceCypressTest = require('../../commmon/ice-cypress-test');
const config = require('../../support/config');
const test = new IceCypressTest(
'g=admin&n=company_structure&m=admin_Admin',
'CompanyStructure',
);
context('Admin Company Structure Module - Company Structure Tab', () => {
it('admin can view list', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.loadTable(cy, 9);
});
it('admin can edit element', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.editElement(cy, [['#address', 'Address 1']]);
test.clickSave(cy);
test.editElementValidate(cy, [['#address', 'Address 1']]);
});
it('manager can view list', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.loadTable(cy, 9);
});
it('manager can not edit element', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.canNotEditElement(cy);
});
});

View File

@@ -0,0 +1,27 @@
const IceCypressTest = require('../../commmon/ice-cypress-test');
const test = new IceCypressTest(
'g=admin&n=employees&m=admin_Employees',
'EmployeeSkill',
true,
);
context('Admin Employee Module - Skills Tab', () => {
it('admin can view list', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.switchTab(cy);
test.loadTable(cy, 2);
});
it('admin can edit element', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.switchTab(cy);
test.editElement(cy, [['#details', 'Employee skill']]);
test.select2Click('skill_id', 'Networking');
test.clickSave(cy);
test.editElementValidate(cy, [['#details', 'Employee skill']]);
});
});

View File

@@ -0,0 +1,53 @@
const IceCypressTest = require('../../commmon/ice-cypress-test');
const config = require('../../support/config');
const test = new IceCypressTest(
'g=admin&n=employees&m=admin_Employees',
'Employee',
true,
);
context('Admin Employee Module - Employee Tab', () => {
it('admin can view list', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.loadTable(cy);
});
it('admin can view element', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.viewElement(cy);
test.viewElementValidate(cy, [['#name', 'IceHrm Employee']]);
});
it('admin can edit element', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.editElement(cy, [['#middle_name', 'Middle Name']]);
test.clickSave(cy);
test.editElementValidate(cy, [['#middle_name', 'Middle Name']]);
});
it('manager can view list', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.loadTable(cy);
});
it('manager can view element', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.viewElement(cy);
test.viewElementValidate(cy, [['#name', 'IceHrm Employee']]);
});
it('manager can edit element', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.editElement(cy, [['#middle_name', 'Middle Name 1']]);
test.clickSave(cy);
test.editElementValidate(cy, [['#middle_name', 'Middle Name 1']]);
});
});

View File

@@ -0,0 +1,44 @@
const IceCypressTest = require('../../commmon/ice-cypress-test');
const config = require('../../support/config');
const test = new IceCypressTest(
'g=admin&n=teams&m=admin_Employees',
'TeamMembers',
false,
);
context('Admin Teams Module - Team Members Tab', () => {
it('admin can view list', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.switchTab(cy);
test.loadTable(cy, 2);
});
it('admin can edit element', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.switchTab(cy);
cy.get('#TeamMembers table tbody').find('tr').first().find('.center div img[data-original-title=\'Edit\']')
.click();
test.select2Click('team', 'beta');
test.clickSave(cy);
});
it('manager can view list', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.switchTab(cy);
test.loadTable(cy, 2);
});
it('manager can edit element', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.switchTab(cy);
cy.get('#TeamMembers table tbody').find('tr').first().find('.center div img[data-original-title=\'Edit\']')
.click();
test.select2Click('team', 'beta');
test.clickSave(cy);
});
});

View File

@@ -0,0 +1,40 @@
const IceCypressTest = require('../../commmon/ice-cypress-test');
const config = require('../../support/config');
const test = new IceCypressTest(
'g=admin&n=teams&m=admin_Employees',
'Teams',
false,
);
context('Admin Teams Module - Teams Tab', () => {
it('admin can view list', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.loadTable(cy, 2);
});
it('admin can edit element', () => {
cy.login('admin', 'admin');
test.loadModule(cy);
test.editElement(cy, [['#description', 'creative designing team']]);
test.select2Click('department', 'Head Office');
test.clickSave(cy);
test.editElementValidate(cy, [['#description', 'creative designing team']]);
});
it('manager can view list', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.loadTable(cy, 2);
});
it('manager can edit element', () => {
cy.login('manager', config.DEFAULT_USER_PASS);
test.loadModule(cy);
test.editElement(cy, [['#description', 'creative designing team']]);
test.select2Click('department', 'Head Office');
test.clickSave(cy);
test.editElementValidate(cy, [['#description', 'creative designing team']]);
});
});

View File

@@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js 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)
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};

View File

@@ -0,0 +1,38 @@
const config = require('./config');
// ***********************************************
// 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 is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add('login', (user, password) => {
cy.visit(`${config.BASE_URL}login.php`);
cy.get('#username').type(user).should('have.value', user);
cy.get('#password').type(password).should('have.value', password);
cy.get('.btn').first().click();
});
Cypress.Commands.add('resetDatabase', () => {
cy.exec('vagrant ssh -c \'cd /vagrant/core/robo; php robo.phar reset:db test; php robo.phar create:tables test; php robo.phar migrate:all test; php robo.phar execute:fixtures test\'');
});

View File

@@ -0,0 +1,13 @@
const BASE_URL = 'http://clients.icehrmpro.test/test/';
const DEFAULT_MAX_PAGE_SIZE = 15;
const DEFAULT_WAIT_TIME = 500;
const DEFAULT_USER_PASS = 'demouserpwd';
const URL_PREFIX = 'test';
module.exports = {
BASE_URL,
DEFAULT_MAX_PAGE_SIZE,
DEFAULT_WAIT_TIME,
DEFAULT_USER_PASS,
URL_PREFIX,
};

View File

@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands';
// Alternatively you can use CommonJS syntax:
// require('./commands')

1751
test/frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
{
"name": "icehrm-frontend-tests",
"version": "0.0.0",
"description": "",
"main": "gulpfile.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"cypress": "^3.4.1",
"eslint-config-airbnb": "^18.0.1"
}
}