Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/deposit-admin.spec.js
Show All 11 Lines | function login(username, password) { | ||||
cy.get('input[name="username"]') | cy.get('input[name="username"]') | ||||
.type(username) | .type(username) | ||||
.get('input[name="password"]') | .get('input[name="password"]') | ||||
.type(password) | .type(password) | ||||
.get('form') | .get('form') | ||||
.submit(); | .submit(); | ||||
} | } | ||||
describe('Test admin deposit page', function() { | // data to use as request query response | ||||
it('Should test deposit page', function() { | let responseDeposits; | ||||
cy.visit(this.Urls.admin_deposit()); | let expectedOrigins; | ||||
// FIXME: cypress anti-pattern, do not use ui to log ¯\_(ツ)_/¯ | |||||
// https://docs.cypress.io/guides/getting-started/testing-your-app.html#Logging-in | |||||
login(username, password); | |||||
cy.server(); | describe('Test admin deposit page', function() { | ||||
let inputDeposits = [ | beforeEach(() => { | ||||
responseDeposits = [ | |||||
{ | { | ||||
'id': 614, | 'id': 614, | ||||
'external_id': 'c-d-1', | 'external_id': 'ch-de-1', | ||||
'reception_date': '2020-05-18T13:48:27Z', | 'reception_date': '2020-05-18T13:48:27Z', | ||||
'status': 'done', | 'status': 'done', | ||||
'status_detail': null, | 'status_detail': null, | ||||
'swh_id': 'swh:1:dir:ef04a768', | 'swh_id': 'swh:1:dir:ef04a768', | ||||
'swh_id_context': 'swh:1:dir:ef04a768;origin=https://w.s.o/c-d-1;visit=swh:1:snp:b234be1e;anchor=swh:1:rev:d24a75c9;path=/' | 'swh_id_context': 'swh:1:dir:ef04a768;origin=https://w.s.o/c-d-1;visit=swh:1:snp:b234be1e;anchor=swh:1:rev:d24a75c9;path=/' | ||||
}, | }, | ||||
{ | { | ||||
'id': 613, | 'id': 613, | ||||
'external_id': 'c-d-2', | 'external_id': 'ch-de-2', | ||||
'reception_date': '2020-05-18T11:20:16Z', | 'reception_date': '2020-05-18T11:20:16Z', | ||||
'status': 'done', | 'status': 'done', | ||||
'status_detail': null, | 'status_detail': null, | ||||
'swh_id': 'swh:1:dir:181417fb', | 'swh_id': 'swh:1:dir:181417fb', | ||||
'swh_id_context': 'swh:1:dir:181417fb;origin=https://w.s.o/c-d-2;visit=swh:1:snp:8c32a2ef;anchor=swh:1:rev:3d1eba04;path=/' | 'swh_id_context': 'swh:1:dir:181417fb;origin=https://w.s.o/c-d-2;visit=swh:1:snp:8c32a2ef;anchor=swh:1:rev:3d1eba04;path=/' | ||||
}, | }, | ||||
{ | { | ||||
'id': 612, | 'id': 612, | ||||
'external_id': 'c-d-3', | 'external_id': 'ch-de-3', | ||||
'reception_date': '2020-05-18T11:20:16Z', | 'reception_date': '2020-05-18T11:20:16Z', | ||||
'status': 'rejected', | 'status': 'rejected', | ||||
'status_detail': 'incomplete deposit!', | 'status_detail': 'incomplete deposit!', | ||||
'swh_id': null, | 'swh_id': null, | ||||
'swh_id_context': null | 'swh_id_context': null | ||||
} | } | ||||
]; | ]; | ||||
// those are computed from the | |||||
expectedOrigins = { | |||||
614: 'https://w.s.o/c-d-1', | |||||
613: 'https://w.s.o/c-d-2', | |||||
612: '' | |||||
}; | |||||
ardumont: I have some wip about this (but it's not completely stable).
I won't push right now so that… | |||||
Done Inline Actions(was speaking about the FIXME, this comment is now out of sync...) ardumont: (was speaking about the FIXME, this comment is now out of sync...) | |||||
}); | |||||
it('Should filter out deposits matching excluding pattern from display', function() { | |||||
cy.visit(this.Urls.admin_deposit()); | |||||
// FIXME: cypress anti-pattern, do not use ui to log ¯\_(ツ)_/¯ | |||||
// https://docs.cypress.io/guides/getting-started/testing-your-app.html#Logging-in | |||||
login(username, password); | |||||
cy.server(); | |||||
// entry supposed to be excluded from the display by default | |||||
let extraDeposit = { | |||||
'id': 10, | |||||
'external_id': 'check-deposit-3', | |||||
'reception_date': '2020-05-18T11:20:16Z', | |||||
'status': 'done', | |||||
'status_detail': null, | |||||
'swh_id': 'swh:1:dir:fb234417', | |||||
'swh_id_context': 'swh:1:dir:fb234417;origin=https://w.s.o/c-d-3;visit=swh:1:snp:181417fb;anchor=swh:1:rev:3d166604;path=/' | |||||
}; | |||||
// of course, that's how to copy a list (an "array") | |||||
let testDeposits = responseDeposits.slice(); | |||||
// and add a new element to that array by mutating it... | |||||
testDeposits.push(extraDeposit); | |||||
expectedOrigins[10] = 'https://w.s.o/c-d-3'; | |||||
// ensure we don't touch the original reference | |||||
expect(responseDeposits.length).to.be.equal(3); | |||||
expect(testDeposits.length).to.be.equal(4); | |||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: `${this.Urls.admin_deposit_list()}**`, | url: `${this.Urls.admin_deposit_list()}**`, | ||||
response: { | response: { | ||||
'draw': 10, | 'draw': 10, | ||||
'recordsTotal': 3, | 'recordsTotal': testDeposits.length, | ||||
'recordsFiltered': 3, | 'recordsFiltered': testDeposits.length, | ||||
'data': inputDeposits | 'data': testDeposits | ||||
} | } | ||||
}).as('listDeposits'); | }).as('listDeposits'); | ||||
cy.location('pathname') | cy.location('pathname') | ||||
.should('be.equal', this.Urls.admin_deposit()); | .should('be.equal', this.Urls.admin_deposit()); | ||||
cy.url().should('include', '/admin/deposit'); | cy.url().should('include', '/admin/deposit'); | ||||
cy.get('#swh-admin-deposit-list') | cy.get('#swh-admin-deposit-list') | ||||
.should('exist'); | .should('exist'); | ||||
// those are computed from the | cy.wait('@listDeposits').then((xhr) => { | ||||
let expectedOrigins = [ | let deposits = xhr.response.body.data; | ||||
'https://w.s.o/c-d-1', 'https://w.s.o/c-d-2', '' | expect(deposits.length).to.equal(testDeposits.length); | ||||
]; | |||||
cy.get('#swh-admin-deposit-list').find('tbody > tr').as('rows'); | |||||
// only 2 entries | |||||
cy.get('@rows').each((row, idx, collection) => { | |||||
let deposit = deposits[idx]; | |||||
let responseDeposit = testDeposits[idx]; | |||||
cy.log('deposit', deposit); | |||||
cy.log('responseDeposit', responseDeposit); | |||||
expect(deposit.id).to.be.equal(responseDeposit['id']); | |||||
expect(deposit.external_id).to.be.equal(responseDeposit['external_id']); | |||||
expect(deposit.status).to.be.equal(responseDeposit['status']); | |||||
expect(deposit.status_detail).to.be.equal(responseDeposit['status_detail']); | |||||
expect(deposit.swh_id).to.be.equal(responseDeposit['swh_id']); | |||||
expect(deposit.swh_id_context).to.be.equal(responseDeposit['swh_id_context']); | |||||
let expectedOrigin = expectedOrigins[deposit.id]; | |||||
// part of the data, but it should not be displayed (got filtered out) | |||||
if (deposit.external_id === 'check-deposit-3') { | |||||
cy.contains(deposit.status).should('not.be.visible'); | |||||
cy.contains(deposit.status_detail).should('not.be.visible'); | |||||
cy.contains(deposit.external_id).should('not.be.visible'); | |||||
cy.contains(expectedOrigin).should('not.be.visible'); | |||||
cy.contains(deposit.swh_id).should('not.be.visible'); | |||||
cy.contains(deposit.swh_id_context).should('not.be.visible'); | |||||
} else { | |||||
expect(deposit.external_id).to.be.not.equal('check-deposit-3'); | |||||
cy.contains(deposit.id).should('be.visible'); | |||||
if (deposit.status !== 'rejected') { | |||||
cy.contains(deposit.external_id).should('not.be.visible'); | |||||
cy.contains(expectedOrigin).should('be.visible'); | |||||
// ensure it's in the dom | |||||
} | |||||
cy.contains(deposit.status).should('be.visible'); | |||||
// those are hidden by default, so now visible | |||||
if (deposit.status_detail !== null) { | |||||
cy.contains(deposit.status_detail).should('not.be.visible'); | |||||
} | |||||
// those are hidden by default | |||||
if (deposit.swh_id !== null) { | |||||
cy.contains(deposit.swh_id).should('not.be.visible'); | |||||
cy.contains(deposit.swh_id_context).should('not.be.visible'); | |||||
} | |||||
} | |||||
}); | |||||
// toggling all links and ensure, the previous checks are inverted | |||||
cy.get('a.toggle-col').click({'multiple': true}).then(() => { | |||||
cy.get('#swh-admin-deposit-list').find('tbody > tr').as('rows'); | |||||
cy.get('@rows').should('have.length', 3); | |||||
cy.get('@rows').each((row, idx, collection) => { | |||||
let deposit = deposits[idx]; | |||||
let expectedOrigin = expectedOrigins[deposit.id]; | |||||
// filtered out deposit | |||||
if (deposit.external_id === 'check-deposit-3') { | |||||
cy.contains(deposit.status).should('not.be.visible'); | |||||
cy.contains(deposit.status_detail).should('not.be.visible'); | |||||
cy.contains(deposit.external_id).should('not.be.visible'); | |||||
cy.contains(expectedOrigin).should('not.be.visible'); | |||||
cy.contains(deposit.swh_id).should('not.be.visible'); | |||||
cy.contains(deposit.swh_id_context).should('not.be.visible'); | |||||
} else { | |||||
expect(deposit.external_id).to.be.not.equal('check-deposit-3'); | |||||
// ensure it's in the dom | |||||
cy.contains(deposit.id).should('not.be.visible'); | |||||
if (deposit.status !== 'rejected') { | |||||
cy.contains(deposit.external_id).should('not.be.visible'); | |||||
expect(row).to.contain(expectedOrigin); | |||||
} | |||||
expect(row).to.not.contain(deposit.status); | |||||
// those are hidden by default, so now visible | |||||
if (deposit.status_detail !== null) { | |||||
cy.contains(deposit.status_detail).should('be.visible'); | |||||
} | |||||
// those are hidden by default, so now they should be visible | |||||
if (deposit.swh_id !== null) { | |||||
cy.contains(deposit.swh_id).should('be.visible'); | |||||
cy.contains(deposit.swh_id_context).should('be.visible'); | |||||
} | |||||
} | |||||
}); | |||||
}); | |||||
cy.get('#swh-admin-deposit-list-error') | |||||
.should('not.contain', | |||||
'An error occurred while retrieving the list of deposits'); | |||||
}); | |||||
}); | |||||
it('Should display properly entries', function() { | |||||
cy.visit(this.Urls.admin_deposit()); | |||||
// FIXME: cypress anti-pattern, do not use ui to log ¯\_(ツ)_/¯ | |||||
// https://docs.cypress.io/guides/getting-started/testing-your-app.html#Logging-in | |||||
login(username, password); | |||||
let testDeposits = responseDeposits; | |||||
cy.server(); | |||||
cy.route({ | |||||
method: 'GET', | |||||
url: `${this.Urls.admin_deposit_list()}**`, | |||||
response: { | |||||
'draw': 10, | |||||
'recordsTotal': testDeposits.length, | |||||
'recordsFiltered': testDeposits.length, | |||||
'data': testDeposits | |||||
} | |||||
}).as('listDeposits'); | |||||
cy.location('pathname') | |||||
.should('be.equal', this.Urls.admin_deposit()); | |||||
cy.url().should('include', '/admin/deposit'); | |||||
cy.get('#swh-admin-deposit-list') | |||||
.should('exist'); | |||||
cy.wait('@listDeposits').then((xhr) => { | cy.wait('@listDeposits').then((xhr) => { | ||||
cy.log('response:', xhr.response); | cy.log('response:', xhr.response); | ||||
cy.log(xhr.response.body); | cy.log(xhr.response.body); | ||||
let deposits = xhr.response.body.data; | let deposits = xhr.response.body.data; | ||||
cy.log('Deposits: ', deposits); | cy.log('Deposits: ', deposits); | ||||
expect(deposits.length).to.equal(inputDeposits.length); | expect(deposits.length).to.equal(testDeposits.length); | ||||
cy.get('#swh-admin-deposit-list').find('tbody > tr').as('rows'); | cy.get('#swh-admin-deposit-list').find('tbody > tr').as('rows'); | ||||
// only 2 entries | // only 2 entries | ||||
cy.get('@rows').each((row, idx, collection) => { | cy.get('@rows').each((row, idx, collection) => { | ||||
let deposit = deposits[idx]; | let deposit = deposits[idx]; | ||||
let inputDeposit = inputDeposits[idx]; | let responseDeposit = testDeposits[idx]; | ||||
assert.isNotNull(deposit); | assert.isNotNull(deposit); | ||||
assert.isNotNull(inputDeposit); | assert.isNotNull(responseDeposit); | ||||
expect(deposit.id).to.be.equal(inputDeposit['id']); | expect(deposit.id).to.be.equal(responseDeposit['id']); | ||||
expect(deposit.external_id).to.be.equal(inputDeposit['external_id']); | expect(deposit.external_id).to.be.equal(responseDeposit['external_id']); | ||||
expect(deposit.status).to.be.equal(inputDeposit['status']); | expect(deposit.status).to.be.equal(responseDeposit['status']); | ||||
expect(deposit.status_detail).to.be.equal(inputDeposit['status_detail']); | expect(deposit.status_detail).to.be.equal(responseDeposit['status_detail']); | ||||
expect(deposit.swh_id).to.be.equal(inputDeposit['swh_id']); | expect(deposit.swh_id).to.be.equal(responseDeposit['swh_id']); | ||||
expect(deposit.swh_id_context).to.be.equal(inputDeposit['swh_id_context']); | expect(deposit.swh_id_context).to.be.equal(responseDeposit['swh_id_context']); | ||||
let expectedOrigin = expectedOrigins[idx]; | let expectedOrigin = expectedOrigins[deposit.id]; | ||||
// ensure it's in the dom | // ensure it's in the dom | ||||
cy.contains(deposit.id).should('be.visible'); | cy.contains(deposit.id).should('be.visible'); | ||||
if (deposit.status !== 'rejected') { | if (deposit.status !== 'rejected') { | ||||
cy.contains(deposit.external_id).should('be.visible'); | expect(row).to.not.contain(deposit.external_id); | ||||
cy.contains(expectedOrigin).should('be.visible'); | cy.contains(expectedOrigin).should('be.visible'); | ||||
} | } | ||||
cy.contains(deposit.status).should('be.visible'); | cy.contains(deposit.status).should('be.visible'); | ||||
// those are hidden by default, so now visible | // those are hidden by default, so now visible | ||||
if (deposit.status_detail !== null) { | if (deposit.status_detail !== null) { | ||||
cy.contains(deposit.status_detail).should('not.be.visible'); | cy.contains(deposit.status_detail).should('not.be.visible'); | ||||
} | } | ||||
// those are hidden by default | // those are hidden by default | ||||
if (deposit.swh_id !== null) { | if (deposit.swh_id !== null) { | ||||
cy.contains(deposit.swh_id).should('not.be.visible'); | cy.contains(deposit.swh_id).should('not.be.visible'); | ||||
cy.contains(deposit.swh_id_context).should('not.be.visible'); | cy.contains(deposit.swh_id_context).should('not.be.visible'); | ||||
} | } | ||||
}); | }); | ||||
// toggling all links and ensure, the previous checks are inverted | // toggling all links and ensure, the previous checks are inverted | ||||
cy.get('a.toggle-col').click({'multiple': true}).then(() => { | cy.get('a.toggle-col').click({'multiple': true}).then(() => { | ||||
cy.get('#swh-admin-deposit-list').find('tbody > tr').as('rows'); | cy.get('#swh-admin-deposit-list').find('tbody > tr').as('rows'); | ||||
cy.get('@rows').each((row, idx, collection) => { | cy.get('@rows').each((row, idx, collection) => { | ||||
let deposit = deposits[idx]; | let deposit = deposits[idx]; | ||||
let expectedOrigin = expectedOrigins[idx]; | let expectedOrigin = expectedOrigins[deposit.id]; | ||||
// ensure it's in the dom | // ensure it's in the dom | ||||
cy.contains(deposit.id).should('not.be.visible'); | cy.contains(deposit.id).should('not.be.visible'); | ||||
if (deposit.status !== 'rejected') { | if (deposit.status !== 'rejected') { | ||||
expect(row).to.contain(deposit.external_id); | expect(row).to.not.contain(deposit.external_id); | ||||
expect(row).to.contain(expectedOrigin); | expect(row).to.contain(expectedOrigin); | ||||
} | } | ||||
expect(row).to.not.contain(deposit.status); | expect(row).to.not.contain(deposit.status); | ||||
// those are hidden by default, so now visible | // those are hidden by default, so now visible | ||||
if (deposit.status_detail !== null) { | if (deposit.status_detail !== null) { | ||||
cy.contains(deposit.status_detail).should('be.visible'); | cy.contains(deposit.status_detail).should('be.visible'); | ||||
} | } | ||||
Show All 16 Lines |
I have some wip about this (but it's not completely stable).
I won't push right now so that fixme will stay for now.