diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fcbdd8dfa9f..880ee9bf5ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,8 @@ on: workflow_dispatch: permissions: - contents: read # to fetch code (actions/checkout) + contents: read # to fetch code (actions/checkout) + packages: read # to fetch private images from GitHub Container Registry (GHCR) jobs: tests: @@ -44,12 +45,15 @@ jobs: #CHROME_VERSION: "90.0.4430.212-1" # Bump Node heap size (OOM in CI after upgrading to Angular 15) NODE_OPTIONS: '--max-old-space-size=4096' - # Project name to use when running docker compose prior to e2e tests + # Project name to use when running "docker compose" prior to e2e tests COMPOSE_PROJECT_NAME: 'ci' + # Docker Registry to use for Docker compose scripts below. + # We use GitHub's Container Registry to avoid aggressive rate limits at DockerHub. + DOCKER_REGISTRY: ghcr.io strategy: # Create a matrix of Node versions to test against (in parallel) matrix: - node-version: [16.x, 18.x] + node-version: [18.x, 20.x] # Do NOT exit immediately if one matrix job fails fail-fast: false # These are the actual CI steps to perform per job @@ -119,7 +123,15 @@ jobs: path: 'coverage/dspace-angular/lcov.info' retention-days: 14 - # Using docker compose start backend using CI configuration + # Login to our Docker registry, so that we can access private Docker images using "docker compose" below. + - name: Login to ${{ env.DOCKER_REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Using "docker compose" start backend using CI configuration # and load assetstore from a cached copy - name: Start DSpace REST Backend via Docker (for e2e tests) run: | @@ -195,9 +207,9 @@ jobs: - name: Shutdown Docker containers run: docker compose -f ./docker/docker-compose-ci.yml down - # Codecov upload is a separate job in order to allow us to restart this separate from the entire build/test - # job above. This is necessary because Codecov uploads seem to randomly fail at times. - # See https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954 +# # Codecov upload is a separate job in order to allow us to restart this separate from the entire build/test +# # job above. This is necessary because Codecov uploads seem to randomly fail at times. +# # See https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954 # codecov: # # Must run after 'tests' job above # needs: tests diff --git a/.github/workflows/codescan.yml b/.github/workflows/codescan.yml index 520db7523dc..1e16f8fcf86 100644 --- a/.github/workflows/codescan.yml +++ b/.github/workflows/codescan.yml @@ -35,7 +35,7 @@ jobs: steps: # https://github.com/actions/checkout - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. # https://github.com/github/codeql-action diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 54b79bee00b..4166c307a56 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -4,7 +4,7 @@ name: Docker images # Run this Build for all pushes to 'main' or maintenance branches, or tagged releases. # Also run for PRs to ensure PR doesn't break Docker build process # NOTE: uses "reusable-docker-build.yml" in DSpace/DSpace to actually build each of the Docker images -# https://github.com/DSpace/DSpace/blob/main/.github/workflows/reusable-docker-build.yml +# https://github.com/DSpace/DSpace/blob/dspace-7_x/.github/workflows/reusable-docker-build.yml # on: push: @@ -15,12 +15,17 @@ on: workflow_dispatch: permissions: - contents: read # to fetch code (actions/checkout) + contents: read # to fetch code (actions/checkout) + packages: write # to write images to GitHub Container Registry (GHCR) jobs: + ############################################################# + # Build/Push the 'dspace/dspace-angular' image + ############################################################# dspace-angular: # Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular' if: github.repository == 'dataquest-dev/dspace-angular' + # Use the reusable-docker-build.yml script from DSpace/DSpace repo to build our Docker image uses: dataquest-dev/DSpace/.github/workflows/reusable-docker-build.yml@dtq-dev with: build_id: dspace-angular @@ -38,6 +43,7 @@ jobs: dspace-angular-dist: # Ensure this job never runs on forked repos. It's only executed for 'dataquest/dspace-angular' if: github.repository == 'dataquest-dev/dspace-angular' && false # not used for now + # Use the reusable-docker-build.yml script from DSpace/DSpace repo to build our Docker image uses: dataquest-dev/DSpace/.github/workflows/reusable-docker-build.yml@dtq-dev with: build_id: dspace-angular-dist @@ -51,6 +57,10 @@ jobs: secrets: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }} + # Enable redeploy of sandbox & demo if the branch for this image matches the deployment branch of + # these sites as specified in reusable-docker-build.xml + REDEPLOY_SANDBOX_URL: ${{ secrets.REDEPLOY_SANDBOX_URL }} + REDEPLOY_DEMO_URL: ${{ secrets.REDEPLOY_DEMO_URL }} deploy: needs: dspace-angular diff --git a/.github/workflows/issue_opened.yml b/.github/workflows/issue_opened.yml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/.github/workflows/port_merged_pull_request.yml b/.github/workflows/port_merged_pull_request.yml index 109835d14d3..857f22755e4 100644 --- a/.github/workflows/port_merged_pull_request.yml +++ b/.github/workflows/port_merged_pull_request.yml @@ -23,11 +23,11 @@ jobs: if: github.event.pull_request.merged steps: # Checkout code - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # Port PR to other branch (ONLY if labeled with "port to") # See https://github.com/korthout/backport-action - name: Create backport pull requests - uses: korthout/backport-action@v1 + uses: korthout/backport-action@v2 with: # Trigger based on a "port to [branch]" label on PR # (This label must specify the branch name to port to) diff --git a/Dockerfile b/Dockerfile index 26b07b099ba..e1e72cbf43f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # This image will be published as dspace/dspace-angular # See https://github.com/DSpace/dspace-angular/tree/main/docker for usage details -FROM node:18-alpine +FROM docker.io/node:18-alpine # Ensure Python and other build tools are available # These are needed to install some node modules, especially on linux/arm64 diff --git a/Dockerfile.dist b/Dockerfile.dist index de5b41ff64e..26c8bf6d6ab 100644 --- a/Dockerfile.dist +++ b/Dockerfile.dist @@ -4,7 +4,7 @@ # Test build: # docker build -f Dockerfile.dist -t dspace/dspace-angular:dspace-7_x-dist . -FROM node:18-alpine AS build +FROM docker.io/node:18-alpine AS build # Ensure Python and other build tools are available # These are needed to install some node modules, especially on linux/arm64 diff --git a/angular.json b/angular.json index bf3dd88c524..a57b7582109 100644 --- a/angular.json +++ b/angular.json @@ -30,7 +30,6 @@ "lodash", "jwt-decode", "uuid", - "webfontloader", "zone.js" ], "outputPath": "dist/browser", diff --git a/config/config.example.yml b/config/config.example.yml index 8e23e60a8da..1146ec0a953 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -1,7 +1,7 @@ # NOTE: will log all redux actions and transfers in console debug: false -# Angular Universal server settings +# Angular User Inteface settings # NOTE: these settings define where Node.js will start your UI application. Therefore, these # "ui" settings usually specify a localhost port/URL which is later proxied to a public URL (using Apache or similar) ui: @@ -17,12 +17,34 @@ ui: # Trust X-FORWARDED-* headers from proxies (default = true) useProxies: true +# Angular Universal / Server Side Rendering (SSR) settings universal: - # Whether to inline "critical" styles into the server-side rendered HTML. - # Determining which styles are critical is a relatively expensive operation; - # this option can be disabled to boost server performance at the expense of - # loading smoothness. + # Whether to tell Angular to inline "critical" styles into the server-side rendered HTML. + # Determining which styles are critical is a relatively expensive operation; this option is + # disabled (false) by default to boost server performance at the expense of loading smoothness. inlineCriticalCss: false + # Path prefixes to enable SSR for. By default these are limited to paths of primary DSpace objects. + # NOTE: The "/handle/" path ensures Handle redirects work via SSR. The "/reload/" path ensures + # hard refreshes (e.g. after login) trigger SSR while fully reloading the page. + paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ] + # Whether to enable rendering of Search component on SSR. + # If set to true the component will be included in the HTML returned from the server side rendering. + # If set to false the component will not be included in the HTML returned from the server side rendering. + enableSearchComponent: false + # Whether to enable rendering of Browse component on SSR. + # If set to true the component will be included in the HTML returned from the server side rendering. + # If set to false the component will not be included in the HTML returned from the server side rendering. + enableBrowseComponent: false + # Enable state transfer from the server-side application to the client-side application. + # Defaults to true. + # Note: When using an external application cache layer, it's recommended not to transfer the state to avoid caching it. + # Disabling it ensures that dynamic state information is not inadvertently cached, which can improve security and + # ensure that users always use the most up-to-date state. + transferState: true + # When a different REST base URL is used for the server-side application, the generated state contains references to + # REST resources with the internal URL configured. By default, these internal URLs are replaced with public URLs. + # Disable this setting to avoid URL replacement during SSR. In this the state is not transferred to avoid security issues. + replaceRestUrl: true # The REST API server settings # NOTE: these settings define which (publicly available) REST API to use. They are usually @@ -33,6 +55,9 @@ rest: port: 443 # NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript nameSpace: /server + # Provide a different REST url to be used during SSR execution. It must contain the whole url including protocol, server port and + # server namespace (uncomment to use it). + #ssrBaseUrl: http://localhost:8080/server # Caching settings cache: @@ -176,6 +201,12 @@ languages: - code: en label: English active: true + - code: ar + label: العربية + active: true + - code: bn + label: বাংলা + active: true - code: ca label: Català active: true @@ -185,24 +216,36 @@ languages: - code: de label: Deutsch active: true + - code: el + label: Ελληνικά + active: true - code: es label: Español active: true + - code: fi + label: Suomi + active: true - code: fr label: Français active: true - code: gd label: Gàidhlig active: true + - code: hi + label: हिंदी + active: true + - code: hu + label: Magyar + active: true - code: it label: Italiano active: true + - code: kk + label: Қазақ + active: true - code: lv label: Latviešu active: true - - code: hu - label: Magyar - active: true - code: nl label: Nederlands active: true @@ -218,8 +261,8 @@ languages: - code: sr-lat label: Srpski (lat) active: true - - code: fi - label: Suomi + - code: sr-cyr + label: Српски active: true - code: sv label: Svenska @@ -227,27 +270,12 @@ languages: - code: tr label: Türkçe active: true - - code: vi - label: Tiếng Việt - active: true - - code: kk - label: Қазақ - active: true - - code: bn - label: বাংলা - active: true - - code: hi - label: हिंदी - active: true - - code: el - label: Ελληνικά - active: true - - code: sr-cyr - label: Српски - active: true - code: uk label: Yкраї́нська active: true + - code: vi + label: Tiếng Việt + active: true # Browse-By Pages @@ -394,6 +422,29 @@ comcolSelectionSort: sortField: 'dc.title' sortDirection: 'ASC' +# Live Region configuration +# Live Region as defined by w3c, https://www.w3.org/TR/wai-aria-1.1/#terms: +# Live regions are perceivable regions of a web page that are typically updated as a +# result of an external event when user focus may be elsewhere. +# +# The DSpace live region is a component present at the bottom of all pages that is invisible by default, but is useful +# for screen readers. Any message pushed to the live region will be announced by the screen reader. These messages +# usually contain information about changes on the page that might not be in focus. +liveRegion: + # The duration after which messages disappear from the live region in milliseconds + messageTimeOutDurationMs: 30000 + # The visibility of the live region. Setting this to true is only useful for debugging purposes. + isVisible: false + + +# Search settings +search: + # Number used to render n UI elements called loading skeletons that act as placeholders. + # These elements indicate that some content will be loaded in their stead. + # Since we don't know how many filters will be loaded before we receive a response from the server we use this parameter for the skeletons count. + # e.g. If we set 5 then 5 loading skeletons will be visualized before the actual filters are retrieved. + defaultFiltersCount: 5 + matomo: hostUrl: http://localhost:8135/ siteId: 1 diff --git a/cypress.config.ts b/cypress.config.ts index c7676fb7010..28463a44c61 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,6 +1,7 @@ import { defineConfig } from 'cypress'; export default defineConfig({ + video: true, videosFolder: 'cypress/videos', screenshotsFolder: 'cypress/screenshots', fixturesFolder: 'cypress/fixtures', @@ -9,27 +10,33 @@ export default defineConfig({ openMode: 0, }, env: { - // Global constants used in DSpace e2e tests (see also ./cypress/support/e2e.ts) - // May be overridden in our cypress.json config file using specified environment variables. + // Global DSpace environment variables used in all our Cypress e2e tests + // May be modified in this config, or overridden in a variety of ways. + // See Cypress environment variable docs: https://docs.cypress.io/guides/guides/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 DSPACE_TEST_ADMIN_USER: 'dspacedemo+admin@gmail.com', + DSPACE_TEST_ADMIN_USER_UUID: '335647b6-8a52-4ecb-a8c1-7ebabb199bda', DSPACE_TEST_ADMIN_PASSWORD: 'dspace', // Community/collection/publication used for view/edit tests DSPACE_TEST_COMMUNITY: '0958c910-2037-42a9-81c7-dca80e3892b4', DSPACE_TEST_COLLECTION: '282164f5-d325-4740-8dd1-fa4d6d3e7200', - DSPACE_TEST_ENTITY_PUBLICATION: 'e98b0f27-5c19-49a0-960d-eb6ad5287067', + DSPACE_TEST_ENTITY_PUBLICATION: '6160810f-1e53-40db-81ef-f6621a727398', // Search term (should return results) used in search tests DSPACE_TEST_SEARCH_TERM: 'test', - // Collection used for submission tests + // Main Collection used for submission tests. Should be able to accept normal Item objects DSPACE_TEST_SUBMIT_COLLECTION_NAME: 'Sample Collection', DSPACE_TEST_SUBMIT_COLLECTION_UUID: '9d8334e9-25d3-4a67-9cea-3dffdef80144', + // Collection used for Person entity submission tests. MUST be configured with EntityType=Person. + DSPACE_TEST_SUBMIT_PERSON_COLLECTION_NAME: 'People', // Account used to test basic submission process DSPACE_TEST_SUBMIT_USER: 'dspacedemo+submit@gmail.com', DSPACE_TEST_SUBMIT_USER_PASSWORD: 'dspace', + // Administrator users group + DSPACE_ADMINISTRATOR_GROUP: 'e59f5659-bff9-451e-b28f-439e7bd467e4', CLARIN_TEST_WITHDRAWN_ITEM: '7282fc76-0941-4055-a5a3-1f582c638050', CLARIN_TEST_WITHDRAWN_ITEM_WITH_REASON: '8ae76fcf-b26b-42f2-84d3-9a85e0517bca', CLARIN_TEST_WITHDRAWN_ITEM_WITH_REASON_AND_AUTHORS: 'cd368b6a-0019-4813-bad9-5050e50ba36d', diff --git a/cypress/e2e/admin-menu.cy.ts b/cypress/e2e/admin-menu.cy.ts deleted file mode 100644 index 0d02148cd9d..00000000000 --- a/cypress/e2e/admin-menu.cy.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { - TEST_ADMIN_PASSWORD, - TEST_ADMIN_USER, - TEST_SUBMIT_COLLECTION_UUID, -} from '../support/e2e'; - -/** - * Test menu options for admin - */ -describe('Admin Menu Page', () => { - beforeEach(() => { - // Create a new submission - cy.visit('/submit?collection=' + TEST_SUBMIT_COLLECTION_UUID + '&entityType=none'); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); - }); - - it('should pass accessibility tests', () => { - // Check handles redirect url in the tag - cy.get('.sidebar-top-level-items a[href = "/handle-table"]').scrollIntoView().should('be.visible'); - - // Check licenses redirect url in the tag - cy.get('.sidebar-top-level-items a[href = "/licenses/manage-table"]').scrollIntoView().should('be.visible'); - }); -}); diff --git a/cypress/e2e/breadcrumbs.cy.ts b/cypress/e2e/breadcrumbs.cy.ts deleted file mode 100644 index ea6acdafcde..00000000000 --- a/cypress/e2e/breadcrumbs.cy.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('Breadcrumbs', () => { - it('should pass accessibility tests', () => { - // Visit an Item, as those have more breadcrumbs - cy.visit('/entities/publication/'.concat(TEST_ENTITY_PUBLICATION)); - - // Wait for breadcrumbs to be visible - cy.get('ds-breadcrumbs').should('be.visible'); - - // Analyze for accessibility - testA11y('ds-breadcrumbs'); - }); -}); diff --git a/cypress/e2e/browse-by-author.cy.ts b/cypress/e2e/browse-by-author.cy.ts deleted file mode 100644 index 77af31fb2f2..00000000000 --- a/cypress/e2e/browse-by-author.cy.ts +++ /dev/null @@ -1,14 +0,0 @@ - -describe('Browse By Author', () => { - it('should pass accessibility tests', () => { - cy.visit('/browse/author'); - - // Wait for to be visible - cy.get('ds-browse-by-metadata-page').should('be.visible'); - - // Analyze for accessibility - // CLARIN - // testA11y('ds-browse-by-metadata-page'); - // CLARIN - }); -}); diff --git a/cypress/e2e/browse-by-dateissued.cy.ts b/cypress/e2e/browse-by-dateissued.cy.ts deleted file mode 100644 index e5211210f31..00000000000 --- a/cypress/e2e/browse-by-dateissued.cy.ts +++ /dev/null @@ -1,12 +0,0 @@ -describe('Browse By Date Issued', () => { - it('should pass accessibility tests', () => { - cy.visit('/browse/dateissued'); - - // Wait for to be visible - cy.get('ds-browse-by-date-page').should('be.visible'); - - // Removed the accessibility tests because the whole UI is customized - // Analyze for accessibility - // testA11y('ds-browse-by-date-page'); - }); -}); diff --git a/cypress/e2e/browse-by-subject.cy.ts b/cypress/e2e/browse-by-subject.cy.ts deleted file mode 100644 index 7463e3fe170..00000000000 --- a/cypress/e2e/browse-by-subject.cy.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { testA11y } from 'cypress/support/utils'; - -describe('Browse By Subject', () => { - it('should pass accessibility tests', () => { - cy.visit('/browse/subject'); - - // Wait for to be visible - cy.get('ds-browse-by-metadata-page').should('be.visible'); - - // Analyze for accessibility - // CLARIN - // testA11y('ds-browse-by-metadata-page'); - // CLARIN - }); -}); diff --git a/cypress/e2e/browse-by-title.cy.ts b/cypress/e2e/browse-by-title.cy.ts deleted file mode 100644 index 3cde7d4c7cf..00000000000 --- a/cypress/e2e/browse-by-title.cy.ts +++ /dev/null @@ -1,12 +0,0 @@ -describe('Browse By Title', () => { - it('should pass accessibility tests', () => { - cy.visit('/browse/title'); - - // Wait for to be visible - cy.get('ds-browse-by-title-page').should('be.visible'); - - // Removed the accessibility tests because the whole UI is customized - // Analyze for accessibility - // testA11y('ds-browse-by-title-page'); - }); -}); diff --git a/cypress/e2e/collection-page.cy.ts b/cypress/e2e/collection-page.cy.ts deleted file mode 100644 index e4e17d19c6d..00000000000 --- a/cypress/e2e/collection-page.cy.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TEST_COLLECTION } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('Collection Page', () => { - - it('should pass accessibility tests', () => { - cy.visit('/collections/'.concat(TEST_COLLECTION)); - - // tag must be loaded - cy.get('ds-collection-page').should('be.visible'); - - // TODO accessibility tests are failing because the UI has been changed - // Analyze for accessibility issues - // testA11y('ds-collection-page'); - }); -}); diff --git a/cypress/e2e/collection-statistics.cy.ts b/cypress/e2e/collection-statistics.cy.ts deleted file mode 100644 index d998e14e400..00000000000 --- a/cypress/e2e/collection-statistics.cy.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { REGEX_MATCH_NON_EMPTY_TEXT, TEST_COLLECTION } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('Collection Statistics Page', () => { - const COLLECTIONSTATISTICSPAGE = '/statistics/collections/'.concat(TEST_COLLECTION); - - // NOTE: the statistics option was removed from the navbar - add it there in the future and uncomment this test - // it('should load if you click on "Statistics" from a Collection page', () => { - // cy.visit('/collections/'.concat(TEST_COLLECTION)); - // cy.get('ds-navbar ds-link-menu-item a[title="Statistics"]').click(); - // cy.location('pathname').should('eq', COLLECTIONSTATISTICSPAGE); - // }); - - it('should contain a "Total visits" section', () => { - cy.visit(COLLECTIONSTATISTICSPAGE); - cy.get('table[data-test="TotalVisits"]').should('be.visible'); - }); - - it('should contain a "Total visits per month" section', () => { - cy.visit(COLLECTIONSTATISTICSPAGE); - // Check just for existence because this table is empty in CI environment as it's historical data - cy.get('.'.concat(TEST_COLLECTION).concat('_TotalVisitsPerMonth')).should('exist'); - }); - - it('should pass accessibility tests', () => { - cy.visit(COLLECTIONSTATISTICSPAGE); - - // tag must be loaded - cy.get('ds-collection-statistics-page').should('be.visible'); - - // Verify / wait until "Total Visits" table's label is non-empty - // (This table loads these labels asynchronously, so we want to wait for them before analyzing page) - cy.get('table[data-test="TotalVisits"] th[data-test="statistics-label"]').contains(REGEX_MATCH_NON_EMPTY_TEXT); - - // Analyze for accessibility issues - testA11y('ds-collection-statistics-page'); - }); -}); diff --git a/cypress/e2e/community-list.cy.ts b/cypress/e2e/community-list.cy.ts deleted file mode 100644 index c371f6ceae7..00000000000 --- a/cypress/e2e/community-list.cy.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { testA11y } from 'cypress/support/utils'; - -describe('Community List Page', () => { - - it('should pass accessibility tests', () => { - cy.visit('/community-list'); - - // tag must be loaded - cy.get('ds-community-list-page').should('be.visible'); - - // Open every expand button on page, so that we can scan sub-elements as well - cy.get('[data-test="expand-button"]').click({ multiple: true }); - - // Analyze for accessibility issues - testA11y('ds-community-list-page'); - }); -}); diff --git a/cypress/e2e/community-page.cy.ts b/cypress/e2e/community-page.cy.ts deleted file mode 100644 index 13e29e4fa07..00000000000 --- a/cypress/e2e/community-page.cy.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TEST_COMMUNITY } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('Community Page', () => { - - it('should pass accessibility tests', () => { - cy.visit('/communities/'.concat(TEST_COMMUNITY)); - - // tag must be loaded - cy.get('ds-community-page').should('be.visible'); - - // TODO accessibility tests are failing because the UI has been changed - // Analyze for accessibility issues - // testA11y('ds-community-page',); - }); -}); diff --git a/cypress/e2e/community-statistics.cy.ts b/cypress/e2e/community-statistics.cy.ts deleted file mode 100644 index 5d4000ad052..00000000000 --- a/cypress/e2e/community-statistics.cy.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { REGEX_MATCH_NON_EMPTY_TEXT, TEST_COMMUNITY } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('Community Statistics Page', () => { - const COMMUNITYSTATISTICSPAGE = '/statistics/communities/'.concat(TEST_COMMUNITY); - - // NOTE: Statistics option was removed from the navbar - // it('should load if you click on "Statistics" from a Community page', () => { - // cy.visit('/communities/'.concat(TEST_COMMUNITY)); - // cy.get('ds-navbar ds-link-menu-item a[title="Statistics"]').click(); - // cy.location('pathname').should('eq', COMMUNITYSTATISTICSPAGE); - // }); - - it('should contain a "Total visits" section', () => { - cy.visit(COMMUNITYSTATISTICSPAGE); - cy.get('table[data-test="TotalVisits"]').should('be.visible'); - }); - - it('should contain a "Total visits per month" section', () => { - cy.visit(COMMUNITYSTATISTICSPAGE); - // Check just for existence because this table is empty in CI environment as it's historical data - cy.get('.'.concat(TEST_COMMUNITY).concat('_TotalVisitsPerMonth')).should('exist'); - }); - - it('should pass accessibility tests', () => { - cy.visit(COMMUNITYSTATISTICSPAGE); - - // tag must be loaded - cy.get('ds-community-statistics-page').should('be.visible'); - - // Verify / wait until "Total Visits" table's label is non-empty - // (This table loads these labels asynchronously, so we want to wait for them before analyzing page) - cy.get('table[data-test="TotalVisits"] th[data-test="statistics-label"]').contains(REGEX_MATCH_NON_EMPTY_TEXT); - - // Analyze for accessibility issues - testA11y('ds-community-statistics-page'); - }); -}); diff --git a/cypress/e2e/footer.cy.ts b/cypress/e2e/footer.cy.ts deleted file mode 100644 index 156849519cd..00000000000 --- a/cypress/e2e/footer.cy.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { testA11y } from 'cypress/support/utils'; - -describe('Footer', () => { - it('should pass accessibility tests', () => { - cy.visit('/'); - - // Footer must first be visible - cy.get('ds-footer').should('be.visible'); - - // TODO accessibility tests are failing because the UI has been changed - // Analyze for accessibility - // testA11y('ds-footer'); - }); -}); diff --git a/cypress/e2e/handle-page.cy.ts b/cypress/e2e/handle-page.cy.ts deleted file mode 100644 index 6c900e595d8..00000000000 --- a/cypress/e2e/handle-page.cy.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { TEST_ADMIN_PASSWORD, TEST_ADMIN_USER } from '../support/e2e'; - -/** - * Test for checking if the handle page is loaded after redirecting. - */ -describe('Handle Page', () => { - - it('should pass accessibility tests', { - retries: { - runMode: 8, - openMode: 8, - }, - defaultCommandTimeout: 10000 - }, () => { - cy.visit('/handle-table'); - cy.loginViaForm(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); - // tag must be loaded - cy.get('ds-handle-page').should('exist'); - - // tag must be loaded - cy.get('ds-handle-table').should('exist'); - - // tag must be loaded - cy.get('ds-handle-global-actions').should('exist'); - }); -}); diff --git a/cypress/e2e/header.cy.ts b/cypress/e2e/header.cy.ts deleted file mode 100644 index f2437a687a9..00000000000 --- a/cypress/e2e/header.cy.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { testA11y } from 'cypress/support/utils'; - -describe('Header', () => { - it('should pass accessibility tests', () => { - cy.visit('/'); - - // Header must first be visible - cy.get('ds-header').should('be.visible'); - - // TODO accessibility tests are failing because the UI has been changed - // Analyze for accessibility - // testA11y({ - // include: ['ds-header'], - // exclude: [ - // ['#search-navbar-container'], // search in navbar has duplicative ID. Will be fixed in #1174 - // ['.dropdownLogin'] // "Log in" link has color contrast issues. Will be fixed in #1149 - // ], - // }); - }); -}); diff --git a/cypress/e2e/homepage-statistics.cy.ts b/cypress/e2e/homepage-statistics.cy.ts deleted file mode 100644 index 3c10c42ae2b..00000000000 --- a/cypress/e2e/homepage-statistics.cy.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { REGEX_MATCH_NON_EMPTY_TEXT, TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; -import '../support/commands'; - -describe('Site Statistics Page', () => { - // CLARIN - // NOTE: statistics were removed from the navbar - // it('should load if you click on "Statistics" from homepage', () => { - // cy.visit('/'); - // cy.get('ds-navbar ds-link-menu-item a[title="Statistics"]').click(); - // cy.location('pathname').should('eq', '/statistics'); - // }); - // CLARIN - - it('should pass accessibility tests', () => { - // generate 2 view events on an Item's page - cy.generateViewEvent(TEST_ENTITY_PUBLICATION, 'item'); - cy.generateViewEvent(TEST_ENTITY_PUBLICATION, 'item'); - - cy.visit('/statistics'); - - // tag must be visable - cy.get('ds-site-statistics-page').should('be.visible'); - - // Verify / wait until "Total Visits" table's *last* label is non-empty - // (This table loads these labels asynchronously, so we want to wait for them before analyzing page) - cy.get('table[data-test="TotalVisits"] th[data-test="statistics-label"]').last().contains(REGEX_MATCH_NON_EMPTY_TEXT); - // Wait an extra 500ms, just so all entries in Total Visits have loaded. - cy.wait(500); - - // Analyze for accessibility issues - // CLARIN - // NOTE: accessibility tests are failing because the UI has been changed - // testA11y('ds-site-statistics-page'); - // CLARIN - }); -}); diff --git a/cypress/e2e/homepage.cy.ts b/cypress/e2e/homepage.cy.ts deleted file mode 100644 index 59582adb7bc..00000000000 --- a/cypress/e2e/homepage.cy.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { testA11y } from 'cypress/support/utils'; - -// NOTE: We changed homepage and these tests are failing -// describe('Homepage', () => { -// beforeEach(() => { -// // All tests start with visiting homepage -// cy.visit('/'); -// }); -// -// it('should display translated title "DSpace Angular :: Home"', () => { -// cy.title().should('eq', 'DSpace Angular :: Home'); -// }); -// -// it('should contain a news section', () => { -// cy.get('ds-home-news').should('be.visible'); -// }); -// -// it('should have a working search box', () => { -// const queryString = 'test'; -// cy.get('[data-test="search-box"]').type(queryString); -// cy.get('[data-test="search-button"]').click(); -// cy.url().should('include', '/search'); -// cy.url().should('include', 'query=' + encodeURI(queryString)); -// }); -// -// it('should pass accessibility tests', () => { -// // Wait for homepage tag to appear -// cy.get('ds-home-page').should('be.visible'); -// -// // Analyze for accessibility issues -// testA11y('ds-home-page'); -// }); -// }); diff --git a/cypress/e2e/item-page.cy.ts b/cypress/e2e/item-page.cy.ts deleted file mode 100644 index dae06289983..00000000000 --- a/cypress/e2e/item-page.cy.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('Item Page', () => { - const ITEMPAGE = '/items/'.concat(TEST_ENTITY_PUBLICATION); - const ENTITYPAGE = '/entities/publication/'.concat(TEST_ENTITY_PUBLICATION); - - // Test that entities will redirect to /entities/[type]/[uuid] when accessed via /items/[uuid] - it('should redirect to the entity page when navigating to an item page', () => { - cy.visit(ITEMPAGE); - cy.location('pathname').should('eq', ENTITYPAGE); - }); - - // CLARIN - // NOTE: accessibility tests are failing because the UI has been changed - // it('should pass accessibility tests', () => { - // cy.visit(ENTITYPAGE); - // - // // tag must be loaded - // cy.get('ds-item-page').should('be.visible'); - // - // // Analyze for accessibility issues - // testA11y('ds-item-page'); - // }); - - - // it('should pass accessibility tests on full item page', () => { - // cy.visit(ENTITYPAGE + '/full'); - // - // // tag must be loaded - // cy.get('ds-full-item-page').should('be.visible'); - // - // // Analyze for accessibility issues - // testA11y('ds-full-item-page'); - // }); - // CLARIN -}); diff --git a/cypress/e2e/item-statistics.cy.ts b/cypress/e2e/item-statistics.cy.ts deleted file mode 100644 index c8bc0c0d4ee..00000000000 --- a/cypress/e2e/item-statistics.cy.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { REGEX_MATCH_NON_EMPTY_TEXT, TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('Item Statistics Page', () => { - const ITEMSTATISTICSPAGE = '/statistics/items/'.concat(TEST_ENTITY_PUBLICATION); - - // NOTE add statistics to the navbar and change this test - // it('should load if you click on "Statistics" from an Item/Entity page', () => { - // cy.visit('/entities/publication/'.concat(TEST_ENTITY_PUBLICATION)); - // cy.get('ds-navbar ds-link-menu-item a[title="Statistics"]').click(); - // cy.location('pathname').should('eq', ITEMSTATISTICSPAGE); - // }); - - it('should contain element ds-item-statistics-page when navigating to an item statistics page', () => { - cy.visit(ITEMSTATISTICSPAGE); - cy.get('ds-item-statistics-page').should('be.visible'); - cy.get('ds-item-page').should('not.exist'); - }); - - it('should contain a "Total visits" section', () => { - cy.visit(ITEMSTATISTICSPAGE); - cy.get('table[data-test="TotalVisits"]').should('be.visible'); - }); - - it('should contain a "Total visits per month" section', () => { - cy.visit(ITEMSTATISTICSPAGE); - // Check just for existence because this table is empty in CI environment as it's historical data - cy.get('.'.concat(TEST_ENTITY_PUBLICATION).concat('_TotalVisitsPerMonth')).should('exist'); - }); - - it('should pass accessibility tests', () => { - cy.visit(ITEMSTATISTICSPAGE); - - // tag must be loaded - cy.get('ds-item-statistics-page').should('be.visible'); - - // Verify / wait until "Total Visits" table's label is non-empty - // (This table loads these labels asynchronously, so we want to wait for them before analyzing page) - cy.get('table[data-test="TotalVisits"] th[data-test="statistics-label"]').contains(REGEX_MATCH_NON_EMPTY_TEXT); - - // TODO accessibility tests are failing because the UI has been changed - // Analyze for accessibility issues - // testA11y('ds-item-statistics-page'); - }); -}); diff --git a/cypress/e2e/login-modal.cy.ts b/cypress/e2e/login-modal.cy.ts deleted file mode 100644 index e86aa6843ed..00000000000 --- a/cypress/e2e/login-modal.cy.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { TEST_ADMIN_PASSWORD, TEST_ADMIN_USER, TEST_ENTITY_PUBLICATION } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -const page = { - openLoginMenu() { - // Click the "Log In" dropdown menu in header - cy.get('ds-themed-navbar [data-test="login-menu"]').click(); - }, - openUserMenu() { - // Once logged in, click the User menu in header - cy.get('ds-themed-navbar [data-test="user-menu"]').click(); - }, - submitLoginAndPasswordByPressingButton(email, password) { - // Enter email - cy.get('ds-themed-navbar [data-test="email"]').type(email); - // Enter password - cy.get('ds-themed-navbar [data-test="password"]').type(password); - // Click login button - cy.get('ds-themed-navbar [data-test="login-button"]').click(); - }, - submitLoginAndPasswordByPressingEnter(email, password) { - // In opened Login modal, fill out email & password, then click Enter - cy.get('ds-themed-navbar [data-test="email"]').type(email); - cy.get('ds-themed-navbar [data-test="password"]').type(password); - cy.get('ds-themed-navbar [data-test="password"]').type('{enter}'); - }, - submitLogoutByPressingButton() { - // This is the POST command that will actually log us out - cy.intercept('POST', '/server/api/authn/logout').as('logout'); - // Click logout button - cy.get('ds-themed-navbar [data-test="logout-button"]').click(); - // Wait until above POST command responds before continuing - // (This ensures next action waits until logout completes) - cy.wait('@logout'); - } -}; - -// CLARIN - CLARIN-DSpace7.x has different login -// describe('Login Modal', () => { -// it('should login when clicking button & stay on same page', () => { -// const ENTITYPAGE = '/entities/publication/'.concat(TEST_ENTITY_PUBLICATION); -// cy.visit(ENTITYPAGE); -// -// // Login menu should exist -// cy.get('ds-log-in').should('exist'); -// -// // Login, and the tag should no longer exist -// page.openLoginMenu(); -// cy.get('.form-login').should('be.visible'); -// -// page.submitLoginAndPasswordByPressingButton(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); -// cy.get('ds-log-in').should('not.exist'); -// -// // Verify we are still on the same page -// cy.url().should('include', ENTITYPAGE); -// -// // Open user menu, verify user menu & logout button now available -// page.openUserMenu(); -// cy.get('ds-user-menu').should('be.visible'); -// cy.get('ds-log-out').should('be.visible'); -// }); -// -// it('should login when clicking enter key & stay on same page', () => { -// cy.visit('/home'); -// -// // Open login menu in header & verify tag is visible -// page.openLoginMenu(); -// cy.get('.form-login').should('be.visible'); -// -// // Login, and the tag should no longer exist -// page.submitLoginAndPasswordByPressingEnter(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); -// cy.get('.form-login').should('not.exist'); -// -// // Verify we are still on homepage -// cy.url().should('include', '/home'); -// -// // Open user menu, verify user menu & logout button now available -// page.openUserMenu(); -// cy.get('ds-user-menu').should('be.visible'); -// cy.get('ds-log-out').should('be.visible'); -// }); -// -// it('should support logout', () => { -// // First authenticate & access homepage -// cy.login(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); -// cy.visit('/'); -// -// // Verify ds-log-in tag doesn't exist, but ds-log-out tag does exist -// cy.get('ds-log-in').should('not.exist'); -// cy.get('ds-log-out').should('exist'); -// -// // Click logout button -// page.openUserMenu(); -// page.submitLogoutByPressingButton(); -// -// // Verify ds-log-in tag now exists -// cy.get('ds-log-in').should('exist'); -// cy.get('ds-log-out').should('not.exist'); -// }); -// -// it('should allow new user registration', () => { -// cy.visit('/'); -// -// page.openLoginMenu(); -// -// // Registration link should be visible -// cy.get('ds-themed-navbar [data-test="register"]').should('be.visible'); -// -// // Click registration link & you should go to registration page -// cy.get('ds-themed-navbar [data-test="register"]').click(); -// cy.location('pathname').should('eq', '/register'); -// cy.get('ds-register-email').should('exist'); -// }); -// -// it('should allow forgot password', () => { -// cy.visit('/'); -// -// page.openLoginMenu(); -// -// // Forgot password link should be visible -// cy.get('ds-themed-navbar [data-test="forgot"]').should('be.visible'); -// -// // Click link & you should go to Forgot Password page -// cy.get('ds-themed-navbar [data-test="forgot"]').click(); -// cy.location('pathname').should('eq', '/forgot'); -// cy.get('ds-forgot-email').should('exist'); -// }); -// -// it('should pass accessibility tests', () => { -// cy.visit('/'); -// -// page.openLoginMenu(); -// -// cy.get('ds-log-in').should('exist'); -// -// // Analyze for accessibility issues -// testA11y('ds-log-in'); -// }); -// }); diff --git a/cypress/e2e/metadata-registry.cy.ts b/cypress/e2e/metadata-registry.cy.ts new file mode 100644 index 00000000000..fd2cb1601bb --- /dev/null +++ b/cypress/e2e/metadata-registry.cy.ts @@ -0,0 +1,32 @@ +import { testA11y } from 'cypress/support/utils'; + +describe('Metadata Registry', () => { + beforeEach(() => { + // 1️⃣ Set intercept first + cy.intercept('POST', '**/server/api/authn/login*').as('auth'); + + // 2️⃣ Visit protected page (triggers redirection to login) + cy.visit('/admin/registries/metadata'); + + // 3️⃣ Perform form login + cy.loginViaForm( + Cypress.env('DSPACE_TEST_ADMIN_USER'), + Cypress.env('DSPACE_TEST_ADMIN_PASSWORD') + ); + + // 4️⃣ Wait for the auth POST (if it happens) + cy.wait('@auth', { timeout: 10000 }).then(interception => { + cy.log(`Auth POST caught with status ${interception.response?.statusCode}`); + }); + + // 5️⃣ Finally, assert the redirect always happened + cy.url({ timeout: 10000 }).should('include', '/admin/registries/metadata'); + }); + + it('should pass accessibility tests', () => { + // Page must first be visible + cy.get('ds-metadata-registry').should('be.visible'); + // Analyze for accessibility issues + testA11y('ds-metadata-registry'); + }); +}); diff --git a/cypress/e2e/my-dspace.cy.ts b/cypress/e2e/my-dspace.cy.ts deleted file mode 100644 index 7ee733839eb..00000000000 --- a/cypress/e2e/my-dspace.cy.ts +++ /dev/null @@ -1,157 +0,0 @@ -import { Options } from 'cypress-axe'; -import { TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD, TEST_SUBMIT_COLLECTION_NAME } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('My DSpace page', () => { - it('should display recent submissions and pass accessibility tests', () => { - cy.visit('/mydspace'); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - - cy.get('ds-my-dspace-page').should('be.visible'); - - // CLARIN - // CLARIN-search component show only Items, so there are no records in the /mydspace page - // At least one recent submission should be displayed - // cy.get('[data-test="list-object"]').should('be.visible'); - // CLARIN - - // Click each filter toggle to open *every* filter - // (As we want to scan filter section for accessibility issues as well) - cy.get('.filter-toggle').click({ multiple: true }); - - // Analyze for accessibility issues - // CLARIN - // Commented out accessibility violations - // testA11y('ds-my-dspace-page'); - // CLARIN - }); - - it('should have a working detailed view that passes accessibility tests', () => { - cy.visit('/mydspace'); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - - cy.get('ds-my-dspace-page').should('be.visible'); - - // CLARIN - // This test was commented out because there are no options for a detailed view in the CLARIN-search component - // it is e.g., `Grid` or `List` view - // Click button in sidebar to display detailed view - // cy.get('ds-search-sidebar [data-test="detail-view"]').click(); - - // CLARIN-search component show only Items, so there are no records in the /mydspace page - // cy.get('ds-object-detail').should('be.visible'); - - // Analyze for accessibility issues - // CLARIN - // Commented out accessibility violations - // testA11y('ds-my-dspace-page', - // { - // rules: { - // // Search filters fail these two "moderate" impact rules - // 'heading-order': { enabled: false }, - // 'landmark-unique': { enabled: false } - // } - // } as Options - // ); - // CLARIN - }); - - // NOTE: Deleting existing submissions is exercised by submission.spec.ts - it('should let you start a new submission & edit in-progress submissions', () => { - cy.visit('/mydspace'); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - - // Open the New Submission dropdown - cy.get('button[data-test="submission-dropdown"]').click(); - // Click on the "Item" type in that dropdown - cy.get('#entityControlsDropdownMenu button[title="none"]').click(); - - // This should display the (popup window) - cy.get('ds-create-item-parent-selector').should('be.visible'); - - // Type in a known Collection name in the search box - cy.get('ds-authorized-collection-selector input[type="search"]').type(TEST_SUBMIT_COLLECTION_NAME); - - // Click on the button matching that known Collection name - cy.get('ds-authorized-collection-selector button[title="'.concat(TEST_SUBMIT_COLLECTION_NAME).concat('"]')).click(); - - // New URL should include /workspaceitems, as we've started a new submission - cy.url().should('include', '/workspaceitems'); - - // The Submission edit form tag should be visible - cy.get('ds-submission-edit').should('be.visible'); - - // A Collection menu button should exist & its value should be the selected collection - cy.get('#collectionControlsMenuButton span').should('have.text', TEST_SUBMIT_COLLECTION_NAME); - - // Now that we've created a submission, we'll test that we can go back and Edit it. - // Get our Submission URL, to parse out the ID of this new submission - cy.location().then(fullUrl => { - // This will be the full path (/workspaceitems/[id]/edit) - const path = fullUrl.pathname; - // Split on the slashes - const subpaths = path.split('/'); - // Part 2 will be the [id] of the submission - const id = subpaths[2]; - - // Click the "Save for Later" button to save this submission - cy.get('ds-submission-form-footer [data-test="save-for-later"]').click(); - - // "Save for Later" should send us to MyDSpace - cy.url().should('include', '/mydspace'); - - // Close any open notifications, to make sure they don't get in the way of next steps - cy.get('[data-dismiss="alert"]').click({multiple: true}); - - // This is the GET command that will actually run the search - cy.intercept('GET', '/server/api/discover/search/objects*').as('search-results'); - // On MyDSpace, find the submission we just created via its ID - cy.get('[data-test="search-box"]').type(id); - cy.get('[data-test="search-button"]').click(); - - // Wait for search results to come back from the above GET command - cy.wait('@search-results'); - - // CLARIN - // CLARIN-search component show only Items, so there are no records in the /mydspace page - // Click the Edit button for this in-progress submission - // cy.get('#edit_' + id).click(); - - // Should send us back to the submission form - // cy.url().should('include', '/workspaceitems/' + id + '/edit'); - // - // // Discard our new submission by clicking Discard in Submission form & confirming - // cy.get('ds-submission-form-footer [data-test="discard"]').click(); - // cy.get('button#discard_submit').click(); - // - // // Discarding should send us back to MyDSpace - // cy.url().should('include', '/mydspace'); - // CLARIN - }); - }); - - it('should let you import from external sources', () => { - cy.visit('/mydspace'); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - - // Open the New Import dropdown - cy.get('button[data-test="import-dropdown"]').click(); - // Click on the "Item" type in that dropdown - cy.get('#importControlsDropdownMenu button[title="none"]').click(); - - // New URL should include /import-external, as we've moved to the import page - cy.url().should('include', '/import-external'); - - // The external import searchbox should be visible - cy.get('ds-submission-import-external-searchbar').should('be.visible'); - }); - -}); diff --git a/cypress/e2e/pagenotfound.cy.ts b/cypress/e2e/pagenotfound.cy.ts deleted file mode 100644 index d02aa8541c3..00000000000 --- a/cypress/e2e/pagenotfound.cy.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { testA11y } from 'cypress/support/utils'; - -describe('PageNotFound', () => { - it('should contain element ds-pagenotfound when navigating to page that doesnt exist', () => { - // request an invalid page (UUIDs at root path aren't valid) - cy.visit('/e9019a69-d4f1-4773-b6a3-bd362caa46f2', { failOnStatusCode: false }); - cy.get('ds-pagenotfound').should('be.visible'); - - // Analyze for accessibility issues - testA11y('ds-pagenotfound'); - }); - - it('should not contain element ds-pagenotfound when navigating to existing page', () => { - cy.visit('/home'); - cy.get('ds-pagenotfound').should('not.exist'); - }); - -}); diff --git a/cypress/e2e/search-navbar.cy.ts b/cypress/e2e/search-navbar.cy.ts deleted file mode 100644 index 2f252b93a8a..00000000000 --- a/cypress/e2e/search-navbar.cy.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { TEST_SEARCH_TERM } from 'cypress/support/e2e'; - -const page = { - fillOutQueryInNavBar(query) { - // Click the magnifying glass - cy.get('ds-themed-navbar [data-test="header-search-icon"]').click(); - // Fill out a query in input that appears - cy.get('ds-themed-navbar [data-test="header-search-box"]').type(query); - }, - submitQueryByPressingEnter() { - cy.get('ds-themed-navbar [data-test="header-search-box"]').type('{enter}'); - }, - submitQueryByPressingIcon() { - cy.get('ds-themed-navbar [data-test="header-search-icon"]').click(); - } -}; - -// CLARIN -// NOTE: search was removed from the navbar - these tests are not actual -// describe('Search from Navigation Bar', () => { -// // NOTE: these tests currently assume this query will return results! -// const query = TEST_SEARCH_TERM; -// -// it('should go to search page with correct query if submitted (from home)', () => { -// cy.visit('/'); -// // This is the GET command that will actually run the search -// cy.intercept('GET', '/server/api/discover/search/objects*').as('search-results'); -// // Run the search -// page.fillOutQueryInNavBar(query); -// page.submitQueryByPressingEnter(); -// // New URL should include query param -// cy.url().should('include', 'query='.concat(query)); -// // Wait for search results to come back from the above GET command -// cy.wait('@search-results'); -// // At least one search result should be displayed -// cy.get('[data-test="list-object"]').should('be.visible'); -// }); -// -// it('should go to search page with correct query if submitted (from search)', () => { -// cy.visit('/search'); -// // This is the GET command that will actually run the search -// cy.intercept('GET', '/server/api/discover/search/objects*').as('search-results'); -// // Run the search -// page.fillOutQueryInNavBar(query); -// page.submitQueryByPressingEnter(); -// // New URL should include query param -// cy.url().should('include', 'query='.concat(query)); -// // Wait for search results to come back from the above GET command -// cy.wait('@search-results'); -// // At least one search result should be displayed -// cy.get('[data-test="list-object"]').should('be.visible'); -// }); -// -// it('should allow user to also submit query by clicking icon', () => { -// cy.visit('/'); -// // This is the GET command that will actually run the search -// cy.intercept('GET', '/server/api/discover/search/objects*').as('search-results'); -// // Run the search -// page.fillOutQueryInNavBar(query); -// page.submitQueryByPressingIcon(); -// // New URL should include query param -// cy.url().should('include', 'query='.concat(query)); -// // Wait for search results to come back from the above GET command -// cy.wait('@search-results'); -// // At least one search result should be displayed -// cy.get('[data-test="list-object"]').should('be.visible'); -// }); -// }); diff --git a/cypress/e2e/search-page.cy.ts b/cypress/e2e/search-page.cy.ts deleted file mode 100644 index 83b25fdbce2..00000000000 --- a/cypress/e2e/search-page.cy.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { Options } from 'cypress-axe'; -import { TEST_SEARCH_TERM } from 'cypress/support/e2e'; -import { testA11y } from 'cypress/support/utils'; - -describe('Search Page', () => { - it('should redirect to the correct url when query was set and submit button was triggered', () => { - const queryString = 'Another interesting query string'; - cy.visit('/search'); - // Type query in searchbox & click search button - cy.get('[data-test="search-box"]').type(queryString); - cy.get('[data-test="search-button"]').click(); - cy.url().should('include', 'query=' + encodeURI(queryString)); - }); - - // CLARIN - // NOTE: accessibility tests are failing because the UI has been changed - // it('should load results and pass accessibility tests', () => { - // cy.visit('/search?query='.concat(TEST_SEARCH_TERM)); - // cy.get('[data-test="search-box"]').should('have.value', TEST_SEARCH_TERM); - // - // // tag must be loaded - // cy.get('ds-search-page').should('be.visible'); - // - // // At least one search result should be displayed - // cy.get('[data-test="list-object"]').should('be.visible'); - // - // // Click each filter toggle to open *every* filter - // // (As we want to scan filter section for accessibility issues as well) - // cy.get('[data-test="filter-toggle"]').click({ multiple: true }); - // - // // Analyze for accessibility issues - // testA11y('ds-search-page'); - // }); - // - // it('should have a working grid view that passes accessibility tests', () => { - // cy.visit('/search?query='.concat(TEST_SEARCH_TERM)); - // - // // Click button in sidebar to display grid view - // cy.get('ds-search-sidebar [data-test="grid-view"]').click(); - // - // // tag must be loaded - // cy.get('ds-search-page').should('be.visible'); - // - // // At least one grid object (card) should be displayed - // cy.get('[data-test="grid-object"]').should('be.visible'); - // - // // Analyze for accessibility issues - // testA11y('ds-search-page', - // { - // rules: { - // // Search filters fail these two "moderate" impact rules - // 'heading-order': { enabled: false }, - // 'landmark-unique': { enabled: false } - // } - // } as Options - // ); - // }); -}); diff --git a/cypress/e2e/submission-ui.cy.ts b/cypress/e2e/submission-ui.cy.ts deleted file mode 100644 index f52c78517e4..00000000000 --- a/cypress/e2e/submission-ui.cy.ts +++ /dev/null @@ -1,272 +0,0 @@ -/** - * This IT will be never be pushed to the upstream because clicking testing DOM elements is antipattern because - * the tests on other machines could fail. - */ -import { - TEST_ADMIN_PASSWORD, - TEST_ADMIN_USER, - TEST_SUBMIT_CLARIAH_COLLECTION_UUID, - TEST_SUBMIT_COLLECTION_UUID -} from '../support/e2e'; -import { createItemProcess } from '../support/commands'; - - -const sideBarMenu = { - clickOnNewButton() { - cy.get('.sidebar-top-level-items div[role = "button"]').eq(0).click(); - }, - clickOnNewCommunityButton() { - cy.get('.sidebar-sub-level-items a[role = "button"]').eq(0).click(); - }, - clickOnNewCollectionButton() { - cy.get('.sidebar-sub-level-items a[role = "button"]').eq(1).click(); - }, - clickOnNewItemButton() { - cy.get('.sidebar-sub-level-items a[role = "button"]').eq(2).click(); - } -}; - -describe('Create a new submission', () => { - beforeEach(() => { - // Create a new submission - cy.visit('/submit?collection=' + TEST_SUBMIT_COLLECTION_UUID + '&entityType=none'); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); - }); - - // Test openAIRE - configured more retries because it failed with 3 retries - // Note: openAIRE tests are commented because they are failing in the server but locally they success. - // it('should add non EU sponsor without suggestion', { - // retries: { - // runMode: 6, - // openMode: 6, - // }, - // },() => { - // // funding code - // cy.get('ds-dynamic-sponsor-autocomplete').eq(0).click({force: true}).type('code'); - // // suggestion is popped up - must blur - // cy.get('body').click(0,0); - // cy.wait(250); - // // local.sponsor_COMPLEX_INPUT_3 - // cy.get('ds-dynamic-sponsor-autocomplete').eq(1).click({force: true}).type('projectName'); - // // blur because after each click on input will send PATCH request and the input value is removed - // cy.get('body').click(0,0); - // cy.wait(250); - // // select sponsor type - // createItemProcess.clickOnSelectionInput('local.sponsor_COMPLEX_INPUT_0'); - // createItemProcess.clickOnSelection('N/A',0); - // cy.wait(250); - // // sponsor organisation - // createItemProcess.writeValueToInput('local.sponsor_COMPLEX_INPUT_2', 'organisation', false); - // }); - // - // it('should load and add EU sponsor from suggestion',{ - // retries: { - // runMode: 6, - // openMode: 6, - // }, - // }, () => { - // // select sponsor type - // createItemProcess.clickOnSelectionInput('local.sponsor_COMPLEX_INPUT_0'); - // createItemProcess.clickOnSelection('EU',0); - // cy.wait(250); - // // write suggestion for the eu sponsor - local.sponsor_COMPLEX_INPUT_1 - // cy.get('ds-dynamic-sponsor-autocomplete').eq(0).click({force: true}).type('eve'); - // // select suggestion - // createItemProcess.clickOnSuggestionSelection(0); - // cy.wait(250); - // // EU input field should be visible - // createItemProcess.checkIsInputVisible('local.sponsor_COMPLEX_INPUT_4'); - // }); - // - // it('should add four EU sponsors', { - // retries: { - // runMode: 6, - // openMode: 6, - // }, - // },() => { - // // select sponsor type - // createItemProcess.clickOnSelectionInput('local.sponsor_COMPLEX_INPUT_0'); - // createItemProcess.clickOnSelection('EU',0); - // cy.wait(250); - // // write suggestion for the eu sponsor - local.sponsor_COMPLEX_INPUT_1 - // cy.get('ds-dynamic-sponsor-autocomplete').eq(0).click({force: true}).type('eve'); - // // select suggestion - // createItemProcess.clickOnSuggestionSelection(0); - // cy.wait(250); - // // EU input field should be visible - // createItemProcess.checkIsInputVisible('local.sponsor_COMPLEX_INPUT_4'); - // - // // add another sponsors - // addEUSponsor(1); - // addEUSponsor(2); - // addEUSponsor(3); - // }); - - // Test type-bind - it('should be showed chosen type value', { - retries: { - runMode: 6, - openMode: 6, - }, - defaultCommandTimeout: 10000 - },() => { - createItemProcess.clickOnSelectionInput('dc.type'); - createItemProcess.clickOnTypeSelection('Corpus'); - }); - - // Test CMDI input field - it('should be visible Has CMDI file input field because user is admin', { - retries: { - runMode: 6, - openMode: 6, - }, - defaultCommandTimeout: 10000 - },() => { - createItemProcess.checkLocalHasCMDIVisibility(); - }); - - it('The local.hasCMDI value should be sent in the response after type change', { - retries: { - runMode: 6, - openMode: 6, - }, - defaultCommandTimeout: 10000 - },() => { - createItemProcess.clickOnSelectionInput('dc.type'); - createItemProcess.clickOnTypeSelection('Corpus'); - // Wait because after the type change, the `Save` request is sent, and the page is reloaded. - // The checkbox could be checked during the reloading process. - cy.wait(500); - createItemProcess.checkCheckbox('local_hasCMDI'); - createItemProcess.controlCheckedCheckbox('local_hasCMDI',true); - createItemProcess.clickOnSave(); - cy.reload(); - createItemProcess.controlCheckedCheckbox('local_hasCMDI',true); - }); - - it('should change the step status after accepting/declining the distribution license', { - retries: { - runMode: 6, - openMode: 6, - }, - defaultCommandTimeout: 10000 - },() => { - createItemProcess.checkDistributionLicenseStep(); - createItemProcess.checkDistributionLicenseToggle(); - // default status value is warnings - createItemProcess.checkDistributionLicenseStatus('Warnings'); - // accept the distribution license agreement - createItemProcess.clickOnDistributionLicenseToggle(); - // after accepting the status should be valid - createItemProcess.checkDistributionLicenseStatus('Valid'); - // click on the toggle again and status should be changed to `Warnings` - createItemProcess.clickOnDistributionLicenseToggle(); - createItemProcess.checkDistributionLicenseStatus('Warnings'); - }); - - it('should pick up the license from the license selector', { - retries: { - runMode: 6, - openMode: 6, - }, - defaultCommandTimeout: 10000 - },() => { - createItemProcess.checkLicenseResourceStep(); - // check default value in the license dropdown selection - createItemProcess.checkLicenseSelectionValue('Select a License ...'); - // pop up the license selector modal - createItemProcess.clickOnLicenseSelectorButton(); - // check if the modal was popped up - createItemProcess.checkLicenseSelectorModal(); - // pick up the first license from the modal, it is `Public Domain Mark (PD)` - createItemProcess.pickUpLicenseFromLicenseSelector(); - // check if the picked up license value is seen as selected value in the selection - createItemProcess.checkLicenseSelectionValue('Public Domain Mark (PD)'); - }); - - it('should select the license from the license selection dropdown and change status', { - retries: { - runMode: 6, - openMode: 6, - }, - defaultCommandTimeout: 10000 - },() => { - createItemProcess.checkLicenseResourceStep(); - // check default value in the license dropdown selection - createItemProcess.checkLicenseSelectionValue('Select a License ...'); - // check step status - it should be as warning - createItemProcess.checkResourceLicenseStatus('Warnings'); - // click on the dropdown button to list options - createItemProcess.clickOnLicenseSelectionButton(); - // select `Public Domain Mark (PD)` from the selection - createItemProcess.selectValueFromLicenseSelection(2); - // // selected value should be seen as selected value in the selection - createItemProcess.checkLicenseSelectionValue('GNU General Public License, version 2'); - // // check step status - it should be valid - createItemProcess.checkResourceLicenseStatus('Valid'); - }); - - it('should show warning messages if was selected non-supported license', { - retries: { - runMode: 6, - openMode: 6, - }, - defaultCommandTimeout: 10000 - },() => { - createItemProcess.checkLicenseResourceStep(); - // check default value in the license dropdown selection - createItemProcess.checkLicenseSelectionValue('Select a License ...'); - // check step status - it should be as warning - createItemProcess.checkResourceLicenseStatus('Warnings'); - // click on the dropdown button to list options - createItemProcess.clickOnLicenseSelectionButton(); - // select `Select a License ...` from the selection - this license is not supported - createItemProcess.selectValueFromLicenseSelection(0); - // selected value should be seen as selected value in the selection - createItemProcess.checkLicenseSelectionValue('Select a License ...'); - // check step status - it should an error - createItemProcess.checkResourceLicenseStatus('Errors'); - // error messages should be popped up - createItemProcess.showErrorMustChooseLicense(); - createItemProcess.showErrorNotSupportedLicense(); - }); - - it('The submission should not have the Notice Step', { - retries: { - runMode: 6, - openMode: 6, - }, - defaultCommandTimeout: 10000 - },() => { - createItemProcess.checkClarinNoticeStepNotExist(); - }); -}); - -describe('Create a new submission in the clariah collection', () => { - beforeEach(() => { - // Create a new submission - cy.visit('/submit?collection=' + TEST_SUBMIT_CLARIAH_COLLECTION_UUID + '&entityType=none'); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); - }); -}); - -function addEUSponsor(euSponsorOrder) { - createItemProcess.clickAddMore(1); - // select sponsor type of second sponsor - createItemProcess.clickOnSelectionInput('local.sponsor_COMPLEX_INPUT_0', euSponsorOrder); - createItemProcess.clickOnSelection('EU',euSponsorOrder); - cy.wait(500); - // write suggestion for the eu sponsor - // createItemProcess.writeValueToInput('local.sponsor_COMPLEX_INPUT_1', 'eve', true, euSponsorOrder); - // euSponsorOrder * 2 because sponsor complex type has two ds-dynamic-sponsor-autocomplete inputs - cy.get('ds-dynamic-sponsor-autocomplete').eq(euSponsorOrder * 2).click({force: true}).type('eve'); - // select suggestion - createItemProcess.clickOnSuggestionSelection(euSponsorOrder * 2); - cy.wait(250); - // EU input field should be visible - createItemProcess.checkIsInputVisible('local.sponsor_COMPLEX_INPUT_4', false, euSponsorOrder); -} diff --git a/cypress/e2e/submission.cy.ts b/cypress/e2e/submission.cy.ts deleted file mode 100644 index beee544e233..00000000000 --- a/cypress/e2e/submission.cy.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD, TEST_SUBMIT_COLLECTION_NAME, TEST_SUBMIT_COLLECTION_UUID } from 'cypress/support/e2e'; -import { createItemProcess } from '../support/commands'; - -describe('New Submission page', () => { - // NOTE: We already test that new submissions can be started from MyDSpace in my-dspace.spec.ts - - it('should create a new submission when using /submit path & pass accessibility', () => { - // Test that calling /submit with collection & entityType will create a new submission - cy.visit('/submit?collection='.concat(TEST_SUBMIT_COLLECTION_UUID).concat('&entityType=none')); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - - // Should redirect to /workspaceitems, as we've started a new submission - cy.url().should('include', '/workspaceitems'); - - // The Submission edit form tag should be visible - cy.get('ds-submission-edit').should('be.visible'); - - // A Collection menu button should exist & it's value should be the selected collection - cy.get('#collectionControlsMenuButton span').should('have.text', TEST_SUBMIT_COLLECTION_NAME); - - // 4 sections should be visible by default - cy.get('div#section_traditionalpageone').should('be.visible'); - cy.get('div#section_traditionalpagetwo').should('be.visible'); - cy.get('div#section_upload').should('be.visible'); - cy.get('div#section_license').should('be.visible'); - - // Discard button should work - // Clicking it will display a confirmation, which we will confirm with another click - cy.get('button#discard').click(); - cy.get('button#discard_submit').click(); - }); - - it('should block submission & show errors if required fields are missing', () => { - // Create a new submission - cy.visit('/submit?collection='.concat(TEST_SUBMIT_COLLECTION_UUID).concat('&entityType=none')); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - - // Attempt an immediate deposit without filling out any fields - cy.get('button#deposit').click(); - - // A warning alert should display. - cy.get('ds-notification div.alert-success').should('not.exist'); - cy.get('ds-notification div.alert-warning').should('be.visible'); - - // First section should have an exclamation error in the header - // (as it has required fields) - cy.get('div#traditionalpageone-header i.fa-exclamation-circle').should('be.visible'); - - // Title field should have class "is-invalid" applied, as it's required - cy.get('input#dc_title').should('have.class', 'is-invalid'); - - // Date Year field should also have "is-valid" class - cy.get('input#dc_date_issued_year').should('have.class', 'is-invalid'); - - // FINALLY, cleanup after ourselves. This also exercises the MyDSpace delete button. - // Get our Submission URL, to parse out the ID of this submission - cy.location().then(fullUrl => { - // This will be the full path (/workspaceitems/[id]/edit) - const path = fullUrl.pathname; - // Split on the slashes - const subpaths = path.split('/'); - // Part 2 will be the [id] of the submission - const id = subpaths[2]; - - // Even though form is incomplete, the "Save for Later" button should still work - cy.get('button#saveForLater').click(); - - // "Save for Later" should send us to MyDSpace - cy.url().should('include', '/mydspace'); - - // CLARIN - // // A success alert should be visible - // cy.get('ds-notification div.alert-success').should('be.visible'); - // // Now, dismiss any open alert boxes (may be multiple, as tests run quickly) - // cy.get('[data-dismiss="alert"]').click({multiple: true}); - // - // // This is the GET command that will actually run the search - // cy.intercept('GET', '/server/api/discover/search/objects*').as('search-results'); - // // On MyDSpace, find the submission we just saved via its ID - // cy.get('[data-test="search-box"]').type(id); - // cy.get('[data-test="search-button"]').click(); - // - // // Wait for search results to come back from the above GET command - // cy.wait('@search-results'); - // - // // Delete our created submission & confirm deletion - // cy.get('button#delete_' + id).click(); - // cy.get('button#delete_confirm').click(); - }); - }); - - it('should allow for deposit if all required fields completed & file uploaded', () => { - // Create a new submission - cy.visit('/submit?collection='.concat(TEST_SUBMIT_COLLECTION_UUID).concat('&entityType=none')); - - // This page is restricted, so we will be shown the login form. Fill it out & submit. - cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - - // Fill out all required fields (Title, Date) - cy.get('input#dc_title').type('DSpace logo uploaded via e2e tests'); - cy.get('input#dc_date_issued_year').type('2022'); - - // Confirm the required license by checking checkbox - // (NOTE: requires "force:true" cause Cypress claims this checkbox is covered by its own ) - // CLARIN - createItemProcess.clickOnDistributionLicenseToggle(); - // click on the dropdown button to list options - createItemProcess.clickOnLicenseSelectionButton(); - // select `Public Domain Mark (PD)` from the selection - createItemProcess.selectValueFromLicenseSelection(2); - // // selected value should be seen as selected value in the selection - createItemProcess.checkLicenseSelectionValue('GNU General Public License, version 2'); - // CLARIN - - // Before using Cypress drag & drop, we have to manually trigger the "dragover" event. - // This ensures our UI displays the dropzone that covers the entire submission page. - // (For some reason Cypress drag & drop doesn't trigger this even itself & upload won't work without this trigger) - cy.get('ds-uploader').trigger('dragover'); - - // This is the POST command that will upload the file - cy.intercept('POST', '/server/api/submission/workspaceitems/*').as('upload'); - - // Upload our DSpace logo via drag & drop onto submission form - // cy.get('div#section_upload') - cy.get('div.ds-document-drop-zone').selectFile('src/assets/images/dspace-logo.png', { - action: 'drag-drop' - }); - - // Wait for upload to complete before proceeding - cy.wait('@upload'); - - // CLARIN - // // Wait for deposit button to not be disabled & click it. - // cy.get('button#deposit').should('not.be.disabled').click(); - // - // // No warnings should exist. Instead, just successful deposit alert is displayed - // cy.get('ds-notification div.alert-warning').should('not.exist'); - // cy.get('ds-notification div.alert-success').should('be.visible'); - // CLARIN - }); - -}); diff --git a/cypress/e2e/tombstone.cy.ts b/cypress/e2e/tombstone.cy.ts deleted file mode 100644 index 061b0ab9033..00000000000 --- a/cypress/e2e/tombstone.cy.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { - TEST_ADMIN_PASSWORD, TEST_ADMIN_USER, - TEST_WITHDRAWN_ITEM, - TEST_WITHDRAWN_ITEM_WITH_REASON, - TEST_WITHDRAWN_ITEM_WITH_REASON_AND_AUTHORS, - TEST_WITHDRAWN_REPLACED_ITEM, TEST_WITHDRAWN_REPLACED_ITEM_WITH_AUTHORS -} from '../support/e2e'; - -const ITEMPAGE_WITHDRAWN = '/items/' + TEST_WITHDRAWN_ITEM; -const ITEMPAGE_WITHDRAWN_REASON = '/items/' + TEST_WITHDRAWN_ITEM_WITH_REASON; -const ITEMPAGE_WITHDRAWN_REPLACED = '/items/' + TEST_WITHDRAWN_REPLACED_ITEM; -const ITEMPAGE_WITHDRAWN_REASON_AUTHORS = '/items/' + TEST_WITHDRAWN_ITEM_WITH_REASON_AND_AUTHORS; -const ITEMPAGE_WITHDRAWN_REPLACED_AUTHORS = '/items/' + TEST_WITHDRAWN_REPLACED_ITEM_WITH_AUTHORS; -const TOMBSTONED_ITEM_MESSAGE = 'This item has been withdrawn'; - -// describe('Tombstone Page', () => { -// -// it('should see the items page the item must exists', () => { -// cy.visit(ITEMPAGE_WITHDRAWN); -// // tag must be loaded -// cy.get('ds-item-page').should('exist'); -// -// cy.visit(ITEMPAGE_WITHDRAWN_REASON); -// // tag must be loaded -// cy.get('ds-item-page').should('exist'); -// -// cy.visit(ITEMPAGE_WITHDRAWN_REPLACED); -// // tag must be loaded -// cy.get('ds-item-page').should('exist'); -// }); -// -// it('the user should see withdrawn tombstone', () => { -// cy.visit(ITEMPAGE_WITHDRAWN); -// cy.get('ds-withdrawn-tombstone').should('exist'); -// cy.get('ds-replaced-tombstone').should('not.exist'); -// cy.get('ds-view-tracker').should('not.exist'); -// }); -// -// it('the user should see withdrawn tombstone with the reason', () => { -// cy.visit(ITEMPAGE_WITHDRAWN_REASON); -// cy.get('ds-withdrawn-tombstone').contains(TEST_WITHDRAWN_REASON); -// }); -// -// it('the user should see replacement tombstone with the new destination', () => { -// cy.visit(ITEMPAGE_WITHDRAWN_REPLACED); -// cy.get('ds-replaced-tombstone').contains(TEST_WITHDRAWN_REPLACEMENT); -// }); -// -// it('the user should see withdrawn tombstone with the reason and with authors', () => { -// cy.visit(ITEMPAGE_WITHDRAWN_REASON_AUTHORS); -// cy.get('ds-withdrawn-tombstone').contains(TEST_WITHDRAWN_AUTHORS); -// }); -// -// it('the user should see replacement tombstone with the new destination and with the authors', () => { -// cy.visit(ITEMPAGE_WITHDRAWN_REPLACED_AUTHORS); -// cy.get('ds-replaced-tombstone').contains(TEST_WITHDRAWN_AUTHORS); -// }); -// -// }); - -describe('Admin Tombstone Page', () => { - beforeEach(() => { - cy.visit('/login'); - // Cancel discojuice login - only if it is popped up - cy.wait(500); - cy.get('.discojuice_close').should('exist').click(); - // Login as admin - cy.loginViaForm(TEST_ADMIN_USER, TEST_ADMIN_PASSWORD); - cy.visit('/'); - }); - - it('the admin should see ds-item-page',{ - retries: { - runMode: 8, - openMode: 8, - }, - defaultCommandTimeout: 10000 - }, () => { - cy.visit(ITEMPAGE_WITHDRAWN); - cy.get('ds-item-page').should('exist'); - }); - - it('the admin should see the withdrawn message on the replaced item', { - retries: { - runMode: 8, - openMode: 8, - }, - defaultCommandTimeout: 10000 - }, () => { - cy.visit(ITEMPAGE_WITHDRAWN_REPLACED); - cy.get('ds-item-page').contains(TOMBSTONED_ITEM_MESSAGE); - }); - -}); diff --git a/cypress/plugins/index.ts b/cypress/plugins/index.ts index ead38afb921..cc3dccba38e 100644 --- a/cypress/plugins/index.ts +++ b/cypress/plugins/index.ts @@ -1,5 +1,11 @@ const fs = require('fs'); +// These two global variables are used to store information about the REST API used +// by these e2e tests. They are filled out prior to running any tests in the before() +// method of e2e.ts. They can then be accessed by any tests via the getters below. +let REST_BASE_URL: string; +let REST_DOMAIN: string; + // Plugins enable you to tap into, modify, or extend the internal behavior of Cypress // For more info, visit https://on.cypress.io/plugins-api module.exports = (on, config) => { @@ -30,6 +36,24 @@ module.exports = (on, config) => { } return null; + }, + // Save value of REST Base URL, looked up before all tests. + // This allows other tests to use it easily via getRestBaseURL() below. + saveRestBaseURL(url: string) { + return (REST_BASE_URL = url); + }, + // Retrieve currently saved value of REST Base URL + getRestBaseURL() { + return REST_BASE_URL ; + }, + // Save value of REST Domain, looked up before all tests. + // This allows other tests to use it easily via getRestBaseDomain() below. + saveRestBaseDomain(domain: string) { + return (REST_DOMAIN = domain); + }, + // Retrieve currently saved value of REST Domain + getRestBaseDomain() { + return REST_DOMAIN ; } }); }; diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index e7fbeecf151..cb3a3f9094f 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -5,11 +5,7 @@ import { AuthTokenInfo, TOKENITEM } from 'src/app/core/auth/models/auth-token-info.model'; import { DSPACE_XSRF_COOKIE, XSRF_REQUEST_HEADER } from 'src/app/core/xsrf/xsrf.constants'; - -// 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 'login()'. -export const FALLBACK_TEST_REST_BASE_URL = 'http://localhost:8080/server'; -export const FALLBACK_TEST_REST_DOMAIN = 'localhost'; +import { v4 as uuidv4 } from 'uuid'; // Declare Cypress namespace to help with Intellisense & code completion in IDEs // ALL custom commands MUST be listed here for code completion to work @@ -41,6 +37,13 @@ declare global { * @param dsoType type of DSpace Object (e.g. "item", "collection", "community") */ generateViewEvent(uuid: string, dsoType: string): typeof generateViewEvent; + + /** + * Create a new CSRF token and add to required Cookie. CSRF Token is returned + * in chainable in order to allow it to be sent also in required CSRF header. + * @returns Chainable reference to allow CSRF token to also be sent in header. + */ + createCSRFCookie(): Chainable; } } } @@ -54,59 +57,32 @@ declare global { * @param password password to login as */ function login(email: string, password: string): void { - // 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 the URL of our REST API. Have a fallback ready, just in case 'rest.baseUrl' cannot be found. - 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 { - //console.log("Found 'rest.baseUrl' in config.json. Using this REST API for login: ".concat(config.rest.baseUrl)); - baseRestUrl = config.rest.baseUrl; - } - - // Now find domain of our REST API, again with a fallback. - 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; - } - - // Create a fake CSRF Token. Set it in the required server-side cookie - const csrfToken = 'fakeLoginCSRFToken'; - cy.setCookie(DSPACE_XSRF_COOKIE, csrfToken, { 'domain': baseDomain }); - - // Now, send login POST request including that CSRF token - cy.request({ - method: 'POST', - url: baseRestUrl + '/api/authn/login', - headers: { [XSRF_REQUEST_HEADER]: csrfToken}, - form: true, // indicates the body should be form urlencoded - body: { user: email, password: password } - }).then((resp) => { - // We expect a successful login - expect(resp.status).to.eq(200); - // We expect to have a valid authorization header returned (with our auth token) - expect(resp.headers).to.have.property('authorization'); + // Create a fake CSRF cookie/token to use in POST + cy.createCSRFCookie().then((csrfToken: string) => { + // get our REST API's base URL, also needed for POST + cy.task('getRestBaseURL').then((baseRestUrl: string) => { + // Now, send login POST request including that CSRF token + cy.request({ + method: 'POST', + url: baseRestUrl + '/api/authn/login', + headers: { [XSRF_REQUEST_HEADER]: csrfToken}, + form: true, // indicates the body should be form urlencoded + body: { user: email, password: password } + }).then((resp) => { + // We expect a successful login + expect(resp.status).to.eq(200); + // We expect to have a valid authorization header returned (with our auth token) + expect(resp.headers).to.have.property('authorization'); - // Initialize our AuthTokenInfo object from the authorization header. - const authheader = resp.headers.authorization as string; - const authinfo: AuthTokenInfo = new AuthTokenInfo(authheader); + // Initialize our AuthTokenInfo object from the authorization header. + const authheader = resp.headers.authorization as string; + const authinfo: AuthTokenInfo = new AuthTokenInfo(authheader); - // Save our AuthTokenInfo object to our dsAuthInfo UI cookie - // This ensures the UI will recognize we are logged in on next "visit()" - cy.setCookie(TOKENITEM, JSON.stringify(authinfo)); + // Save our AuthTokenInfo object to our dsAuthInfo UI cookie + // This ensures the UI will recognize we are logged in on next "visit()" + cy.setCookie(TOKENITEM, JSON.stringify(authinfo)); + }); }); - - // Remove cookie with fake CSRF token, as it's no longer needed - cy.clearCookie(DSPACE_XSRF_COOKIE); }); } // Add as a Cypress command (i.e. assign to 'cy.login') @@ -117,25 +93,47 @@ Cypress.Commands.add('login', login); * @param email email to login as * @param password password to login as */ -function loginViaForm(email: string, password: string): void { - cy.wait(500); - cy.get('.discojuice_close').should('exist').click(); - // Enter email - cy.get('ds-log-in [data-test="email"]').type(email); - // Enter password - cy.get('ds-log-in [data-test="password"]').type(password); - // Click login button - cy.get('ds-log-in [data-test="login-button"]').click(); +// Cypress custom command for form-based login with intercept and redirect assertion +// Cypress custom command for form-based login with intercept and redirect assertion +function loginViaForm( + email: string, + password: string +): void { + // Spy on the authentication request (allow query params) + cy.intercept({ method: 'POST', url: '/server/api/authn/login*' }).as('auth'); + + // Optionally close the DiscoJuice popup if present + cy.wait(500); + cy.get('.discojuice_close').should('exist').click(); + + // Fill in credentials + cy.get('[data-test="email"]').should('be.visible').type(email); + cy.get('[data-test="password"]').type(password); + + // Submit the form + cy.get('[data-test="login-button"]').click(); + + // Wait for authentication to complete (if request is made) + // cy.wait('@auth', { timeout: 10000 }).then(() => { + // // Wait for redirect + // cy.url({ timeout: 10000 }).should('include', expectedRedirect); + // }, + // (err) => { + // // If the request wasn't made, still check URL + // Cypress.log({ name: 'auth', message: 'Auth request not detected, checking URL directly.' }); + // cy.url({ timeout: 10000 }).should('include', expectedRedirect); + // } + // ); } // Add as a Cypress command (i.e. assign to 'cy.loginViaForm') Cypress.Commands.add('loginViaForm', loginViaForm); -// Do not fail test if an uncaught exception occurs in the application -Cypress.on('uncaught:exception', (err, runnable) => { - // returning false here prevents Cypress from - // failing the test - return false -}) +// // Do not fail test if an uncaught exception occurs in the application +// Cypress.on('uncaught:exception', (err, runnable) => { +// // returning false here prevents Cypress from +// // failing the test +// return false; +// }); /** @@ -150,54 +148,28 @@ Cypress.on('uncaught:exception', (err, runnable) => { * @param dsoType type of DSpace Object (e.g. "item", "collection", "community") */ function generateViewEvent(uuid: string, dsoType: string): void { - // 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 the URL of our REST API. Have a fallback ready, just in case 'rest.baseUrl' cannot be found. - 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; - } - - // Now find domain of our REST API, again with a fallback. - 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; - } - - // Create a fake CSRF Token. Set it in the required server-side cookie - const csrfToken = 'fakeGenerateViewEventCSRFToken'; - cy.setCookie(DSPACE_XSRF_COOKIE, csrfToken, { 'domain': baseDomain }); - - // Now, send 'statistics/viewevents' POST request including that fake CSRF token in required header - cy.request({ - method: 'POST', - url: baseRestUrl + '/api/statistics/viewevents', - headers: { - [XSRF_REQUEST_HEADER] : csrfToken, - // use a known public IP address to avoid being seen as a "bot" - 'X-Forwarded-For': '1.1.1.1', - // Use a user-agent of a Firefox browser on Windows. This again avoids being seen as a "bot" - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0', - }, - //form: true, // indicates the body should be form urlencoded - body: { targetId: uuid, targetType: dsoType }, - }).then((resp) => { - // We expect a 201 (which means statistics event was created) - expect(resp.status).to.eq(201); + // Create a fake CSRF cookie/token to use in POST + cy.createCSRFCookie().then((csrfToken: string) => { + // get our REST API's base URL, also needed for POST + cy.task('getRestBaseURL').then((baseRestUrl: string) => { + // Now, send 'statistics/viewevents' POST request including that fake CSRF token in required header + cy.request({ + method: 'POST', + url: baseRestUrl + '/api/statistics/viewevents', + headers: { + [XSRF_REQUEST_HEADER] : csrfToken, + // use a known public IP address to avoid being seen as a "bot" + 'X-Forwarded-For': '1.1.1.1', + // Use a user-agent of a Firefox browser on Windows. This again avoids being seen as a "bot" + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0', + }, + //form: true, // indicates the body should be form urlencoded + body: { targetId: uuid, targetType: dsoType }, + }).then((resp) => { + // We expect a 201 (which means statistics event was created) + expect(resp.status).to.eq(201); + }); }); - - // Remove cookie with fake CSRF token, as it's no longer needed - cy.clearCookie(DSPACE_XSRF_COOKIE); }); } // Add as a Cypress command (i.e. assign to 'cy.generateViewEvent') @@ -369,3 +341,26 @@ export const createItemProcess = { }; + +/** + * Can be used by tests to generate a random XSRF/CSRF token and save it to + * the required XSRF/CSRF cookie for usage when sending POST requests or similar. + * The generated CSRF token is returned in a Chainable to allow it to be also sent + * in the CSRF HTTP Header. + * @returns a Cypress Chainable which can be used to get the generated CSRF Token + */ +function createCSRFCookie(): Cypress.Chainable { + // Generate a new token which is a random UUID + const csrfToken: string = uuidv4(); + + // Save it to our required cookie + cy.task('getRestBaseDomain').then((baseDomain: string) => { + // Create a fake CSRF Token. Set it in the required server-side cookie + cy.setCookie(DSPACE_XSRF_COOKIE, csrfToken, { 'domain': baseDomain }); + }); + + // return the generated token wrapped in a chainable + return cy.wrap(csrfToken); +} +// Add as a Cypress command (i.e. assign to 'cy.createCSRFCookie') +Cypress.Commands.add('createCSRFCookie', createCSRFCookie); diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index b9c8afa0bbc..10e785e1845 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -19,30 +19,54 @@ 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}'); -}); - -// For better stability between tests, we visit "about:blank" (i.e. blank page) after each test. -// This ensures any remaining/outstanding XHR requests are killed, so they don't affect the next test. -// Borrowed from: https://glebbahmutov.com/blog/visit-blank-page-between-tests/ -/*afterEach(() => { - cy.window().then((win) => { - win.location.href = 'about:blank'; - }); -});*/ + // 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) - +// 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'; // 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'; diff --git a/docker/cli.assetstore.yml b/docker/cli.assetstore.yml index ef5cf95caf6..c120243a337 100644 --- a/docker/cli.assetstore.yml +++ b/docker/cli.assetstore.yml @@ -18,8 +18,6 @@ networks: services: dspace-cli: - networks: - dspacenet: {} environment: # This assetstore zip is available from https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data - LOADASSETS=https://github.com/DSpace-Labs/AIP-Files/releases/download/demo-entities-data/assetstore.tar.gz @@ -34,5 +32,6 @@ services: tar xvfz /tmp/assetstore.tar.gz fi + /dspace/bin/dspace index-discovery -b /dspace/bin/dspace oai import /dspace/bin/dspace oai clean-cache diff --git a/docker/cli.yml b/docker/cli.yml index 9b2175491a9..6a3c95b090d 100644 --- a/docker/cli.yml +++ b/docker/cli.yml @@ -6,6 +6,19 @@ # http://www.dspace.org/license/ # +# +# This is a copy of the docker-compose-cli.yml that is available in the DSpace/DSpace +# (Backend) at: +# https://github.com/DSpace/DSpace/blob/main/docker-compose-cli.yml +# +# Therefore, it should be kept in sync with that file +networks: + # Default to using network named 'dspacenet' from docker-compose-rest.yml. + # Its full name will be prepended with the project name (e.g. "-p d7" means it will be named "d7_dspacenet") + # If COMPOSITE_PROJECT_NAME is missing, default value will be "docker" (name of folder this file is in) + default: + name: ${COMPOSE_PROJECT_NAME:-docker}_dspacenet + external: true services: dspace-cli: image: "${DOCKER_OWNER:-dataquest}/dspace-cli:${DSPACE_VER:-dspace-7_x}" @@ -45,14 +58,9 @@ services: - ./local.cfg:/dspace/config/local.cfg entrypoint: /dspace/bin/dspace command: help - networks: - - dspacenet tty: true stdin_open: true volumes: assetstore: dspace_cli_logs: - -networks: - dspacenet: diff --git a/docker/db.entities.yml b/docker/db.entities.yml index d927af04df7..cc5620423e2 100644 --- a/docker/db.entities.yml +++ b/docker/db.entities.yml @@ -14,7 +14,7 @@ # # Therefore, it should be kept in sync with that file services: dspacedb: - image: dspace/dspace-postgres-pgcrypto:loadsql + image: ${DOCKER_REGISTRY:-docker.io}/${DOCKER_OWNER:-dspace}/dspace-postgres-pgcrypto:${DSPACE_VER:-dspace-7_x}-loadsql environment: # This LOADSQL should be kept in sync with the URL in DSpace/DSpace # This SQL is available from https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data diff --git a/docker/docker-compose-ci.yml b/docker/docker-compose-ci.yml index 5e930b7ba51..b81366e6861 100644 --- a/docker/docker-compose-ci.yml +++ b/docker/docker-compose-ci.yml @@ -32,11 +32,12 @@ services: # Tell Statistics to commit all views immediately instead of waiting on Solr's autocommit. # This allows us to generate statistics in e2e tests so that statistics pages can be tested thoroughly. solr__D__statistics__P__autoCommit: 'false' + LOGGING_CONFIG: /dspace/config/log4j2-container.xml depends_on: - dspacedb image: ${DSPACE_CI_IMAGE:-dataquest/dspace:dspace-7_x-test} networks: - dspacenet: + - dspacenet ports: - published: 8080 target: 8080 @@ -44,8 +45,6 @@ services: tty: true volumes: - assetstore:/dspace/assetstore - # Mount DSpace's solr configs to a volume, so that we can share to 'dspacesolr' container (see below) - - solr_configs:/dspace/solr # Ensure that the database is ready BEFORE starting tomcat # 1. While a TCP connection to dspacedb port 5432 is not available, continue to sleep # 2. Then, run database migration to init database tables (including any out-of-order ignored migrations, if any) @@ -62,18 +61,23 @@ services: # NOTE: This is customized to use our loadsql image, so that we are using a database with existing test data dspacedb: container_name: dspacedb + image: ${DSPACE_DB_IMAGE:-dspace/dspace-postgres-pgcrypto:loadsql} environment: # This LOADSQL should be kept in sync with the LOADSQL in # https://github.com/DSpace/DSpace/blob/main/dspace/src/main/docker-compose/db.entities.yml # This SQL is available from https://github.com/DSpace-Labs/AIP-Files/releases/tag/demo-entities-data LOADSQL: https://github.com/dataquest-dev/DSpace/releases/download/data/dspace-test-database-dump_29.1.2024.sql PGDATA: /pgdata - image: ${DSPACE_DB_IMAGE:-dspace/dspace-postgres-pgcrypto:loadsql} + POSTGRES_PASSWORD: dspace networks: - dspacenet: + - dspacenet + ports: + - published: 5432 + target: 5432 stdin_open: true tty: true volumes: + # Keep Postgres data directory between reboots - pgdata:/pgdata # DSpace Solr container dspacesolr: @@ -83,7 +87,7 @@ services: depends_on: - dspace networks: - dspacenet: + - dspacenet ports: - published: 8983 target: 8983 @@ -91,9 +95,6 @@ services: tty: true working_dir: /var/solr/data volumes: - # Mount our "solr_configs" volume available under the Solr's configsets folder (in a 'dspace' subfolder) - # This copies the Solr configs from main 'dspace' container into 'dspacesolr' via that volume - - solr_configs:/opt/solr/server/solr/configsets/dspace # Keep Solr data directory between reboots - solr_data:/var/solr/data # Initialize all DSpace Solr cores using the mounted configsets (see above), then start Solr @@ -102,14 +103,16 @@ services: - '-c' - | init-var-solr - precreate-core authority /opt/solr/server/solr/configsets/dspace/authority - precreate-core oai /opt/solr/server/solr/configsets/dspace/oai - precreate-core search /opt/solr/server/solr/configsets/dspace/search - precreate-core statistics /opt/solr/server/solr/configsets/dspace/statistics + precreate-core authority /opt/solr/server/solr/configsets/authority + cp -r /opt/solr/server/solr/configsets/authority/* authority + precreate-core oai /opt/solr/server/solr/configsets/oai + cp -r /opt/solr/server/solr/configsets/oai/* oai + precreate-core search /opt/solr/server/solr/configsets/search + cp -r /opt/solr/server/solr/configsets/search/* search + precreate-core statistics /opt/solr/server/solr/configsets/statistics + cp -r /opt/solr/server/solr/configsets/statistics/* statistics exec solr -f volumes: assetstore: pgdata: solr_data: - # Special volume used to share Solr configs from 'dspace' to 'dspacesolr' container (see above) - solr_configs: diff --git a/docker/docker-compose-dist.yml b/docker/docker-compose-dist.yml index 1f4d2d7f5e6..88e5be16a5d 100644 --- a/docker/docker-compose-dist.yml +++ b/docker/docker-compose-dist.yml @@ -26,7 +26,7 @@ services: DSPACE_REST_HOST: demo.dspace.org DSPACE_REST_PORT: 443 DSPACE_REST_NAMESPACE: /server - image: dspace/dspace-angular:dspace-7_x-dist + image: "${DOCKER_REGISTRY:-docker.io}/${DOCKER_OWNER:-dspace}/dspace-angular:${DSPACE_VER:-dspace-7_x}-dist" build: context: .. dockerfile: Dockerfile.dist diff --git a/docker/docker-compose-rest.yml b/docker/docker-compose-rest.yml index 4ef37744599..cd4f26c062c 100644 --- a/docker/docker-compose-rest.yml +++ b/docker/docker-compose-rest.yml @@ -42,6 +42,7 @@ services: # proxies.trusted.ipranges: This setting is required for a REST API running in Docker to trust requests # from the host machine. This IP range MUST correspond to the 'dspacenet' subnet defined above. proxies__P__trusted__P__ipranges: '172.2${INSTANCE}.0' + LOGGING_CONFIG: /dspace/config/log4j2-container.xml #S3 config assetstore__P__index__P__primary: ${S3_STORAGE:-0} assetstore__P__s3__P__enabled: ${S3_ENABLED:-false} @@ -57,7 +58,7 @@ services: depends_on: - dspacedb networks: - dspacenet: + - dspacenet ports: # BE server port - published: 808${INSTANCE} @@ -118,7 +119,7 @@ services: POSTGRES_PASSWORD: dspace image: ${DSPACE_DB_IMAGE:-dataquest/dspace-postgres-pgcrypto:dspace-7_x} networks: - dspacenet: + - dspacenet ports: - published: 543${INSTANCE} target: 543${INSTANCE} @@ -126,6 +127,7 @@ services: stdin_open: true tty: true volumes: + # Keep Postgres data directory between reboots - pgdata:/pgdata command: -p 543${INSTANCE} # DSpace Solr container @@ -136,7 +138,7 @@ services: container_name: dspacesolr${INSTANCE} image: ${DSPACE_SOLR_IMAGE:-dataquest/dspace-solr:dspace-7_x} networks: - dspacenet: + - dspacenet ports: - published: 898${INSTANCE} target: 898${INSTANCE} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6b5d32efff4..09f23c8a5de 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -6,6 +6,9 @@ # http://www.dspace.org/license/ # +# Docker Compose for running the DSpace Angular UI for testing/development +# Requires also running a REST API backend (either locally or remotely), +# for example via 'docker-compose-rest.yml' networks: dspacenet: services: diff --git a/package.json b/package.json index 2e863135534..a39c42346db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dspace-angular", - "version": "7.6.1", + "version": "7.6.3", "scripts": { "ng": "ng", "config:watch": "nodemon", @@ -12,7 +12,6 @@ "preserve": "yarn base-href", "serve": "ts-node --project ./tsconfig.ts-node.json scripts/serve.ts", "serve:ssr": "node dist/server/main", - "analyze": "webpack-bundle-analyzer dist/browser/stats.json", "build": "ng build --configuration development", "build:stats": "ng build --stats-json", "build:prod": "cross-env NODE_ENV=production yarn run build:ssr", @@ -49,27 +48,20 @@ "https": false }, "private": true, - "resolutions": { - "minimist": "^1.2.5", - "webdriver-manager": "^12.1.8", - "ts-node": "10.2.1" - }, "dependencies": { - "@angular/animations": "^15.2.8", - "@angular/cdk": "^15.2.8", - "@angular/common": "^15.2.8", - "@angular/compiler": "^15.2.8", - "@angular/core": "^15.2.8", - "@angular/forms": "^15.2.8", - "@angular/localize": "15.2.8", - "@angular/platform-browser": "^15.2.8", - "@angular/platform-browser-dynamic": "^15.2.8", - "@angular/platform-server": "^15.2.8", - "@angular/router": "^15.2.8", - "@babel/runtime": "7.21.0", + "@angular/animations": "^15.2.10", + "@angular/cdk": "^15.2.9", + "@angular/common": "^15.2.10", + "@angular/compiler": "^15.2.10", + "@angular/core": "^15.2.10", + "@angular/forms": "^15.2.10", + "@angular/localize": "15.2.10", + "@angular/platform-browser": "^15.2.10", + "@angular/platform-browser-dynamic": "^15.2.10", + "@angular/platform-server": "^15.2.10", + "@angular/router": "^15.2.10", + "@babel/runtime": "7.26.0", "@kolkov/ngx-gallery": "^2.0.1", - "@material-ui/core": "^4.11.0", - "@material-ui/icons": "^4.11.3", "@ng-bootstrap/ng-bootstrap": "^11.0.0", "@ng-dynamic-forms/core": "^15.0.0", "@ng-dynamic-forms/ui-ng-bootstrap": "^15.0.0", @@ -80,133 +72,132 @@ "@ngx-translate/core": "^14.0.0", "@nth-cloud/ng-toggle": "11.0.0", "@nicky-lenaers/ngx-scroll-to": "^14.0.0", - "@types/grecaptcha": "^3.0.4", "angular-idle-preload": "3.0.0", - "angulartics2": "^12.2.0", - "axios": "^1.6.0", + "angulartics2": "^12.2.1", + "axios": "^1.7.9", "bootstrap": "^4.6.1", "cerialize": "0.1.18", "cli-progress": "^3.12.0", "colors": "^1.4.0", "ng2-charts": "4.1.1", "chart.js": "4.3.3", - "compression": "^1.7.4", - "cookie-parser": "1.4.6", - "core-js": "^3.30.1", - "date-fns": "^2.29.3", + "compression": "^1.7.5", + "cookie-parser": "1.4.7", + "core-js": "^3.40.0", + "date-fns": "^2.30.0", "date-fns-tz": "^1.3.7", "deepmerge": "^4.3.1", - "ejs": "^3.1.9", - "express": "^4.18.2", + "ejs": "^3.1.10", + "express": "^4.21.2", "express-rate-limit": "^5.1.3", "fast-json-patch": "^3.1.1", "filesize": "^6.1.0", - "http-proxy-middleware": "^1.0.5", + "http-proxy-middleware": "^2.0.7", "http-terminator": "^3.2.0", - "isbot": "^3.6.10", + "isbot": "^5.1.21", "js-cookie": "2.2.1", "js-yaml": "^4.1.0", "json5": "^2.2.3", - "jsonschema": "1.4.1", + "jsonschema": "1.5.0", "jwt-decode": "^3.1.2", - "klaro": "^0.7.18", + "klaro": "^0.7.21", "lindat-common": "^1.5.0", "lodash": "^4.17.21", "lru-cache": "^7.14.1", - "markdown-it": "^13.0.1", + "markdown-it": "^13.0.2", "markdown-it-mathjax3": "^4.3.2", - "mirador": "^3.3.0", + "mirador": "^3.4.3", "mirador-dl-plugin": "^0.13.0", - "mirador-share-plugin": "^0.11.0", + "mirador-share-plugin": "^0.16.0", "morgan": "^1.10.0", - "ng-mocks": "^14.10.0", "ng2-file-upload": "1.4.0", "ng2-nouislider": "^2.0.0", "ngx-infinite-scroll": "^15.0.0", "ngx-pagination": "6.0.3", + "ngx-skeleton-loader": "^7.0.0", "ngx-sortablejs": "^11.1.0", - "ngx-ui-switch": "^14.0.3", - "nouislider": "^15.7.1", - "pem": "1.14.7", - "prop-types": "^15.8.1", - "react-copy-to-clipboard": "^5.1.0", - "reflect-metadata": "^0.1.13", + "ngx-ui-switch": "^14.1.0", + "nouislider": "^15.8.1", + "pem": "1.14.8", + "reflect-metadata": "^0.2.2", "rxjs": "^7.8.0", - "sanitize-html": "^2.10.0", - "sortablejs": "1.15.0", + "sanitize-html": "^2.14.0", + "sortablejs": "1.15.6", "uuid": "^8.3.2", - "webfontloader": "1.6.28", - "zone.js": "~0.11.5" + "zone.js": "~0.13.3" }, "devDependencies": { "@angular-builders/custom-webpack": "~15.0.0", - "@angular-devkit/build-angular": "^15.2.6", + "@angular-devkit/build-angular": "^15.2.11", "@angular-eslint/builder": "15.2.1", "@angular-eslint/eslint-plugin": "15.2.1", "@angular-eslint/eslint-plugin-template": "15.2.1", "@angular-eslint/schematics": "15.2.1", "@angular-eslint/template-parser": "15.2.1", - "@angular/cli": "^15.2.6", - "@angular/compiler-cli": "^15.2.8", - "@angular/language-service": "^15.2.8", + "@angular/cli": "^16.2.16", + "@angular/compiler-cli": "^15.2.10", + "@angular/language-service": "^15.2.10", "@cypress/schematic": "^1.5.0", - "@fortawesome/fontawesome-free": "^6.4.0", + "@fortawesome/fontawesome-free": "^6.7.2", + "@material-ui/core": "^4.12.4", + "@material-ui/icons": "^4.11.3", "@ngrx/store-devtools": "^15.4.0", "@ngtools/webpack": "^15.2.6", "@nguniversal/builders": "^15.2.1", - "@types/deep-freeze": "0.1.2", - "@types/ejs": "^3.1.2", - "@types/express": "^4.17.17", + "@types/deep-freeze": "0.1.5", + "@types/ejs": "^3.1.5", + "@types/express": "^4.17.21", + "@types/grecaptcha": "^3.0.9", "@types/jasmine": "~3.6.0", "@types/js-cookie": "2.2.6", - "@types/lodash": "^4.14.194", - "@types/node": "^14.14.9", - "@types/sanitize-html": "^2.9.0", - "@typescript-eslint/eslint-plugin": "^5.59.1", - "@typescript-eslint/parser": "^5.59.1", - "axe-core": "^4.7.2", + "@types/lodash": "^4.17.14", + "@types/node": "^14.18.63", + "@types/sanitize-html": "^2.13.0", + "@typescript-eslint/eslint-plugin": "^5.62.0", + "@typescript-eslint/parser": "^5.62.0", + "axe-core": "^4.10.2", "compression-webpack-plugin": "^9.2.0", "copy-webpack-plugin": "^6.4.1", "cross-env": "^7.0.3", - "cypress": "12.17.4", - "cypress-axe": "^1.4.0", + "csstype": "^3.1.3", + "cypress": "^13.17.0", + "cypress-axe": "^1.5.0", "deep-freeze": "0.0.1", "eslint": "^8.39.0", - "eslint-plugin-deprecation": "^1.4.1", - "eslint-plugin-import": "^2.27.5", - "eslint-plugin-jsdoc": "^39.6.4", - "eslint-plugin-jsonc": "^2.6.0", + "eslint-plugin-deprecation": "^1.5.0", + "eslint-plugin-import": "^2.31.0", + "eslint-plugin-jsdoc": "^45.0.0", + "eslint-plugin-jsonc": "^2.18.2", "eslint-plugin-lodash": "^7.4.0", "eslint-plugin-unused-imports": "^2.0.0", - "express-static-gzip": "^2.1.7", + "express-static-gzip": "^2.2.0", "jasmine-core": "^3.8.0", "jasmine-marbles": "0.9.2", - "karma": "^6.4.2", + "karma": "^6.4.4", "karma-chrome-launcher": "~3.2.0", "karma-coverage-istanbul-reporter": "~3.0.3", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "^1.5.0", "karma-mocha-reporter": "2.2.5", + "ng-mocks": "^14.13.2", "ngx-mask": "^13.1.7", "nodemon": "^2.0.22", - "postcss": "^8.4", - "postcss-apply": "0.12.0", + "postcss": "^8.5", "postcss-import": "^14.0.0", "postcss-loader": "^4.0.3", "postcss-preset-env": "^7.4.2", - "postcss-responsive-type": "1.0.0", + "prop-types": "^15.8.1", "react": "^16.14.0", + "react-copy-to-clipboard": "^5.1.0", "react-dom": "^16.14.0", "rimraf": "^3.0.2", - "rxjs-spy": "^8.0.2", - "sass": "~1.62.0", + "sass": "~1.83.4", "sass-loader": "^12.6.0", "sass-resources-loader": "^2.2.5", "ts-node": "^8.10.2", "typescript": "~4.8.4", "webpack": "5.76.1", - "webpack-bundle-analyzer": "^4.8.0", "webpack-cli": "^4.2.0", - "webpack-dev-server": "^4.13.3" + "webpack-dev-server": "^4.15.2" } } diff --git a/postcss.config.js b/postcss.config.js index df092d1d39f..f8b9666b312 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,8 +1,6 @@ module.exports = { plugins: [ require('postcss-import')(), - require('postcss-preset-env')(), - require('postcss-apply')(), - require('postcss-responsive-type')() + require('postcss-preset-env')() ] }; diff --git a/server.ts b/server.ts index 93f3e868763..cfab230ef59 100644 --- a/server.ts +++ b/server.ts @@ -28,7 +28,7 @@ import * as expressStaticGzip from 'express-static-gzip'; /* eslint-enable import/no-namespace */ import axios from 'axios'; import LRU from 'lru-cache'; -import isbot from 'isbot'; +import { isbot } from 'isbot'; import { createCertificate } from 'pem'; import { createServer } from 'https'; import { json } from 'body-parser'; @@ -79,6 +79,9 @@ let anonymousCache: LRU; // extend environment with app config for server extendEnvironmentWithAppConfig(environment, appConfig); +// The REST server base URL +const REST_BASE_URL = environment.rest.ssrBaseUrl || environment.rest.baseUrl; + // The Express app is exported so that it can be used by serverless Functions. export function app() { @@ -176,7 +179,7 @@ export function app() { * Proxy the sitemaps */ router.use('/sitemap**', createProxyMiddleware({ - target: `${environment.rest.baseUrl}/sitemaps`, + target: `${REST_BASE_URL}/sitemaps`, pathRewrite: path => path.replace(environment.ui.nameSpace, '/'), changeOrigin: true })); @@ -185,7 +188,7 @@ export function app() { * Proxy the linksets */ router.use('/signposting**', createProxyMiddleware({ - target: `${environment.rest.baseUrl}`, + target: `${REST_BASE_URL}`, pathRewrite: path => path.replace(environment.ui.nameSpace, '/'), changeOrigin: true })); @@ -238,7 +241,7 @@ export function app() { * The callback function to serve server side angular */ function ngApp(req, res) { - if (environment.universal.preboot) { + if (environment.universal.preboot && req.method === 'GET' && (req.path === '/' || environment.universal.paths.some(pathPrefix => req.path.startsWith(pathPrefix)))) { // Render the page to user via SSR (server side rendering) serverSideRender(req, res); } else { @@ -269,6 +272,11 @@ function serverSideRender(req, res, sendToUser: boolean = true) { requestUrl: req.originalUrl, }, (err, data) => { if (hasNoValue(err) && hasValue(data)) { + // Replace REST URL with UI URL + if (environment.universal.replaceRestUrl && REST_BASE_URL !== environment.rest.baseUrl) { + data = data.replace(new RegExp(REST_BASE_URL, 'g'), environment.rest.baseUrl); + } + // save server side rendered page to cache (if any are enabled) saveToCache(req, data); if (sendToUser) { @@ -621,7 +629,7 @@ function start() { * The callback function to serve health check requests */ function healthCheck(req, res) { - const baseUrl = `${environment.rest.baseUrl}${environment.actuators.endpointPath}`; + const baseUrl = `${REST_BASE_URL}${environment.actuators.endpointPath}`; axios.get(baseUrl) .then((response) => { res.status(response.status).send(response.data); diff --git a/src/app/access-control/bulk-access/browse/bulk-access-browse.component.html b/src/app/access-control/bulk-access/browse/bulk-access-browse.component.html index c716aedb8b3..131cb49d6be 100644 --- a/src/app/access-control/bulk-access/browse/bulk-access-browse.component.html +++ b/src/app/access-control/bulk-access/browse/bulk-access-browse.component.html @@ -1,15 +1,15 @@ -
-
-
+
+
@@ -17,51 +17,52 @@
-
-
+ diff --git a/src/app/access-control/bulk-access/bulk-access.component.html b/src/app/access-control/bulk-access/bulk-access.component.html index 382caf85f46..cda6b805bcc 100644 --- a/src/app/access-control/bulk-access/bulk-access.component.html +++ b/src/app/access-control/bulk-access/bulk-access.component.html @@ -1,4 +1,5 @@
+

