Skip to content

Commit 43df739

Browse files
Francesco MautoAndrea Barbasso
authored andcommitted
Merged in task/dspace-cris-2024_02_x/DSC-2417 (pull request DSpace#4898)
[DSC-2417] add: new property to define preferred init view modes Approved-by: Andrea Barbasso
2 parents f82016a + cd0ed8d commit 43df739

48 files changed

Lines changed: 320 additions & 45 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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import {
2+
SEARCH_RESULT_VIEW_MODE_SELECTOR,
3+
testA11y,
4+
} from 'cypress/support/utils';
25

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

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

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

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

cypress/e2e/bulk-access.cy.ts

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

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

cypress/e2e/my-dspace.cy.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import {
2+
SEARCH_RESULT_VIEW_MODE_SELECTOR,
3+
switchToListView,
4+
testA11y,
5+
} from 'cypress/support/utils';
26

37
describe('My DSpace page', () => {
48
it('should display recent submissions and pass accessibility tests', () => {
@@ -9,8 +13,8 @@ describe('My DSpace page', () => {
913

1014
cy.get('ds-my-dspace-page').should('be.visible');
1115

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

1519
// Click each filter toggle to open *every* filter
1620
// (As we want to scan filter section for accessibility issues as well)
@@ -86,6 +90,9 @@ describe('My DSpace page', () => {
8690
// Close any open notifications, to make sure they don't get in the way of next steps
8791
cy.get('[data-dismiss="alert"]').click({ multiple: true });
8892

93+
// Switch to list view so that edit/delete action buttons are visible
94+
switchToListView();
95+
8996
// This is the GET command that will actually run the search
9097
cy.intercept('GET', '**/server/api/discover/search/objects*').as('search-results');
9198
// On MyDSpace, find the submission we just created via its ID
@@ -260,12 +267,12 @@ describe('My DSpace page', () => {
260267
//Validate URL
261268
cy.url().should('include', 'configuration=workflow');
262269

263-
//Wait to render the list and at leat one item
264-
cy.get('[data-test="list-object"]').should('have.length.greaterThan', 0);
270+
//Wait to render the list and at leat one item (supports list or grid view)
271+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR).should('have.length.greaterThan', 0);
265272
cy.get('[data-test="claim-button"]').should('exist');
266273

267274
//Check that we have at least one item in worflow search, the item have claim-button and can click in it.
268-
cy.get('[data-test="list-object"]')
275+
cy.get(SEARCH_RESULT_VIEW_MODE_SELECTOR)
269276
.then(($items) => {
270277
const itemWithClaim = [...$items].find(item =>
271278
item.querySelector('[data-test="claim-button"]'),

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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import {
2+
SEARCH_RESULT_VIEW_MODE_SELECTOR,
3+
testA11y,
4+
} from 'cypress/support/utils';
25

36
describe('Search Page', () => {
47
// NOTE: these tests currently assume this query will return results!
@@ -21,7 +24,7 @@ describe('Search Page', () => {
2124
cy.get('ds-search-page').should('be.visible');
2225

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

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

cypress/e2e/submission.cy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { testA11y } from 'cypress/support/utils';
1+
import {
2+
switchToListView,
3+
testA11y,
4+
} from 'cypress/support/utils';
25
//import { TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD, TEST_SUBMIT_COLLECTION_NAME, TEST_SUBMIT_COLLECTION_UUID, TEST_ADMIN_USER, TEST_ADMIN_PASSWORD } from 'cypress/support/e2e';
36
import { Options } from 'cypress-axe';
47

@@ -96,6 +99,9 @@ describe('New Submission page', () => {
9699
// Now, dismiss any open alert boxes (may be multiple, as tests run quickly)
97100
cy.get('[data-dismiss="alert"]').click({ multiple: true });
98101

102+
// Switch to list view so that edit/delete action buttons are visible
103+
switchToListView();
104+
99105
// This is the GET command that will actually run the search
100106
cy.intercept('GET', '**/server/api/discover/search/objects*').as('search-results');
101107
// On MyDSpace, find the submission we just saved via its ID

cypress/support/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
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+
11+
/**
12+
* Switches the search results to list view mode.
13+
* Use this before interacting with action buttons (edit, delete) that are only available in list view.
14+
*/
15+
export const switchToListView = () => {
16+
cy.get('ds-search-sidebar [data-test="list-view"]').click();
17+
cy.get('[data-test="list-object"]').should('exist');
18+
};
19+
420
// Log violations to terminal/commandline in a table format.
521
// Uses 'log' and 'table' tasks defined in ../plugins/index.ts
622
// Borrowed from https://github.com/component-driven/cypress-axe#in-your-spec-file

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ describe('SearchService', () => {
126126
});
127127
});
128128

129+
it('should return the given default view mode when no view query param is set', () => {
130+
testScheduler.run(({ expectObservable }) => {
131+
expectObservable(service.getViewMode(ViewMode.GridElement)).toBe('(a|)', {
132+
a: ViewMode.GridElement,
133+
});
134+
});
135+
});
136+
129137
it('should return ViewMode.List when the viewMode is set to ViewMode.List in the ActivatedRoute', () => {
130138
testScheduler.run(({ expectObservable }) => {
131139
spyOn(routeService, 'getQueryParamMap').and.returnValue(observableOf(new Map([

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,15 @@ export class SearchService implements OnDestroy {
400400

401401
/**
402402
* Requests the current view mode based on the current URL
403+
* @param {ViewMode} defaultView The view mode to fall back to when none is set through the `view` query parameter
403404
* @returns {Observable<ViewMode>} The current view mode
404405
*/
405-
getViewMode(): Observable<ViewMode> {
406+
getViewMode(defaultView: ViewMode = ViewMode.ListElement): Observable<ViewMode> {
406407
return this.routeService.getQueryParamMap().pipe(map((params) => {
407408
if (isNotEmpty(params.get('view')) && hasValue(params.get('view'))) {
408409
return params.get('view');
409410
} else {
410-
return ViewMode.ListElement;
411+
return defaultView;
411412
}
412413
}));
413414
}

0 commit comments

Comments
 (0)