datacite/bracco

View on GitHub
cypress/e2e/client_admin/info.test.ts

Summary

Maintainability
F
3 days
Test Coverage
/// <reference types="cypress" />
/* eslint-disable no-undef */

function escapeRE(string) {
  //return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
  return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}

describe('ACCEPTANCE: CLIENT_ADMIN | INFO', () => {
  const waitTime = 1000;
  const waitTime2 = 2000;
  const waitTime3 = 3000;

  before(function () {
    cy.login(Cypress.env('client_admin_username'), Cypress.env('client_admin_password'));
    cy.setCookie('_consent', 'true');
    cy.wait(waitTime2);
  })

  beforeEach(() => {
    // TBD - Set up test environment.
  });

  after(function () {
    // TBD - Clean up any resources created for the test. (only local dev and stage).
    // cy.log('TBD - CLEAN UP RESOURCES AFTER TEST');
    cy.clearAllSessionStorage()
  });

  it('is logged in to homepage', () => {
    cy.visit('/');
    cy.url().should('include', '/repositories/datacite.test').then(() => {

      // Has Fabrica logo
      cy.get('img.fabrica-logo').should('exist').should('have.attr', 'src').should('include', 'fabrica-logo.svg');

      cy.get('h2.work').contains('DataCite Test Repository');
      cy.get('a#account_menu_link').should('contain', 'DATACITE.TEST');

      cy.get('ul.nav-tabs li.active a').contains(/Info/i)
        .and('have.attr', 'href').and('include', '/repositories/datacite.test');
      cy.get('ul.nav-tabs li a').contains(/Settings/i)
        .and('have.attr', 'href').and('include', '/repositories/datacite.test/settings');
      cy.get('ul.nav-tabs li a').contains(/Prefixes/i)
        .and('have.attr', 'href').and('include', '/repositories/datacite.test/prefixes');
      cy.get('ul.nav-tabs li a').contains(/DOIs/i)
        .and('have.attr', 'href').and('include', '/repositories/datacite.test/dois');

      cy.get('button.export-basic-metadata').should('not.exist');

      cy.get('#chart-doi-title').parent().parent('.panel').within((panel) => {
        cy.get('#chart-doi-title').contains(/DOIs\s*by\s*year/i);
        cy.get('.member.graphs a').and('have.attr', 'href')
          .and('include', '/repositories/datacite.test/dois');
        cy.get('#chart-doi');
      });

      // Has left sidebar buttons.
      cy.get('[data-test-left-sidebar]').should('be.visible').within(($sidebar) => {
        // Create DOI button - would like to do more testing but seems impossible in Cypress.
        cy.get('.create-doi-button').contains(/Create DOI/i);
        cy.get('.create-doi-button button.dropdown-toggle').click({ force: true }).then(($obj) => {
          //cy.get('.create-doi-button ul.dropdown-menu')
          //cy.get('.create-doi-button ul.dropdown-menu ul li a').contains(/DOI\s*Form/i);
          //cy.get('.create-doi-button ul.dropdown-menu ul li a').contains(/File\s*Upload/i);
        });
      });
    });
  });

  it('/settings redirects to homepage', () => {
    cy.visit('/settings');
    cy.url().should('include', '/repositories/datacite.test').then (() => {
      cy.get('a#account_menu_link').should('contain', 'DATACITE.TEST');
    });
  });

  it('/prefixes redirects to homepage', () => {
    cy.visit('/prefixes');
    cy.url().should('include', '/repositories/datacite.test').then (() => {
      cy.get('h2.work').contains('DataCite Test Repository');
      cy.get('a#account_menu_link').should('contain', 'DATACITE.TEST');
    });
  });

  it('/dois redirects to homepage', () => {
    cy.visit('/dois');
    cy.url().should('include', '/repositories/datacite.test').then (() => {
      cy.get('h2.work').contains('DataCite Test Repository');
      cy.get('a#account_menu_link').should('contain', 'DATACITE.TEST');
    });
  });

  it('has password settings page', () => {
    cy.visit('/repositories/datacite.test/change').then (() => {
      cy.url().should('include', '/repositories/datacite.test/change');
      cy.get('h2.work').contains('DataCite Test Repository');
      cy.get('a#account_menu_link').should('contain', 'DATACITE.TEST');

      cy.get('h3').contains(/Set Password/i);

      cy.get('form').within(($form) => {
        cy.get('input#password-input-field').should('be.visible');
        cy.get('input#confirm-password-input-field').should('be.visible');
        cy.get('button[type=submit]').should('be.visible');
        cy.get('button#cancel').should('be.visible');

        cy.get('button#cancel').click({force:true});
      });
    });

    cy.on("url:changed", (newUrl) => {
      expect(newUrl).to.contain("/repositories/datacite.test")
    })
  });

  // TBD - Could do more testing here. Only cursory testing for
  // presence of field objects. No testing of form behavior yet.
  it('has repository settings page', () => {
    cy.visit('/repositories/datacite.test/edit');
    cy.url().should('include', '/repositories/datacite.test/edit').then(() => {

      cy.wait(waitTime);
      cy.get('h2.work').contains('DataCite Test Repository');
      cy.get('a#account_menu_link').should('contain', 'DATACITE.TEST');

      cy.get('#repository-id').should('be.visible');
      cy.get('#client-type').should('be.visible');
      cy.get('#client-type .ember-power-select-selected-item').should('contain', 'Repository');

      cy.get('div#client-type div[role="button"]').click({ waitForAnimations: true }).then(($dropdown) => {
        // IGSN ID Catalog option should not exist for existing Periodical and Repository client_types
        cy.get('ul.ember-power-select-options li').contains('IGSN ID Catalog').should('not.exist');

        // Set client_type to Periodical
        cy.get('ul.ember-power-select-options li').contains('Periodical').click({ waitForAnimations: true }).then(() => {
          // Periodical client_type divs should be visible and Repository client_type divs shoudl not exist
          cy.get('#repository-issn').should('be.visible');
          cy.get('#repository-type').should('not.exist');
          cy.get('#certificate').should('not.exist');
        })
      });

      // Set client_type to RAiD Registry
      cy.get('div#client-type div[role="button"]').click({ waitForAnimations: true }).then(() => {
        cy.get('ul.ember-power-select-options li').contains('RAiD Registry').click({ waitForAnimations: true }).then(() => {
          // RAiD Registry client_type divs should be visible
          cy.get('#repository-issn').should('not.exist');
          cy.get('#repository-type').should('be.visible');
          cy.get('#certificate').should('be.visible');   
        })
      });

      // Set client_type back to Repository
      cy.get('div#client-type div[role="button"]').click({ waitForAnimations: true, force: true }).then(($dropdown) => {
        cy.get('ul.ember-power-select-options li').contains('Repository').click({ waitForAnimations: true })
      });

      cy.get('#re3data').should('be.visible');
      cy.get('#name').should('be.visible');
      cy.get('#name-field').should('be.visible');
      cy.get('#alternate-name').should('be.visible');
      cy.get('#system-email').should('be.visible');
      cy.get('#service-contact-given-name').should('be.visible');
      cy.get('#service-contact-family-name').should('be.visible');
      cy.get('#service-contact-email').should('be.visible');
      cy.get('#description').should('be.visible');
      cy.get('#url').should('be.visible');
      cy.get('#language').should('be.visible');
      cy.get('#software').should('be.visible');
      cy.get('#domains').should('be.visible');
      cy.get('#repository-type').should('be.visible');
      cy.get('#certificate').should('be.visible');
      cy.get('.alert.opt-in').contains(/The contacts entered may receive notifications/i)
        .within(() => {
          cy.get('a[href*="privacy-policy"]').should('be.visible');
        }
      );
      cy.get('button#update-repository').should('be.visible');
      cy.get('button').contains(/Cancel/i).should('be.visible');

      cy.get('button').contains(/Cancel/i).click({force:true});
    });

    cy.on("url:changed", (newUrl) => {
      expect(newUrl).to.contain("/repositories/datacite.test");
    });
  });

  it('can see info when using capitalized identifier URL subdirectory', () => {
    cy.visit('/repositories/DATACITE.TEST');
    cy.url().should('include', '/repositories/DATACITE.TEST').then(() => {
      
      cy.wait(waitTime3)
      // Info page should be populated with non-zero graph data.
      cy.get('.graphs > a').contains(/^0$/).should('not.exist')
    });
  });
});