Skip to content

Commit

Permalink
Merge pull request #1000 from necyberteam/cypress-jasper-11-08-2023
Browse files Browse the repository at this point in the history
more tests, esp. tags
  • Loading branch information
a-pasquale authored Nov 9, 2023
2 parents 7d4bf9b + f9789fc commit a460a11
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("Anonymous user tests the Individual Affinity Groups page", () => {
// verify image
cy.get('.field--name-field-image')
.find('img')
.ampVerifyImage();
.verifyImage();

// events & announcements
cy.get('.block-access-affinitygroup.block-affinity-bottom-left')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
describe('Anonymous user verifes the images on the affinity-group page', () => {
it('should find expected stuff', () => {
cy.visit('/affinity_groups');
cy.get('img').each(($img) => cy.wrap($img).ampVerifyImage());
cy.verifyImages();
});
});
7 changes: 7 additions & 0 deletions tests/cypress/cypress/e2e/accessmatch/asp-homepage.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe('Homepage ASP Test', () => {
it('tests ASP', () => {
cy.visit('/');
cy.verifyImages();
cy.task("log", "ASP homepage images all load");
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ describe("Tests of the knowledge-base page", () => {
.should('have.attr', 'href')
.and('contain', 'https://ask.cyberinfrastructure.org/tag'));

// popular ci-links
// popular 3 ci-links so popular links list is full
cy.loginAs('[email protected]', 'b8QW]X9h7#5n');
create_dummy_ci_link();
create_dummy_ci_link();
create_dummy_ci_link();
cy.drupalLogout();
cy.visit("/knowledge-base");

cy.get('.btn.btn-primary')
.contains('FIND LINKS')
Expand All @@ -61,12 +66,20 @@ describe("Tests of the knowledge-base page", () => {
cy.get('.field--type-text-with-summary')
.contains('Popular CI Links');

// verify count of ask-ci links is 10
cy.get('.block-top-tags-from-askci > .flex-wrap')
.find('a').should('have.length', 10);

// test the known ci-link
cy.get('.view-resources.view-id-resources')
.contains('dummy-ci-link-for-testing-knowledge-base')
.should('have.attr', 'href')
.and('contain', '/ci-links');

// verify count of ci-links is 3
cy.get('.view-resources.view-id-resources')
.find('a').should('have.length', 3);

// test any other ci-links
cy.get('.view-resources.view-id-resources')
.find('a')
Expand All @@ -80,7 +93,6 @@ describe("Tests of the knowledge-base page", () => {

// helper function to create a ci-link that can be added to the AG
function create_dummy_ci_link() {
cy.loginAs('[email protected]', 'b8QW]X9h7#5n');
cy.visit('/form/ci-link');
cy.get('#edit-approved').check();
cy.get('#edit-title').type('dummy-ci-link-for-testing-knowledge-base');
Expand All @@ -90,8 +102,6 @@ function create_dummy_ci_link() {
// tag "access-acount" is selected
cy.get('.tags').contains('access-acount').click();
cy.get('#edit-submit').click();
cy.drupalLogout();
cy.visit("/knowledge-base");
}


Expand Down
4 changes: 2 additions & 2 deletions tests/cypress/cypress/e2e/accessmatch/outgages.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describe('Anonymous user visit the outages page', () => {
cy.get('#outages-all_info').contains('Showing 1 to 10 of');

// be default, 10 outages are shown.
cy.get('table[id="outages-all"]')
.find('tr').should('have.length', 11);
cy.get('table[id="outages-all"] > tbody')
.find('tr').should('have.length', 10);

// check each row has link to ask.ci
cy.get('table[id="outages-all"]')
Expand Down
53 changes: 53 additions & 0 deletions tests/cypress/cypress/e2e/accessmatch/tags/tags.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Verify the tags page.
*/
describe("Verify the tags page", () => {
it("Tests the tags page", () => {

cy.visit("/tags");

cy.get(".page-title").contains("Tags");

// check breadcrumbs
const crumbs = [
['Support', '/'],
['Tags', null]
];
cy.checkBreadcrumbs(crumbs);

// each h2 is a tag category -- verify each h2 with the each() function
cy.get('.block-system-main-block')
.find('h2.mt-10')
.each(($el) => {

// cy.task('log', 'h2: ' + $el.text());

// verify there's a block with the id of the h2 text
cy.get('.block-system-main-block')
.get('[id="' + $el.text() + '"]')
.contains($el.text());

// each category should have a bunch of tags - get an alias to that element
cy.get('.block-system-main-block')
.get('[id="' + $el.text() + '"]')
.next() // in the DOM, this gets the element containing all the tags
.as('tag-list');

// verify there are more than 0 tags per category
cy.get('@tag-list')
.find('a').should('have.length.gt', 0);

// verify each tag has a good href
cy.get('@tag-list')
.find('a')
.each($a => {
expect($a).to.have.attr("href", '/tags/' + $a.text());
});

// verify 2nd sidebar has same tag category
cy.get('.region.region-sidebar-second')
.contains($el.text())
.should('have.attr', 'href', '#' + $el.text());
});
});
});
12 changes: 9 additions & 3 deletions tests/cypress/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/**
* Verify all images load.
*/
Cypress.Commands.add('verifyImages', () => {
cy.get('img').each(($img) => cy.wrap($img).verifyImage());
});

/**
* Verify that an img element loads.
*
* Note that this is a "child" custom command, so it must be called
* with parent cypress command that yields an image element, e.g.:
* cy.get('.field--name-field-image')
* .get('img')
* .ampVerifyImage();
* .verifyImage();
*/
Cypress.Commands.add('ampVerifyImage', { prevSubject: true }, ($img) => {
Cypress.Commands.add('verifyImage', { prevSubject: true }, ($img) => {
const url = ($img[0]?.src || $img[0]?.srcset);
if (url) {
cy.request(url).then((response) => {
Expand Down Expand Up @@ -59,7 +66,6 @@ Cypress.Commands.add('checkBreadcrumbs', (crumbs) => {
}
});


/**
* Logs out the user.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ hostname: support.access-ci.org
name: 'Access Support'
scheme: https
weight: 11
is_default: true
is_default: false
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ hostname: necyberteam.org
name: 'Northeast Cyberteam'
scheme: https
weight: 1
is_default: false
is_default: true

0 comments on commit a460a11

Please sign in to comment.