Page MenuHomeSoftware Heritage
Paste P676

status fail: deposit admin page cypress test tryouts
ActivePublic

Authored by ardumont on May 19 2020, 9:38 AM.
describe('Test admin deposit page', function() {
it('Does not do much!', function () {
expect(true).to.equal(true);
});
it('parseOrigin should parse correctly origin', function () {
function parseOrigin(data) {
"Extract origin if pattern found, null otherwise"
let originPattern = ';origin=';
let originPatternIdx = data.indexOf(originPattern);
if (originPatternIdx !== -1) {
let originUrl = data.slice(originPatternIdx + originPattern.length);
let nextSepPattern = ';';
let nextSepPatternIdx = originUrl.indexOf(nextSepPattern);
if (nextSepPatternIdx !== -1) { /* Remove extra context */
originUrl = originUrl.slice(0, nextSepPatternIdx);
}
return originUrl;
}
return null;
}
let data = "swh:1:rev:abc;origin=https://g.c/user/repo;visit=swh:1:snp:dev;path=/"
let actual_origin = parseOrigin(data)
expect(actual_origin).to.equal("https://g.c/user/repo")
let data2 = "swh:1:rev:abc;origin=something;path=/some/other"
let actual_origin2 = parseOrigin(data2)
expect(actual_origin2).to.equal("something")
let data3 = "swh:1:rev:abc;origin=https://f.s.o/repositories/swh-web"
let actual_origin3 = parseOrigin(data3)
expect(actual_origin3).to.equal("https://f.s.o/repositories/swh-web")
});
it ('Should test deposit page', function (){
cy.visit(this.Urls.admin_deposit());
// FIXME: cypress anti-pattern, do not use ui to log
login(username, password);
cy.server();
cy.log("admin deposit list api url: ", this.Urls.admin_deposit_list())
cy.route({
method: 'GET',
url: `${this.Urls.admin_deposit_list()}**`,
response: {
"draw": 1,
"recordsTotal": 2,
"recordsFiltered": 2,
"data": [
{
"id": 614,
"external_id": "check-deposit-2020-05-18T13:48:26.812334",
"reception_date": "2020-05-18T13:48:27.135170Z",
"status": "done",
"status_detail": null,
"swh_anchor_id": "swh:1:rev:d24a75c9528f569107d665aa3e37c31fffb148af",
"swh_anchor_id_context": "swh:1:rev:d24a75c9528f569107d665aa3e37c31fffb148af;origin=https://www.softwareheritage.org/check-deposit-2020-05-18T13:48:26.812334",
"swh_id": "swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea",
"swh_id_context": "swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea;origin=https://www.softwareheritage.org/check-deposit-2020-05-18T13:48:26.812334;visit=swh:1:snp:b234be1e0b0ecdbc76836a9c77a09846cf4d6dc2;anchor=swh:1:rev:d24a75c9528f569107d665aa3e37c31fffb148af;path=/"
},
{
"id": 613,
"external_id": "check-deposit-2020-05-18T11:20:16.079754",
"reception_date": "2020-05-18T11:20:16.414994Z",
"status": "done",
"status_detail": null,
"swh_anchor_id": "swh:1:rev:3d1eba044ba3d0c3f8668676c464367af94d76bc",
"swh_anchor_id_context": "swh:1:rev:3d1eba044ba3d0c3f8668676c464367af94d76bc;origin=https://www.softwareheritage.org/check-deposit-2020-05-18T11:20:16.079754",
"swh_id": "swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea",
"swh_id_context": "swh:1:dir:ef04a768181417fbc5eef4243e2507915f24deea;origin=https://www.softwareheritage.org/check-deposit-2020-05-18T11:20:16.079754;visit=swh:1:snp:8c32a2efdd7308d7753f7f52255ce7b6ced2dd76;anchor=swh:1:rev:3d1eba044ba3d0c3f8668676c464367af94d76bc;path=/"},
]
}
}).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.get('#swh-admin-deposit-list-error')
.should("not.contain",
"An error occurred while retrieving the list of deposits");
cy.get('#swh-admin-deposit-list')
.should("contain", "status");
cy.wait('@listDeposits', {"log": true});
// cy.get('#swh-admin-deposit-list')
// .should("contain", "https://www.softwareheritage.org/check-deposit-2020-05-18T13:48:26.812334");
cy.get('td.sorting-1').should("contain", 614);
cy.get('td.sorting-2').should("contain", 613);
});
});

Event Timeline

ardumont created this paste.May 19 2020, 9:38 AM
ardumont updated the paste's language from autodetect to js.
ardumont added a comment.EditedMay 20 2020, 10:24 AM

The issue with the real cypress test (3rd one 'Should test deposit page') is
that the stubbing of the listing deposit api request do not work as I expect...
At least, it's not apparently taken into account by the main deposit page i'm
cy.visiting ¯\_(ツ)_/¯. <- don't take me wrong, that must be me not understanding something

Note: Another issue I'm facing, I would like to be able to test one function,
not with all the html page context, i have no clue how to do that. I did not
understand yet how the js is loaded. So I ended up inlining the function i want
to test (2nd test 'parseOrigin should parse correctly origin').

Note2: I started reading the documentations heh but I'm not done. Those tools
(at least cypress, mocha) have extensive ones.