Some cypress test cleanup and fixes

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2022-08-28 14:37:11 +02:00
parent 74d9e63888
commit a0c47f8115
7 changed files with 213 additions and 142 deletions

View File

@@ -1,4 +1,4 @@
import { randHash } from "../utils" import { randHash } from '../utils'
const randUser = randHash() const randUser = randHash()
describe('Board', function() { describe('Board', function() {
@@ -13,7 +13,7 @@ describe('Board', function () {
}) })
it('Can create a board', function() { it('Can create a board', function() {
let board = 'Test' const board = 'Test'
cy.intercept({ cy.intercept({
method: 'POST', method: 'POST',

View File

@@ -1,38 +1,67 @@
import { randHash } from '../utils' import { randHash } from '../utils'
const randUser = randHash() const randUser = randHash()
describe('Card', function () { const testBoardData = {
const board = 'TestBoard' title: 'MyBoardTest',
const list = 'TestList' color: '00ff00',
const password = 'pass123' stacks: [
{
title: 'TestList',
cards: [
{
title: 'Hello world',
},
],
},
],
}
describe('Card', function() {
before(function() { before(function() {
cy.nextcloudCreateUser(randUser, password) cy.nextcloudCreateUser(randUser, randUser)
cy.deckCreateBoard({ user: randUser, password }, board) cy.createExampleBoard({
cy.deckCreateList({ user: randUser, password }, list) user: randUser,
password: randUser,
board: testBoardData,
})
}) })
beforeEach(function() { beforeEach(function() {
cy.login(randUser, password) cy.login(randUser, randUser)
}) })
it('Can add a card', function () { it('Can show card details modal', function() {
let card = 'Card 1'
cy.openLeftSidebar() cy.openLeftSidebar()
cy.get('#app-navigation-vue .app-navigation__list .app-navigation-entry') cy.getNavigationEntry(testBoardData.title)
.eq(3).find('a.app-navigation-entry-link')
.first().click({ force: true }) .first().click({ force: true })
cy.get('.board .stack').eq(0).within(() => { cy.get('.board .stack').eq(0).within(() => {
cy.get('button.action-item.action-item--single.icon-add') cy.get('.card:contains("Hello world")').should('be.visible').click()
})
cy.get('.modal__card').should('be.visible')
cy.get('.app-sidebar-header__maintitle').contains('Hello world')
})
it('Can add a card', function() {
const newCardTitle = 'Write some cypress tests'
cy.openLeftSidebar()
cy.getNavigationEntry(testBoardData.title)
.first().click({ force: true })
cy.get('.board .stack').eq(0).within(() => {
cy.get('.card:contains("Hello world")').should('be.visible')
cy.get('.button-vue[aria-label*="Add card"]')
.first().click() .first().click()
cy.get('.stack__card-add form input#new-stack-input-main') cy.get('.stack__card-add form input#new-stack-input-main')
.type(card) .type(newCardTitle)
cy.get('.stack__card-add form input[type=submit]') cy.get('.stack__card-add form input[type=submit]')
.first().click() .first().click()
cy.get('.card').first().contains(card).should('be.visible') cy.get(`.card:contains("${newCardTitle}")`).should('be.visible')
}) })
}) })
}) })

View File

@@ -22,9 +22,8 @@ describe('Deck dashboard', function() {
const defaultBoard = 'Personal' const defaultBoard = 'Personal'
cy.openLeftSidebar() cy.openLeftSidebar()
cy.get('.app-navigation__list .app-navigation-entry') cy.get('.app-navigation-entry-wrapper[icon=icon-deck]')
.eq(1) .find('ul.app-navigation-entry__children .app-navigation-entry:contains(' + defaultBoard + ')')
.find('ul.app-navigation-entry__children li.app-navigation-entry')
.first() .first()
.contains(defaultBoard) .contains(defaultBoard)
.should('be.visible') .should('be.visible')

View File

@@ -1,10 +1,10 @@
import { randHash } from "../utils"; import { randHash } from '../utils'
const randUser = randHash(); const randUser = randHash()
describe("Stack", function () { describe('Stack', function() {
const board = "TestBoard"; const board = 'TestBoard'
const password = "pass123"; const password = 'pass123'
const stack = "List 1"; const stack = 'List 1'
before(function() { before(function() {
cy.nextcloudCreateUser(randUser, password) cy.nextcloudCreateUser(randUser, password)
@@ -16,18 +16,15 @@ describe("Stack", function () {
cy.login(randUser, password) cy.login(randUser, password)
}) })
it("Can create a stack", function () { it('Can create a stack', function() {
cy.openLeftSidebar() cy.openLeftSidebar()
cy.get("#app-navigation-vue .app-navigation__list .app-navigation-entry") cy.getNavigationEntry(board)
.eq(3)
.find("a.app-navigation-entry-link")
.first()
.click({ force: true }) .click({ force: true })
cy.get("#stack-add button").first().click() cy.get('#stack-add button').first().click()
cy.get("#stack-add form input#new-stack-input-main").type(stack) cy.get('#stack-add form input#new-stack-input-main').type(stack)
cy.get("#stack-add form input[type=submit]").first().click() cy.get('#stack-add form input[type=submit]').first().click()
cy.get(".board .stack").eq(0).contains(stack).should("be.visible") cy.get('.board .stack').eq(0).contains(stack).should('be.visible')
})
}) })
});

View File

@@ -20,94 +20,140 @@
* *
*/ */
const url = Cypress.config("baseUrl").replace(/\/index.php\/?$/g, ""); const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
Cypress.env("baseUrl", url); Cypress.env('baseUrl', url)
Cypress.Commands.add("login", (user, password, route = "/apps/deck/") => { Cypress.Commands.add('login', (user, password, route = '/apps/deck/') => {
let session = `${user}-${Date.now()}`; const session = `${user}-${Date.now()}`
cy.session(session, function() { cy.session(session, function() {
cy.visit(route); cy.visit(route)
cy.get("input[name=user]").type(user); cy.get('input[name=user]').type(user)
cy.get("input[name=password]").type(password); cy.get('input[name=password]').type(password)
cy.get("form[name=login] [type=submit]").click(); cy.get('form[name=login] [type=submit]').click()
cy.url().should("include", route); cy.url().should('include', route)
}); })
// in case the session already existed but we are on a different route... cy.visit(route)
cy.visit(route); })
});
Cypress.Commands.add("logout", (route = "/") => { Cypress.Commands.add('logout', (route = '/') => {
cy.session("_guest", function () {}); cy.session('_guest', function() {})
}); })
Cypress.Commands.add("nextcloudCreateUser", (user, password) => { Cypress.Commands.add('nextcloudCreateUser', (user, password) => {
cy.clearCookies(); cy.clearCookies()
cy.request({ cy.request({
method: "POST", method: 'POST',
url: `${Cypress.env("baseUrl")}/ocs/v1.php/cloud/users?format=json`, url: `${Cypress.env('baseUrl')}/ocs/v1.php/cloud/users?format=json`,
form: true, form: true,
body: { body: {
userid: user, userid: user,
password: password, password,
}, },
auth: { user: "admin", pass: "admin" }, auth: { user: 'admin', pass: 'admin' },
headers: { headers: {
"OCS-ApiRequest": "true", 'OCS-ApiRequest': 'true',
"Content-Type": "application/x-www-form-urlencoded", 'Content-Type': 'application/x-www-form-urlencoded',
}, },
}).then((response) => { }).then((response) => {
cy.log(`Created user ${user}`, response.status); cy.log(`Created user ${user}`, response.status)
}); })
}); })
Cypress.Commands.add("nextcloudUpdateUser", (user, password, key, value) => { Cypress.Commands.add('nextcloudUpdateUser', (user, password, key, value) => {
cy.request({ cy.request({
method: "PUT", method: 'PUT',
url: `${Cypress.env("baseUrl")}/ocs/v2.php/cloud/users/${user}`, url: `${Cypress.env('baseUrl')}/ocs/v2.php/cloud/users/${user}`,
form: true, form: true,
body: { key, value }, body: { key, value },
auth: { user, pass: password }, auth: { user, pass: password },
headers: { headers: {
"OCS-ApiRequest": "true", 'OCS-ApiRequest': 'true',
"Content-Type": "application/x-www-form-urlencoded", 'Content-Type': 'application/x-www-form-urlencoded',
}, },
}).then((response) => { }).then((response) => {
cy.log(`Updated user ${user} ${key} to ${value}`, response.status); cy.log(`Updated user ${user} ${key} to ${value}`, response.status)
}); })
}); })
Cypress.Commands.add("openLeftSidebar", () => { Cypress.Commands.add('openLeftSidebar', () => {
cy.get(".app-navigation button.app-navigation-toggle").click(); cy.get('.app-navigation button.app-navigation-toggle').click()
}); })
Cypress.Commands.add("deckCreateBoard", ({ user, password }, title) => { Cypress.Commands.add('deckCreateBoard', ({ user, password }, title) => {
cy.login(user, password); cy.login(user, password)
cy.get(".app-navigation button.app-navigation-toggle").click(); cy.get('.app-navigation button.app-navigation-toggle').click()
cy.get("#app-navigation-vue .app-navigation__list .app-navigation-entry") cy.get('#app-navigation-vue .app-navigation__list .app-navigation-entry')
.eq(3) .eq(3)
.find("a") .find('a')
.first() .first()
.click({ force: true }); .click({ force: true })
cy.get(".board-create form input[type=text]").type(title, { force: true }); cy.get('.board-create form input[type=text]').type(title, { force: true })
cy.get(".board-create form input[type=submit]") cy.get('.board-create form input[type=submit]')
.first() .first()
.click({ force: true }); .click({ force: true })
}); })
Cypress.Commands.add("deckCreateList", ({ user, password }, title) => { Cypress.Commands.add('deckCreateList', ({ user, password }, title) => {
cy.login(user, password); cy.login(user, password)
cy.get(".app-navigation button.app-navigation-toggle").click(); cy.get('.app-navigation button.app-navigation-toggle').click()
cy.get("#app-navigation-vue .app-navigation__list .app-navigation-entry") cy.get('#app-navigation-vue .app-navigation__list .app-navigation-entry')
.eq(3) .eq(3)
.find("a.app-navigation-entry-link") .find('a.app-navigation-entry-link')
.first() .first()
.click({ force: true }); .click({ force: true })
cy.get("#stack-add button").first().click(); cy.get('#stack-add button').first().click()
cy.get("#stack-add form input#new-stack-input-main").type(title); cy.get('#stack-add form input#new-stack-input-main').type(title)
cy.get("#stack-add form input[type=submit]").first().click(); cy.get('#stack-add form input[type=submit]').first().click()
}); })
Cypress.Commands.add('createExampleBoard', ({ user, password, board }) => {
cy.request({
method: 'POST',
url: `${Cypress.env('baseUrl')}/index.php/apps/deck/api/v1.0/boards`,
auth: {
user,
password,
},
body: { title: board.title, color: board.color ?? 'ff0000' },
}).then((boardResponse) => {
expect(boardResponse.status).to.eq(200)
const boardData = boardResponse.body
for (const stackIndex in board.stacks) {
const stack = board.stacks[stackIndex]
cy.request({
method: 'POST',
url: `${Cypress.env('baseUrl')}/index.php/apps/deck/api/v1.0/boards/${boardData.id}/stacks`,
auth: {
user,
password,
},
body: { title: stack.title, order: 0 },
}).then((stackResponse) => {
const stackData = stackResponse.body
for (const cardIndex in stack.cards) {
const card = stack.cards[cardIndex]
cy.request({
method: 'POST',
url: `${Cypress.env('baseUrl')}/index.php/apps/deck/api/v1.0/boards/${boardData.id}/stacks/${stackData.id}/cards`,
auth: {
user,
password,
},
body: { title: card.title },
})
}
})
}
})
})
Cypress.Commands.add('getNavigationEntry', (boardTitle) => {
return cy.get('.app-navigation-entry-wrapper[icon=icon-deck]')
.find('ul.app-navigation-entry__children .app-navigation-entry:contains(' + boardTitle + ')')
.find('a.app-navigation-entry-link')
})