Page MenuHomeSoftware Heritage
Paste P1317

(An Untitled Masterwork)
ActivePublic

Authored by ardumont on Mar 25 2022, 3:02 PM.
describe('Browse requests list tests', function() {
beforeEach(function() {
this.addForgeNowUrl = this.Urls.forge_add();
this.listAddForgeRequestsUrl = this.Urls.add_forge_request_list_datatables();
});
//...
it('should only display user requests when filter is activated', function() {
cy.intercept(`${this.listAddForgeRequestsUrl}**`, {
fixture: 'add-forge-now-requests'
}).as('listRequests');
let expectedUserRequests = [];
let expectedOtherRequests = [];
cy.readFile('cypress/fixtures/add-forge-now-requests.json').then((result) => {
let requests = result['data'];
for (let i = 0; i < requests.length; i++) {
let request = requests[i];
console.log(request)
if (request.submitter_name === 'user') {
expectedUserRequests.push(request);
} else {
expectedOtherRequests.push(request);
}
}
expect(expectedUserRequests.length).to.eq(2);
expect(expectedOtherRequests.length).to.eq(4);
});
cy.userLogin();
cy.visit(this.addForgeNowUrl);
// user requests filter checkbox should be in the DOM
cy.get('#swh-add-forge-requests-list-tab').click();
cy.get('#swh-add-forge-user-filter').should('exist').should('be.checked');
// cy.get('#swh-add-forge-user-filter')
// .click({force: true});
cy.wait('@listRequests');
// check unfiltered user requests
cy.get('tbody tr').then(rows => {
cy.log(rows)
expect(rows.length).to.eq(2); // does not work since there is 6 entries in the fixture used and the actual filtering is done server side...
});
//...
});
});

Event Timeline

Almost but no, i don't find the way to check for the proper req.user_requests_only == 1 which works:

let userRequests = [];
let otherUsersRequests = [];
cy.readFile('cypress/fixtures/add-forge-now-requests.json').then((result) => {
  let requests = result['data'];
  for (let i = 0; i < requests.length; i++) {
    let request = requests[i];
    console.log(request)
    if (request.submitter_name === 'user') {
      userRequests.push(request);
    } else {
      otherUsersRequests.push(request);
    }
  }
  expect(userRequests.length).to.eq(2);
  expect(otherUsersRequests.length).to.eq(4);
});
cy.intercept(`${this.listAddForgeRequestsUrl}**`, (req) => {
  console.log(req);
  console.log(req.body);
  console.log(req.headers);
  console.log(req.user_requests_only);
  const data = req.user_requests_only == 1 ? userRequests : otherUsersRequests
  req.reply({
    statusCode: 201,
    body: {
      recordsTotal: 6,
      draw: 1,
      recordsFiltered: data.length,
      data: data
    }
  });