Skip to content

Commit

Permalink
Updating from recent pull requests
Browse files Browse the repository at this point in the history
Merge branch 'd3bootstrap' into d3bootstrap_delsec
  • Loading branch information
jorisvanzundert committed May 23, 2024
2 parents 9119a1e + 0075152 commit 28d77b9
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 69 deletions.
28 changes: 28 additions & 0 deletions frontend-e2e/cypress/e2e/experimental.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,31 @@ describe('intercept traditions', () => {
});
});
});

describe('intercept login request', () => {
if (Cypress.env('CY_MODE') === 'headed') { // skip when in headless mode
it('passes in headed mode but fails in headless mode: run only in headed mode', { defaultCommandTimeout: 10000 }, () => {
cy.log("Cypress.env('CY_MODE'): " + Cypress.env('CY_MODE'));

cy.visit(`${Cypress.env('CY_STEMMAWEB_FRONTEND_URL')}/`);
cy.viewport(1600, 900);

cy.intercept('POST', `${Cypress.env('CY_STEMMAWEB_FRONTEND_URL')}/requests/login`).as('loginrequest');

cy.get('header').contains('a', 'Sign in').wait(500).click();
cy.get('#loginEmail').wait(500).type('[email protected]', { delay: 50 });
cy.get('#loginPassword').wait(500).type('UserPass', { delay: 50 });
cy.get('auth-modal').contains('button', 'Sign in').wait(500).click();

cy.wait('@loginrequest').then(interception => {
// const res_str = JSON.stringify(interception.response);
// cy.log('res_str: ' + res_str);
cy.expect(interception.response.statusCode).to.eq(200);
});

cy.get('header').contains('a', 'Logged in as [email protected]');
cy.get('header').should('not.contain', 'Sign in');
cy.get('header').contains('a', 'Sign out'); // for now, don't click without interception
});
}
});
10 changes: 5 additions & 5 deletions frontend-e2e/cypress/e2e/florilegium_cb.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ describe("'Florilegium Coislinianum B' has the right owner and witnesses", funct
cy.visit(`${Cypress.env('CY_STEMMAWEB_FRONTEND_URL')}/`);

cy.wait(500);
/* cy.get('#tradition_name').should(($tn) => {
/* cy.get('#tradition-name').should(($tn) => {
expect($tn.text().trim()).to.not.equal('Notre besoin'); }); // should fail.
// Does not fail because the tradition_name is not loaded so quickly.
// Eventually it is 'Notre besoin'. It fails as it should,
// only after waiting a bit, e.g. with cy.wait(1000) */

/* cy.get('#tradition_name').contains('Notre besoin'); // passes as expected,
/* cy.get('#tradition-name').contains('Notre besoin'); // passes as expected,
// it is the intended first view of the page.
// But one could also check if Florilegium is not there,
// and only there, after clicking on in in the toc. */

const expectedName = 'Florilegium "Coislinianum B"'
cy.get('#tradition_name').should(($tn) => {
cy.get('#tradition-name').should(($tn) => {
expect($tn.text().trim()).to.not.equal('Florilegium Coislinianum B');
}); // should pass
// is there a better way to assert 'does not contain text xyz'?
cy.get('#tradition_name').should('not.have.text', expectedName)
cy.get('#tradition-name').should('not.have.text', expectedName)
cy.get('tradition-list')
.contains(expectedName)
.click();
cy.get('#tradition_name').contains(expectedName);
cy.get('#tradition-name').contains(expectedName);
cy.get('#sidebar_properties').contains('[email protected]');
// Sort the witness list for better reliability
cy.get('#sidebar_properties').contains('A, B, C, D, E, F, G, H, K, P, Q, S, T');
Expand Down
132 changes: 132 additions & 0 deletions frontend-e2e/cypress/e2e/homepage.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* Assert everything is visible for an admin on the homepage upon login */

import test_traditions from '../fixtures/test_traditions.json';
import users from '../fixtures/users.json';
const admin = users.filter(({username}) => username === '[email protected]')[0];
const selected_fill_color = 'rgb(207, 220, 238)';

beforeEach(() => {
cy.visit(`${Cypress.env('CY_STEMMAWEB_FRONTEND_URL')}/`);
cy.viewport(1600, 900);
test_traditions.sort( (tradition_a, tradition_b) => tradition_a.title.localeCompare( tradition_b.title ) );
cy.loginViaUi(admin); // TODO: also for headless mode
});

afterEach(() => {
cy.logoutViaUi(admin); // TODO: also for headless mode
});

// on the homepage, the admin should see all traditions listed
// traditions with stemma should have buttons: edit add delete; those without: add
describe('all traditions are listed and provide stemma add or edit buttons', () => {
it('passes', () => {
// the number of displayed traditions should be equal to the total number of test_traditions
const count = test_traditions.length; // 7
cy.get('ul#traditions-list').children().should('have.length', count);
test_traditions.forEach((tradition) => {
cy.log("title: " + tradition.title);
// the test_tradition titles should all be found on the homepage
// together with their stemmas
cy.get('ul#traditions-list').contains(tradition.title).should('be.visible').click();
if (tradition.stemmata.length){
cy.log('Number of stemmata: ' + tradition.stemmata.length);
// traditions with a stemma should have buttons highlighted: edit add delete
cy.get('edit-stemma-buttons').within( ()=> {
cy.get('a#edit-stemma-button-link').should('be.visible').and('not.have.class', 'greyed-out');
cy.get('a#add-stemma-button-link').should('be.visible').and('not.have.class', 'greyed-out');
cy.get('a#delete-stemma-button-link').should('be.visible').and('not.have.class', 'greyed-out');
});
}
else {
// traditions with no stemma should have buttons highlighted: add
cy.get('edit-stemma-buttons').within( ()=> {
cy.get('a#edit-stemma-button-link').should('be.visible').and('have.class', 'greyed-out');
cy.get('a#add-stemma-button-link').should('be.visible').and('not.have.class', 'greyed-out');
cy.get('a#delete-stemma-button-link').should('be.visible').and('have.class', 'greyed-out');
});
}
});
});
});

// Assert that the stemma “edit” button is only enabled when there is a stemma (also the “delete” button/cross), and that it disappears on click, being being replaced, together with the “new” and “delete” button, by a “save” and a “cancel” button.

describe('Assert that only one tradition is highlighted in the sidebar menu: \
the current one, clicked on, or \
the first one upon loading the page.', () => {
// implements #164
it('passes', () => {
let n = 0 // check the first tradition at start
test_traditions.forEach((tradition, i) => {
// traditions are displayed in alphabetical order (test_traditions sorted above)
cy.log('idx+1) test_tradition title: ' + String(Number(i)+1) + ') ' +tradition.title);
cy.get('ul#traditions-list > li').eq(i).find('a')
.invoke('text')
.then((text) => {
expect(text.trim()).to.equal(tradition.title.trim())
cy.log('same idx+1) tradition title: ' + text.trim())
});
cy.get('ul#traditions-list > li').eq(i).contains(tradition.title).should('be.visible');

// on load only the first tradition is selected and highlighted
if (i == n){
cy.get('ul#traditions-list > li').eq(i).find('div').should('have.class', 'selected');
cy.get('ul#traditions-list > li').eq(i).find('svg').should('have.css', 'fill', selected_fill_color)
}
else {
cy.get('ul#traditions-list > li').eq(i).find('div').should('not.have.class', 'selected');
cy.get('ul#traditions-list > li').eq(i).find('svg').should('not.have.css', 'fill', selected_fill_color);
}
});

// Click on another tradition higlights its title and the others are not selected or highlighted
n = 3; // check nth tradition
cy.log('Click on ' + String(Number(n)+1) + '. tradition and assert selection');
cy.get('ul#traditions-list > li').eq(n).click();
cy.get('ul#traditions-list > li').eq(n).find('a') // <li> contains also section info text, <a> just the title
.invoke('text')
.then((text) => {
cy.log('Clicked on ' + String(Number(n)+1) + '. tradition title: ' + text.trim())
});
// Assert all traditions are correctly un-/selected and un-/filled
test_traditions.forEach((tradition, i) => {
// Only the clicked tradition is selected and highlighted
if (i == n){
cy.get('ul#traditions-list > li').eq(i).find('div').should('have.class', 'selected');
cy.get('ul#traditions-list > li').eq(i).find('svg').should('have.css', 'fill', selected_fill_color)
}
else {
cy.get('ul#traditions-list > li').eq(i).find('div').should('not.have.class', 'selected');
cy.get('ul#traditions-list > li').eq(i).find('svg').should('not.have.css', 'fill', selected_fill_color);
}
});
});

});

describe('message console logs errors and successes', () => {
if (Cypress.env('CY_MODE') === 'headed') {
it('passes', () => { // Login needed to add a stemma. Skip in headless mode for now.
const stemma_added_marker = 'Stemma added';
const stemma_deleted_marker = 'Deleted';
// initially the message panel should exist without text content
cy.get('#message-console-text-panel').as('messageconsole');
cy.get('@messageconsole').should('have.value', '');
// Add a stemma (the default example stemma)
cy.get('#add-stemma-button-link').click();
cy.get('#save-stemma-button-link').wait(500).click();
// when a stemma is saved it should have a message with the text "Stemma added"
cy.get('@messageconsole').contains(stemma_added_marker);
// delete the added stemma in order to reset the db
cy.get('#delete-stemma-button-link').click();
cy.get('.modal-content').contains('button', 'Yes, delete it').wait(500).click();
cy.get('#modalDialog').should('not.be.visible');
cy.get('@messageconsole').contains(stemma_deleted_marker);

// assert the content in the message console stays there also upon clicking on another tradition.
cy.get('ul#traditions-list > li').eq(-1).wait(500).click(); // ultimate tradition
cy.get('@messageconsole').should('be.visible').contains(stemma_deleted_marker);
cy.get('@messageconsole').contains(stemma_added_marker);
});
}
});
Loading

0 comments on commit 28d77b9

Please sign in to comment.