mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
96 lines
4.6 KiB
TypeScript
96 lines
4.6 KiB
TypeScript
// ***********************************************************
|
|
// This example support/index.js is processed and
|
|
// loaded automatically before your test files.
|
|
//
|
|
// This is a great place to put global configuration and
|
|
// behavior that modifies Cypress.
|
|
//
|
|
// You can change the location of this file or turn off
|
|
// automatically serving support files with the
|
|
// 'supportFile' configuration option.
|
|
//
|
|
// You can read more here:
|
|
// https://on.cypress.io/configuration
|
|
// ***********************************************************
|
|
|
|
// Import all custom Commands (from commands.ts) for all tests
|
|
import './commands';
|
|
|
|
// Import Cypress Axe tools for all tests
|
|
// https://github.com/component-driven/cypress-axe
|
|
import 'cypress-axe';
|
|
import { DSPACE_XSRF_COOKIE } from 'src/app/core/xsrf/xsrf.constants';
|
|
|
|
|
|
// Runs once before all tests
|
|
before(() => {
|
|
// Cypress doesn't have access to the running application in Node.js.
|
|
// So, it's not possible to inject or load the AppConfig or environment of the Angular UI.
|
|
// Instead, we'll read our running application's config.json, which contains the configs &
|
|
// is regenerated at runtime each time the Angular UI application starts up.
|
|
cy.task('readUIConfig').then((str: string) => {
|
|
// Parse config into a JSON object
|
|
const config = JSON.parse(str);
|
|
|
|
// Find URL of our REST API & save to global variable via task
|
|
let baseRestUrl = FALLBACK_TEST_REST_BASE_URL;
|
|
if (!config.rest.baseUrl) {
|
|
console.warn("Could not load 'rest.baseUrl' from config.json. Falling back to " + FALLBACK_TEST_REST_BASE_URL);
|
|
} else {
|
|
baseRestUrl = config.rest.baseUrl;
|
|
}
|
|
cy.task('saveRestBaseURL', baseRestUrl);
|
|
|
|
// Find domain of our REST API & save to global variable via task.
|
|
let baseDomain = FALLBACK_TEST_REST_DOMAIN;
|
|
if (!config.rest.host) {
|
|
console.warn("Could not load 'rest.host' from config.json. Falling back to " + FALLBACK_TEST_REST_DOMAIN);
|
|
} else {
|
|
baseDomain = config.rest.host;
|
|
}
|
|
cy.task('saveRestBaseDomain', baseDomain);
|
|
|
|
});
|
|
});
|
|
|
|
// Runs once before the first test in each "block"
|
|
beforeEach(() => {
|
|
// Pre-agree to all Klaro cookies by setting the klaro-anonymous cookie
|
|
// This just ensures it doesn't get in the way of matching other objects in the page.
|
|
cy.setCookie('klaro-anonymous', '{%22authentication%22:true%2C%22preferences%22:true%2C%22acknowledgement%22:true%2C%22google-analytics%22:true%2C%22google-recaptcha%22:true}');
|
|
|
|
// Remove any CSRF cookies saved from prior tests
|
|
cy.clearCookie(DSPACE_XSRF_COOKIE);
|
|
});
|
|
|
|
// Global constants used in tests
|
|
// May be overridden in our cypress.json config file using specified environment variables.
|
|
// Default values listed here are all valid for the Demo Entities Data set available at
|
|
// https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data
|
|
// (This is the data set used in our CI environment)
|
|
|
|
// Admin account used for administrative tests
|
|
export const TEST_ADMIN_USER = Cypress.env('DSPACE_TEST_ADMIN_USER') || 'dspacedemo+admin@gmail.com';
|
|
export const TEST_ADMIN_PASSWORD = Cypress.env('DSPACE_TEST_ADMIN_PASSWORD') || 'dspace';
|
|
// Community/collection/publication used for view/edit tests
|
|
export const TEST_COLLECTION = Cypress.env('DSPACE_TEST_COLLECTION') || '282164f5-d325-4740-8dd1-fa4d6d3e7200';
|
|
export const TEST_COMMUNITY = Cypress.env('DSPACE_TEST_COMMUNITY') || '0958c910-2037-42a9-81c7-dca80e3892b4';
|
|
export const TEST_ENTITY_PUBLICATION = Cypress.env('DSPACE_TEST_ENTITY_PUBLICATION') || 'e98b0f27-5c19-49a0-960d-eb6ad5287067';
|
|
// Search term (should return results) used in search tests
|
|
export const TEST_SEARCH_TERM = Cypress.env('DSPACE_TEST_SEARCH_TERM') || 'test';
|
|
// Collection used for submission tests
|
|
export const TEST_SUBMIT_COLLECTION_NAME = Cypress.env('DSPACE_TEST_SUBMIT_COLLECTION_NAME') || 'Sample Collection';
|
|
export const TEST_SUBMIT_COLLECTION_UUID = Cypress.env('DSPACE_TEST_SUBMIT_COLLECTION_UUID') || '9d8334e9-25d3-4a67-9cea-3dffdef80144';
|
|
export const TEST_SUBMIT_USER = Cypress.env('DSPACE_TEST_SUBMIT_USER') || 'dspacedemo+submit@gmail.com';
|
|
export const TEST_SUBMIT_USER_PASSWORD = Cypress.env('DSPACE_TEST_SUBMIT_USER_PASSWORD') || 'dspace';
|
|
// NOTE: FALLBACK_TEST_REST_BASE_URL is only used if Cypress cannot read the REST API BaseURL
|
|
// from the Angular UI's config.json. See 'before()' above.
|
|
const FALLBACK_TEST_REST_BASE_URL = 'http://localhost:8080/server';
|
|
const FALLBACK_TEST_REST_DOMAIN = 'localhost';
|
|
|
|
// USEFUL REGEX for testing
|
|
|
|
// Match any string that contains at least one non-space character
|
|
// Can be used with "contains()" to determine if an element has a non-empty text value
|
|
export const REGEX_MATCH_NON_EMPTY_TEXT = /^(?!\s*$).+/;
|