Skip to content

Commit

Permalink
Merge branch 'beta' of github.com:SoftwareBrothers/admin-bro into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-krysiak committed Oct 31, 2020
2 parents f108eaa + e5f32db commit f73bd88
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 60 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ module.exports = {
},
},
{
files: ['**/*/cypress/integration/**/*.spec.js'],
files: [
'**/*/cypress/integration/**/*.spec.js',
'./cy/**/*.js',
],
rules: {
'mocha/no-mocha-arrows': 'off',
'spaced-comment': 'off',
Expand Down
14 changes: 14 additions & 0 deletions cy/commands/ab-get-property.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference types="cypress" />

/**
* @method abGetProperty
* @param {string} propertyPath
* @param {string} [selector=null]
*/
Cypress.Commands.add('abGetProperty', (propertyPath, selector = null) => {
let propertySelector = `[data-testid$="-${propertyPath}"]`
if (selector) {
propertySelector = [propertySelector, selector].join(' ')
}
return cy.get(propertySelector)
})
19 changes: 19 additions & 0 deletions cy/commands/ab-keep-logged-in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference types="cypress" />

/**
* @method abKeepLoggedIn
* @param {object} [options]
* @param {object} [options.cookie] session cookie name: default to Cypress.env('AB_COOKIE_NAME')
* @example
* before(() => {
* cy.abLogin()
* })
*
* beforeAll(() => {
* cy.abKeepLoggedIn({ cookie: 'my-session-cookie' })
* cy.visit('your/path')
* })
*/
Cypress.Commands.add('abKeepLoggedIn', ({ cookie }) => {
Cypress.Cookies.preserveOnce(cookie || Cypress.env('AB_COOKIE_NAME'))
})
15 changes: 15 additions & 0 deletions cy/commands/ab-login-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types="cypress" />

/**
* @method abLogin
* @param {object} [options]
* @param {object} [options.email] login email: default to Cypress.env('AB_EMAIL')
* @param {object} [options.password] login password: default to Cypress.env('AB_PASSWORD')
* @param {object} [options.loginPath] default to '/login'
*/
Cypress.Commands.add('abLoginAPI', ({ email, password, loginPath } = {}) => (
cy.request('POST', loginPath || '/login', {
email: email || Cypress.env('AB_EMAIL'),
password: password || Cypress.env('AB_PASSWORD'),
})
))
15 changes: 15 additions & 0 deletions cy/commands/ab-login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types="cypress" />

/**
* @method abLogin
* @param {object} [options]
* @param {object} [options.email] login email: default to Cypress.env('AB_EMAIL')
* @param {object} [options.password] login password: default to Cypress.env('AB_PASSWORD')
* @param {object} [options.loginPath] default to '/login'
*/
Cypress.Commands.add('abLogin', ({ email, password, loginPath } = {}) => {
cy.visit(loginPath || '/login')
cy.get('[name=email]').type(email || Cypress.env('AB_EMAIL'))
cy.get('[name=password]').type(password || Cypress.env('AB_PASSWORD'))
cy.get('button').click()
})
20 changes: 20 additions & 0 deletions cy/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference types="cypress" />

declare namespace Cypress {
type AbLoginParams = {
email?: string;
password?: string;
loginPath?: string;
}

type AbKeepLoggedInParams = {
cookie?: string;
}

interface Chainable<Subject> {
abLogin(params?: AbLoginParams): Chainable<any>;
abLoginAPI(params?: AbLoginParams): Chainable<any>;
abGetProperty(propertyPath: string, selector?: string): Chainable<any>;
abKeepLoggedIn(params?: AbKeepLoggedInParams): Chainable<any>;
}
}
4 changes: 4 additions & 0 deletions cy/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('./commands/ab-login')
require('./commands/ab-login-api')
require('./commands/ab-keep-logged-in')
require('./commands/ab-get-property')
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "admin-bro",
"version": "3.3.0-beta.35",
"version": "3.3.0-beta.36",
"description": "Admin panel for apps written in node.js",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -9,7 +9,7 @@
"types": "tsc",
"clean": "rm -rf lib && mkdir lib && rm -fr types && mkdir types",
"build": "babel src --out-dir lib --copy-files --extensions '.ts,.js,.jsx,.tsx'",
"lint": "eslint './spec/**/*' './src/**/*' './*'",
"lint": "eslint './spec/**/*' './src/**/*' './cy/**/*' './*'",
"cover": "NODE_ENV=test nyc --reporter=lcov --reporter=text-lcov npm test",
"codecov": "NODE_ENV=test nyc --reporter=text-lcov npm test | codecov --pipe",
"bundle": "node bin/watch-dev.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
/// <reference types="cypress" />
/// <reference types="admin-bro/cy" />
/// <reference types="../../support" />

context('resources/Company/actions/new', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Company/actions/new')
})

it('shows password property', () => {
const typedPassword = 'password'

cy.get('[data-testid="property-edit-password"] input[type="password"]').type(typedPassword)
cy.get('[data-testid="property-edit-password"] button').click()
cy.abGetProperty('password', 'input[type="password"]')
.type(typedPassword)
cy.abGetProperty('password', 'button')
.click()

cy.get('[data-testid="property-edit-password"] input[type="input"]').should('have.value', typedPassword)
cy.abGetProperty('password', 'input[type="input"]')
.should('have.value', typedPassword)
})

it('shows disabled checkBox', () => {
cy.get('[data-testid="property-edit-isAdmin"] input[type="checkbox"]')
cy.abGetProperty('isAdmin', 'input[type="checkbox"]')
.should('be.disabled')
.should('not.be.checked')

cy.get('[data-testid="property-edit-isAdmin"] label')
cy.abGetProperty('isAdmin', 'label')
.click()
.should('not.be.checked')
})

it('show translated select labels and button', () => {
cy.get('[data-testid="property-edit-companySize"] input').click()
cy.get('[data-testid="property-edit-companySize"] [class$="option"]')
.then((options) => {
expect(
options.map((k, option) => cy.$$(option).text()).toArray(),
).to.have.members(['superBig', 's', 't'])
})
cy.get('[data-testid="property-edit-tags"] button').should('have.text', 'Add new Tag')
cy.abGetProperty('companySize', 'input')
.click()
.get('[class$="option"]').then(options => options
.map((k, option) => cy.$$(option).text()).toArray())
.should('have.members', ['superBig', 's', 't'])

cy.abGetProperty('tags', 'button').should('have.text', 'Add new Tag')
})

it('preserve regular checkbox value when validation fails', () => {
cy.get('[data-testid="property-edit-isBig"] input[type="checkbox"]')
cy.abGetProperty('isBig', 'input[type="checkbox"]')
.should('not.be.disabled')
.should('not.be.checked')

// clicking checkbox twice
cy.get('[data-testid="property-edit-isBig"] label')
.click().click()
cy.abGetProperty('isBig', 'label').click().click()

cy.get('form button[data-testid="button-save"]').click()

cy.get('[data-testid="property-edit-isBig"] input[type="checkbox"]')
cy.abGetProperty('isBig', 'input[type="checkbox"]')
.should('not.be.checked')
})

Expand All @@ -64,19 +66,27 @@ context('resources/Company/actions/new', () => {
companySize: 'superBig',
}

cy.get('#email').type(data.email)
cy.get('#companyName').type(data.companyName)
cy.get('#address').type(data.address)
cy.get('#password').type('somePassword')

cy.get('[data-testid="property-edit-companySize"] input').click()
cy.get('[data-testid="property-edit-companySize"] [class$="option"]').first().click()

cy.get('[data-testid="property-edit-isBig"] label').click()
cy.abGetProperty('email', 'input')
.type(data.email)
cy.abGetProperty('companyName', 'input')
.type(data.companyName)
cy.abGetProperty('address', 'input')
.type(data.address)
cy.abGetProperty('password', 'input')
.type('somePassword')
cy.abGetProperty('companySize', 'input')
.click()
.get('[class$="option"]')
.first()
.click()
cy.abGetProperty('isBig', 'label')
.click()

cy.get('button[type="submit"]').click()
cy.get('button[type="submit"]')
.click()

cy.location('pathname').should('eq', '/admin/resources/Company')
cy.location('pathname')
.should('eq', '/admin/resources/Company')

cy.get('td[data-property-name="email"]')
.contains(data.email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('resources/Company', () => {
beforeEach(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
cy.visit('resources/Company')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const select = (selector, value) => {

context('resources/Employee/actions/new', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Employee/actions/new')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

context('resources/ExternalEmployees/actions/new', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/ExternalEmployees/actions/new')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

context('resources/Nested/actions/new', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Nested/actions/new')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const dateTimeRegex = /^[\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2}$/

context('resources/Profession/actions/new', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Page/actions/new')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

context('resources/Profession/actions/new', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Profession/actions/new')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

context('SignIn page', () => {
beforeEach(() => {
cy.login()
cy.abLogin({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

it('logs in to the application', () => {
cy.location('pathname').should('not.include', 'admin/login')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

context('resources/Taggables/actions/new', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Taggables/actions/new')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

context('resources/Tool/actions/new', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Tool/actions/new')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

context('resources/Tool/actions/edit', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Tool')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

context('resources/Tool', () => {
before(() => {
cy.login()
cy.abLoginAPI({ password: Cypress.env('ADMIN_PASSWORD'), email: Cypress.env('ADMIN_EMAIL') })
})

beforeEach(() => {
Cypress.Cookies.preserveOnce(Cypress.env('COOKIE_NAME'))
cy.abKeepLoggedIn({ cookie: Cypress.env('COOKIE_NAME') })
cy.visit('resources/Tool')
cy.get('.admin-bro_PaginationLink')
cy.get('.admin-bro_H2 .admin-bro_Badge').invoke('text').as('total')
Expand Down
Loading

0 comments on commit f73bd88

Please sign in to comment.