Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/deposit-admin.spec.js
Show All 25 Lines | it('Should test deposit page', function() { | ||||
cy.server(); | cy.server(); | ||||
let inputDeposits = [ | let inputDeposits = [ | ||||
{ | { | ||||
'id': 614, | 'id': 614, | ||||
'external_id': 'c-d-1', | 'external_id': 'c-d-1', | ||||
'reception_date': '2020-05-18T13:48:27Z', | 'reception_date': '2020-05-18T13:48:27Z', | ||||
'status': 'done', | 'status': 'done', | ||||
'status_detail': 'all good', | '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': 'c-d-2', | ||||
'reception_date': '2020-05-18T11:20:16Z', | 'reception_date': '2020-05-18T11:20:16Z', | ||||
'status': 'done', | 'status': 'done', | ||||
'status_detail': 'everything is fine', | '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': 'c-d-3', | ||||
'reception_date': '2020-05-18T11:20:16Z', | 'reception_date': '2020-05-18T11:20:16Z', | ||||
'status': 'rejected', | 'status': 'rejected', | ||||
'status_detail': 'hu ho, issue!', | 'status_detail': 'incomplete deposit!', | ||||
'swh_id': null, | 'swh_id': null, | ||||
'swh_id_context': null | 'swh_id_context': null | ||||
} | } | ||||
]; | ]; | ||||
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': 3, | ||||
'recordsFiltered': 3, | 'recordsFiltered': 3, | ||||
'data': inputDeposits | 'data': inputDeposits | ||||
} | } | ||||
}).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 | // those are computed from the | ||||
let expectedOrigins = ['https://w.s.o/c-d-1', 'https://w.s.o/c-d-2', '']; | let expectedOrigins = [ | ||||
'https://w.s.o/c-d-1', 'https://w.s.o/c-d-2', '' | |||||
]; | |||||
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(inputDeposits.length); | ||||
Show All 9 Lines | cy.wait('@listDeposits').then((xhr) => { | ||||
expect(deposit.external_id).to.be.equal(inputDeposit['external_id']); | expect(deposit.external_id).to.be.equal(inputDeposit['external_id']); | ||||
expect(deposit.status).to.be.equal(inputDeposit['status']); | expect(deposit.status).to.be.equal(inputDeposit['status']); | ||||
expect(deposit.status_detail).to.be.equal(inputDeposit['status_detail']); | expect(deposit.status_detail).to.be.equal(inputDeposit['status_detail']); | ||||
expect(deposit.swh_id).to.be.equal(inputDeposit['swh_id']); | expect(deposit.swh_id).to.be.equal(inputDeposit['swh_id']); | ||||
expect(deposit.swh_id_context).to.be.equal(inputDeposit['swh_id_context']); | expect(deposit.swh_id_context).to.be.equal(inputDeposit['swh_id_context']); | ||||
let expectedOrigin = expectedOrigins[idx]; | let expectedOrigin = expectedOrigins[idx]; | ||||
// ensure it's in the dom | // ensure it's in the dom | ||||
expect(row).to.contain(deposit.id); | cy.contains(deposit.id).should('be.visible'); | ||||
if (deposit.status === 'done') { | if (deposit.status !== 'rejected') { | ||||
expect(row).to.contain(deposit.external_id); | cy.contains(deposit.external_id).should('be.visible'); | ||||
} else { | cy.contains(expectedOrigin).should('be.visible'); | ||||
expect(row).to.not.contain(deposit.external_id); | |||||
} | } | ||||
expect(row).to.contain(deposit.status); | |||||
expect(row).to.contain(expectedOrigin); | 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 | // those are hidden by default | ||||
expect(row).to.not.contain(deposit.status_detail); | if (deposit.swh_id !== null) { | ||||
expect(row).to.not.contain(deposit.swh_id); | cy.contains(deposit.swh_id).should('not.be.visible'); | ||||
expect(row).to.not.contain(deposit.swh_id_context); | 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]; | |||||
// ensure it's in the dom | // ensure it's in the dom | ||||
expect(row).to.not.contain(deposit.id); | cy.contains(deposit.id).should('not.be.visible'); | ||||
if (deposit.status === 'done') { | if (deposit.status !== 'rejected') { | ||||
expect(row).to.contain(deposit.external_id); | expect(row).to.contain(deposit.external_id); | ||||
} else { | expect(row).to.contain(expectedOrigin); | ||||
expect(row).to.not.contain(deposit.external_id); | |||||
} | } | ||||
expect(row).to.not.contain(deposit.status); | expect(row).to.not.contain(deposit.status); | ||||
// those are hidden by default | // those are hidden by default, so now visible | ||||
expect(row).to.contain(deposit.status_detail); | 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) { | if (deposit.swh_id !== null) { | ||||
expect(row).to.contain(deposit.swh_id); | cy.contains(deposit.swh_id).should('be.visible'); | ||||
expect(row).to.contain(deposit.swh_id_context); | cy.contains(deposit.swh_id_context).should('be.visible'); | ||||
} | } | ||||
}); | }); | ||||
}); | }); | ||||
cy.get('#swh-admin-deposit-list-error') | cy.get('#swh-admin-deposit-list-error') | ||||
.should('not.contain', | .should('not.contain', | ||||
'An error occurred while retrieving the list of deposits'); | 'An error occurred while retrieving the list of deposits'); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); |