{{ 'admin.access-control.bulk-access.title' | translate }}

@@ -9,7 +10,7 @@ -
diff --git a/src/app/access-control/bulk-access/settings/bulk-access-settings.component.html b/src/app/access-control/bulk-access/settings/bulk-access-settings.component.html index 01f36ef03f4..c41053874e7 100644 --- a/src/app/access-control/bulk-access/settings/bulk-access-settings.component.html +++ b/src/app/access-control/bulk-access/settings/bulk-access-settings.component.html @@ -1,13 +1,13 @@ -
- -
-
+
+
@@ -15,7 +15,7 @@
- + diff --git a/src/app/access-control/epeople-registry/epeople-registry.component.html b/src/app/access-control/epeople-registry/epeople-registry.component.html index 4979f858193..540f57032bf 100644 --- a/src/app/access-control/epeople-registry/epeople-registry.component.html +++ b/src/app/access-control/epeople-registry/epeople-registry.component.html @@ -2,7 +2,7 @@
- +

{{labelPrefix + 'head' | translate}}

- +
+ {{'admin.registries.bitstream-formats.select' | translate}}} {{bitstreamFormat.id}} @@ -45,13 +46,13 @@
-
diff --git a/src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts b/src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts index 8a44240b7e2..8041e21206b 100644 --- a/src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts +++ b/src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.spec.ts @@ -15,8 +15,8 @@ import { NotificationsService } from '../../../shared/notifications/notification import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub'; import { BitstreamFormat } from '../../../core/shared/bitstream-format.model'; import { BitstreamFormatSupportLevel } from '../../../core/shared/bitstream-format-support-level'; -import { cold, getTestScheduler, hot } from 'jasmine-marbles'; -import { TestScheduler } from 'rxjs/testing'; +import { XSRFService } from '../../../core/xsrf/xsrf.service'; +import { hot } from 'jasmine-marbles'; import { createNoContentRemoteDataObject$, createSuccessfulRemoteDataObject, @@ -31,7 +31,6 @@ describe('BitstreamFormatsComponent', () => { let comp: BitstreamFormatsComponent; let fixture: ComponentFixture; let bitstreamFormatService; - let scheduler: TestScheduler; let notificationsServiceStub; let paginationService; @@ -86,8 +85,6 @@ describe('BitstreamFormatsComponent', () => { const initAsync = () => { notificationsServiceStub = new NotificationsServiceStub(); - scheduler = getTestScheduler(); - bitstreamFormatService = jasmine.createSpyObj('bitstreamFormatService', { findAll: observableOf(mockFormatsRD), find: createSuccessfulRemoteDataObject$(mockFormatsList[0]), @@ -108,7 +105,8 @@ describe('BitstreamFormatsComponent', () => { { provide: BitstreamFormatDataService, useValue: bitstreamFormatService }, { provide: HostWindowService, useValue: new HostWindowServiceStub(0) }, { provide: NotificationsService, useValue: notificationsServiceStub }, - { provide: PaginationService, useValue: paginationService } + { provide: PaginationService, useValue: paginationService }, + { provide: XSRFService, useValue: {} }, ] }).compileComponents(); }; @@ -178,17 +176,17 @@ describe('BitstreamFormatsComponent', () => { beforeEach(waitForAsync(initAsync)); beforeEach(initBeforeEach); it('should return an observable of true if the provided bistream is in the list returned by the service', () => { - const result = comp.isSelected(bitstreamFormat1); - - expect(result).toBeObservable(cold('b', { b: true })); + comp.selectedBitstreamFormatIDs().subscribe((selectedBitstreamFormatIDs: string[]) => { + expect(selectedBitstreamFormatIDs).toContain(bitstreamFormat1.id); + }); }); it('should return an observable of false if the provided bistream is not in the list returned by the service', () => { const format = new BitstreamFormat(); format.uuid = 'new'; - const result = comp.isSelected(format); - - expect(result).toBeObservable(cold('b', { b: false })); + comp.selectedBitstreamFormatIDs().subscribe((selectedBitstreamFormatIDs: string[]) => { + expect(selectedBitstreamFormatIDs).not.toContain(format.id); + }); }); }); @@ -214,8 +212,6 @@ describe('BitstreamFormatsComponent', () => { beforeEach(waitForAsync(() => { notificationsServiceStub = new NotificationsServiceStub(); - scheduler = getTestScheduler(); - bitstreamFormatService = jasmine.createSpyObj('bitstreamFormatService', { findAll: observableOf(mockFormatsRD), find: createSuccessfulRemoteDataObject$(mockFormatsList[0]), @@ -263,8 +259,6 @@ describe('BitstreamFormatsComponent', () => { beforeEach(waitForAsync(() => { notificationsServiceStub = new NotificationsServiceStub(); - scheduler = getTestScheduler(); - bitstreamFormatService = jasmine.createSpyObj('bitstreamFormatService', { findAll: observableOf(mockFormatsRD), find: createSuccessfulRemoteDataObject$(mockFormatsList[0]), diff --git a/src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.ts b/src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.ts index 162bf2bdb28..263c1aede2a 100644 --- a/src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.ts +++ b/src/app/admin/admin-registries/bitstream-formats/bitstream-formats.component.ts @@ -1,5 +1,5 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { combineLatest as observableCombineLatest, Observable} from 'rxjs'; +import { Observable} from 'rxjs'; import { RemoteData } from '../../../core/data/remote-data'; import { PaginatedList } from '../../../core/data/paginated-list.model'; import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; @@ -7,7 +7,6 @@ import { BitstreamFormat } from '../../../core/shared/bitstream-format.model'; import { BitstreamFormatDataService } from '../../../core/data/bitstream-format-data.service'; import { map, mergeMap, switchMap, take, toArray } from 'rxjs/operators'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; -import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { NoContent } from '../../../core/shared/NoContent.model'; import { PaginationService } from '../../../core/pagination/pagination.service'; @@ -26,7 +25,12 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy { /** * A paginated list of bitstream formats to be shown on the page */ - bitstreamFormats: Observable>>; + bitstreamFormats$: Observable>>; + + /** + * The currently selected {@link BitstreamFormat} IDs + */ + selectedBitstreamFormatIDs$: Observable; /** * The current pagination configuration for the page @@ -39,7 +43,6 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy { }); constructor(private notificationsService: NotificationsService, - private router: Router, private translateService: TranslateService, private bitstreamFormatService: BitstreamFormatDataService, private paginationService: PaginationService, @@ -94,14 +97,11 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy { } /** - * Checks whether a given bitstream format is selected in the list (checkbox) - * @param bitstreamFormat + * Returns the list of all the bitstream formats that are selected in the list (checkbox) */ - isSelected(bitstreamFormat: BitstreamFormat): Observable { + selectedBitstreamFormatIDs(): Observable { return this.bitstreamFormatService.getSelectedBitstreamFormats().pipe( - map((bitstreamFormats: BitstreamFormat[]) => { - return bitstreamFormats.find((selectedFormat) => selectedFormat.id === bitstreamFormat.id) != null; - }) + map((bitstreamFormats: BitstreamFormat[]) => bitstreamFormats.map((selectedFormat) => selectedFormat.id)), ); } @@ -125,27 +125,23 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy { const prefix = 'admin.registries.bitstream-formats.delete'; const suffix = success ? 'success' : 'failure'; - const messages = observableCombineLatest( - this.translateService.get(`${prefix}.${suffix}.head`), - this.translateService.get(`${prefix}.${suffix}.amount`, {amount: amount}) - ); - messages.subscribe(([head, content]) => { + const head: string = this.translateService.instant(`${prefix}.${suffix}.head`); + const content: string = this.translateService.instant(`${prefix}.${suffix}.amount`, { amount: amount }); - if (success) { - this.notificationsService.success(head, content); - } else { - this.notificationsService.error(head, content); - } - }); + if (success) { + this.notificationsService.success(head, content); + } else { + this.notificationsService.error(head, content); + } } ngOnInit(): void { - - this.bitstreamFormats = this.paginationService.getFindListOptions(this.pageConfig.id, this.pageConfig).pipe( + this.bitstreamFormats$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.pageConfig).pipe( switchMap((findListOptions: FindListOptions) => { return this.bitstreamFormatService.findAll(findListOptions); }) ); + this.selectedBitstreamFormatIDs$ = this.selectedBitstreamFormatIDs(); } diff --git a/src/app/admin/admin-registries/bitstream-formats/edit-bitstream-format/edit-bitstream-format.component.html b/src/app/admin/admin-registries/bitstream-formats/edit-bitstream-format/edit-bitstream-format.component.html index f57ec9cd382..efcced2a87c 100644 --- a/src/app/admin/admin-registries/bitstream-formats/edit-bitstream-format/edit-bitstream-format.component.html +++ b/src/app/admin/admin-registries/bitstream-formats/edit-bitstream-format/edit-bitstream-format.component.html @@ -1,11 +1,11 @@
-

{{'admin.registries.bitstream-formats.edit.head' | translate:{format: (bitstreamFormatRD$ | async)?.payload.shortDescription} }}

+

{{'admin.registries.bitstream-formats.edit.head' | translate:{format: (bitstreamFormatRD$ | async)?.payload.shortDescription} }}

-
\ No newline at end of file +
diff --git a/src/app/admin/admin-registries/metadata-registry/metadata-registry.component.html b/src/app/admin/admin-registries/metadata-registry/metadata-registry.component.html index 35bffad185c..48081328931 100644 --- a/src/app/admin/admin-registries/metadata-registry/metadata-registry.component.html +++ b/src/app/admin/admin-registries/metadata-registry/metadata-registry.component.html @@ -2,7 +2,7 @@