Skip to content

Commit f1b048a

Browse files
Francesco MautoAndrea Barbasso
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-2417 (pull request DSpace#4899)
Task/dspace cris 2023 02 x/DSC-2417 Approved-by: Andrea Barbasso
2 parents 7d51841 + 8aea2a4 commit f1b048a

45 files changed

Lines changed: 253 additions & 48 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cypress/e2e/admin-search-page.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import { SEARCH_RESULT_VIEW_MODE_SELECTOR, testA11y } from 'cypress/support/utils';
22

33
describe('Admin Search Page', () => {
44
beforeEach(() => {
@@ -11,7 +11,7 @@ describe('Admin Search Page', () => {
1111
//Page must first be visible
1212
cy.get('ds-admin-search-page').should('be.visible');
1313
// At least one search result should be displayed
14-
cy.get('[data-test="list-object"]').should('be.visible');
14+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('be.visible');
1515
// Click each filter toggle to open *every* filter
1616
// (As we want to scan filter section for accessibility issues as well)
1717
cy.get('[data-test="filter-toggle"]').click({ multiple: true });

cypress/e2e/admin-workflow-page.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import { SEARCH_RESULT_VIEW_MODE_SELECTOR, testA11y } from 'cypress/support/utils';
22

33
describe('Admin Workflow Page', () => {
44
beforeEach(() => {
@@ -11,7 +11,7 @@ describe('Admin Workflow Page', () => {
1111
// Page must first be visible
1212
cy.get('ds-admin-workflow-page').should('be.visible');
1313
// At least one search result should be displayed
14-
cy.get('[data-test="list-object"]').should('be.visible');
14+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('be.visible');
1515
// Click each filter toggle to open *every* filter
1616
// (As we want to scan filter section for accessibility issues as well)
1717
cy.get('[data-test="filter-toggle"]').click({ multiple: true });

cypress/e2e/bulk-access.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import { SEARCH_RESULT_VIEW_MODE_SELECTOR, testA11y } from 'cypress/support/utils';
22
import { Options } from 'cypress-axe';
33

44
describe('Bulk Access', () => {
@@ -12,7 +12,7 @@ describe('Bulk Access', () => {
1212
// Page must first be visible
1313
cy.get('ds-bulk-access').should('be.visible');
1414
// At least one search result should be displayed
15-
cy.get('[data-test="list-object"]').should('be.visible');
15+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('be.visible');
1616
// Click each filter toggle to open *every* filter
1717
// (As we want to scan filter section for accessibility issues as well)
1818
cy.get('[data-test="filter-toggle"]').click({ multiple: true });

cypress/e2e/my-dspace.cy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import { SEARCH_RESULT_VIEW_MODE_SELECTOR, testA11y } from 'cypress/support/utils';
22

33
describe('My DSpace page', () => {
44
it('should display recent submissions and pass accessibility tests', () => {
@@ -9,8 +9,8 @@ describe('My DSpace page', () => {
99

1010
cy.get('ds-my-dspace-page').should('be.visible');
1111

12-
// At least one recent submission should be displayed
13-
cy.get('[data-test="list-object"]').should('be.visible');
12+
// At least one recent submission should be displayed (supports list or grid view)
13+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('be.visible');
1414

1515
// Click each filter toggle to open *every* filter
1616
// (As we want to scan filter section for accessibility issues as well)

cypress/e2e/search-navbar.cy.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { SEARCH_RESULT_VIEW_MODE_SELECTOR } from 'cypress/support/utils';
2+
13
const page = {
24
fillOutQueryInNavBar(query) {
35
// Click the magnifying glass
@@ -29,7 +31,7 @@ describe('Search from Navigation Bar', () => {
2931
// Wait for search results to come back from the above GET command
3032
cy.wait('@search-results');
3133
// At least one search result should be displayed
32-
cy.get('[data-test="list-object"]').should('be.visible');
34+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('be.visible');
3335
});
3436

3537
it('should go to search page with correct query if submitted (from search)', () => {
@@ -44,7 +46,7 @@ describe('Search from Navigation Bar', () => {
4446
// Wait for search results to come back from the above GET command
4547
cy.wait('@search-results');
4648
// At least one search result should be displayed
47-
cy.get('[data-test="list-object"]').should('be.visible');
49+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('be.visible');
4850
});
4951

5052
it('should allow user to also submit query by clicking icon', () => {
@@ -59,6 +61,6 @@ describe('Search from Navigation Bar', () => {
5961
// Wait for search results to come back from the above GET command
6062
cy.wait('@search-results');
6163
// At least one search result should be displayed
62-
cy.get('[data-test="list-object"]').should('be.visible');
64+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('be.visible');
6365
});
6466
});

cypress/e2e/search-page.cy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import { SEARCH_RESULT_VIEW_MODE_SELECTOR, testA11y } from 'cypress/support/utils';
22

33
describe('Search Page', () => {
44
// NOTE: these tests currently assume this query will return results!
@@ -20,8 +20,8 @@ describe('Search Page', () => {
2020
// <ds-search-page> tag must be loaded
2121
cy.get('ds-search-page').should('be.visible');
2222

23-
// At least one search result should be displayed
24-
cy.get('[data-test="list-object"]').should('be.visible');
23+
// At least one search result should be displayed
24+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('be.visible');
2525

2626
// Click each filter toggle to open *every* filter
2727
// (As we want to scan filter section for accessibility issues as well)

cypress/support/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { Result } from 'axe-core';
22
import { Options } from 'cypress-axe';
33

4+
/**
5+
* Selector that matches search result items regardless of the active view mode (list, grid, or detail).
6+
* Use this instead of hardcoding a single data-test attribute so that tests remain
7+
* independent of the `preferredDisplayView` configuration.
8+
*/
9+
export const SEARCH_RESULT_VIEW_MODE_SELECTOR = '[data-test="list-object"], [data-test="grid-object"], [data-test="detail-object"]';
10+
411
// Log violations to terminal/commandline in a table format.
512
// Uses 'log' and 'table' tasks defined in ../plugins/index.ts
613
// Borrowed from https://github.com/component-driven/cypress-axe#in-your-spec-file

src/app/core/shared/search/search.service.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ describe('SearchService', () => {
6767
searchService = TestBed.inject(SearchService);
6868
});
6969

70-
it('should return list view mode', () => {
70+
it('should return default list view mode when no query params exist', () => {
7171
searchService.getViewMode().subscribe((viewMode) => {
7272
expect(viewMode).toBe(ViewMode.ListElement);
7373
});
7474
});
75+
76+
it('should return given list view mode when no query params exist', () => {
77+
searchService.getViewMode(ViewMode.GridElement).subscribe((viewMode) => {
78+
expect(viewMode).toBe(ViewMode.GridElement);
79+
});
80+
});
7581
});
7682
describe('', () => {
7783
let searchService: SearchService;

src/app/core/shared/search/search.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,12 @@ export class SearchService implements OnDestroy {
363363
* Requests the current view mode based on the current URL
364364
* @returns {Observable<ViewMode>} The current view mode
365365
*/
366-
getViewMode(): Observable<ViewMode> {
366+
getViewMode(defaultView: ViewMode = ViewMode.ListElement): Observable<ViewMode> {
367367
return this.routeService.getQueryParamMap().pipe(map((params) => {
368368
if (isNotEmpty(params.get('view')) && hasValue(params.get('view'))) {
369369
return params.get('view');
370370
} else {
371-
return ViewMode.ListElement;
371+
return defaultView;
372372
}
373373
}));
374374
}

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/relation/cris-layout-relation-box.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[collapseCharts]="true"
88
[showChartsToggle]="true"
99
[showScopeSelector]="false"
10+
[initViewMode]="initViewMode"
1011
[showSearchResultNotice]="showSearchResultNotice$ | async"
1112
[searchResultNotice]="searchResultNotice">
1213
</ds-configuration-search-page>

0 commit comments

Comments
 (0)