From 9e6aae13b9977a6b24f7b06014a0f45cfed1a123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Fern=C3=A1ndez=20de=20Alba?= Date: Mon, 17 Jul 2023 19:02:50 +0200 Subject: [PATCH 1/4] Remove dangling out of place Guillotina Cypress tests (#4980) --- cypress/tests/core/guillotina/autologin.js | 18 --- cypress/tests/core/guillotina/blocks-text.js | 88 --------------- cypress/tests/core/guillotina/content.js | 110 ------------------- cypress/tests/core/guillotina/history.js | 33 ------ cypress/tests/core/guillotina/login.js | 9 -- cypress/tests/core/guillotina/sharing.js | 32 ------ news/4980.internal | 1 + 7 files changed, 1 insertion(+), 290 deletions(-) delete mode 100644 cypress/tests/core/guillotina/autologin.js delete mode 100644 cypress/tests/core/guillotina/blocks-text.js delete mode 100644 cypress/tests/core/guillotina/content.js delete mode 100644 cypress/tests/core/guillotina/history.js delete mode 100644 cypress/tests/core/guillotina/login.js delete mode 100644 cypress/tests/core/guillotina/sharing.js create mode 100644 news/4980.internal diff --git a/cypress/tests/core/guillotina/autologin.js b/cypress/tests/core/guillotina/autologin.js deleted file mode 100644 index fce720381b..0000000000 --- a/cypress/tests/core/guillotina/autologin.js +++ /dev/null @@ -1,18 +0,0 @@ -describe('Autologin Tests', () => { - it('Autologin as an standalone test', function () { - const api_url = 'http://127.0.0.1:8081/db/web'; - const user = 'admin'; - const password = 'admin'; - - cy.request({ - method: 'POST', - url: `${api_url}/@login`, - headers: { Accept: 'application/json' }, - body: { login: user, password: password }, - }).then((response) => cy.setCookie('auth_token', response.body.token)); - - cy.visit('/'); - cy.get('#toolbar-personal').click(); - cy.get('#toolbar-logout'); - }); -}); diff --git a/cypress/tests/core/guillotina/blocks-text.js b/cypress/tests/core/guillotina/blocks-text.js deleted file mode 100644 index 334c3b3c32..0000000000 --- a/cypress/tests/core/guillotina/blocks-text.js +++ /dev/null @@ -1,88 +0,0 @@ -describe('Text Block Tests', () => { - beforeEach(() => { - // given a logged in editor and a page in edit mode - cy.autologin(); - cy.visit('/'); - cy.createContent({ - contentType: 'Document', - contentId: 'my-page', - contentTitle: 'My Page', - }); - cy.visit('/my-page'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.waitForResourceToLoad('my-page'); - cy.navigate('/my-page/edit'); - }); - - it('As editor I can add a text block', () => { - // when I add a text block - cy.getSlate(true).focus().click().type('My text').contains('My text'); - cy.get('#toolbar-save').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.waitForResourceToLoad('my-page'); - - // then the page view should contain the text block - cy.get('#page-document').contains('My text'); - }); - - it('As editor I can add a link to a text block', function () { - // when I create a link - cy.getSlate(true) - .focus() - .click() - .type('Colorless green ideas sleep furiously.') - .setSlateSelection('furiously'); - cy.clickSlateButton('Add link'); - cy.get('.slate-toolbar .link-form-container input').type( - 'https://google.com{enter}', - ); - cy.get('#toolbar-save').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.waitForResourceToLoad('my-page'); - - // then the page view should contain a link - cy.contains('Colorless green ideas sleep furiously.'); - cy.get('#page-document p a') - .should('have.attr', 'href') - .and('include', 'https://google.com'); - }); - - it('As editor I can add a mailto link to a text block', function () { - cy.getSlateTitle().focus().click(); - - // when I create a mailto link - cy.getSlate(true) - .focus() - .click() - .type('Colorless green ideas sleep furiously.') - .setSlateSelection('furiously'); - cy.clickSlateButton('Add link'); - cy.get('.slate-toolbar .link-form-container input').type( - 'mailto:hello@example.com{enter}', - ); - cy.get('#toolbar-save').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.waitForResourceToLoad('my-page'); - - // then the page view should contain a mailto link - cy.contains('Colorless green ideas sleep furiously.'); - cy.get('#page-document p a') - .should('have.attr', 'href') - .and('include', 'mailto:hello@example.com'); - }); -}); diff --git a/cypress/tests/core/guillotina/content.js b/cypress/tests/core/guillotina/content.js deleted file mode 100644 index eaa4da5c8e..0000000000 --- a/cypress/tests/core/guillotina/content.js +++ /dev/null @@ -1,110 +0,0 @@ -describe('Add Content Tests', () => { - beforeEach(() => { - // give a logged in editor and the site root - cy.autologin(); - cy.visit('/'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.waitForResourceToLoad(''); - }); - it('As editor I can add a page', function () { - // when I add a page - cy.get('#toolbar-add').click(); - cy.get('#toolbar-add-document').click(); - cy.getSlateTitle().focus().click().type('My Page').contains('My Page'); - - // then I a new page has been created - cy.get('#toolbar-save').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); - cy.contains('My Page'); - }); - it('As editor I can add a page with a text block', function () { - // when I add a page with a text block - cy.get('#toolbar-add').click(); - cy.get('#toolbar-add-document').click(); - cy.getSlateTitle().focus().click().type('My Page').contains('My Page'); - cy.getSlateEditorAndType('This is the text').contains('This is the text'); - cy.get('#toolbar-save').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); - - // then a new page with a text block has been added - cy.contains('My Page'); - cy.contains('This is the text'); - }); - it('As editor I can add a file', function () { - // when I add a file - cy.get('#toolbar-add').click(); - cy.get('#toolbar-add-file').click(); - - cy.get('.formtabs.menu').contains('default').click(); - - cy.get('input[name="title"]') - .type('My File') - .should('have.value', 'My File'); - - // Guillotina wants the file handler instead than the base64 encoding - cy.fixture('file.pdf').then((fileContent) => { - cy.get('#field-file').attachFile( - { fileContent, fileName: 'file.pdf', mimeType: 'application/pdf' }, - { subjectType: 'input' }, - ); - }); - - cy.get('#toolbar-save').focus().click(); - - // then a new file should have been created - cy.url().should('eq', Cypress.config().baseUrl + '/my-file'); - cy.contains('My File'); - }); - - it('As editor I can add an image', function () { - // when I add an image - cy.get('#toolbar-add').click(); - cy.get('#toolbar-add-image').click(); - - cy.get('.formtabs.menu').contains('default').click(); - - cy.get('input[name="title"]') - .type('My image') - .should('have.value', 'My image'); - - // Guillotina wants the file handler instead than the base64 encoding - cy.fixture('image.png') - .then((fc) => { - return Cypress.Blob.base64StringToBlob(fc); - }) - .then((fileContent) => { - cy.get('#field-image').attachFile( - { fileContent, fileName: 'image.png', mimeType: 'image/png' }, - { subjectType: 'input' }, - ); - cy.get('#field-image-image').parent().parent().contains('image.png'); - }); - - cy.get('#toolbar-save').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-image'); - cy.contains('My image'); - }); - - describe('Actions', () => { - beforeEach(() => { - cy.autologin(); - }); - it('As editor I can add a Guillotina folder', function () { - cy.visit('/'); - cy.get('#toolbar-add').click(); - cy.get('#toolbar-add-cmsfolder').click(); - cy.getSlateTitle() - .focus() - .click() - .type('This is a guillotina folder') - .contains('This is a guillotina folder'); - - cy.get('#toolbar-save').click(); - - cy.contains('This is a guillotina folder'); - }); - }); -}); diff --git a/cypress/tests/core/guillotina/history.js b/cypress/tests/core/guillotina/history.js deleted file mode 100644 index 731131d0de..0000000000 --- a/cypress/tests/core/guillotina/history.js +++ /dev/null @@ -1,33 +0,0 @@ -describe('History Tests', () => { - beforeEach(() => { - // give a logged in editor and the site root - cy.autologin(); - cy.visit('/'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.waitForResourceToLoad(''); - }); - it('As editor I can add a page and access history', function () { - // I add a page - cy.get('#toolbar-add').click(); - cy.get('#toolbar-add-document').click(); - cy.getSlateTitle().focus().click().type('My Page').contains('My Page'); - - // then a new page has been created - cy.get('#toolbar-save').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); - - cy.contains('My Page'); - - // then I click on the Toolbar > More - cy.get('#toolbar-more').click(); - cy.get('.menu-more').contains('History'); - - // and then I click on History - cy.get('.menu-more a[href*="/history"]').contains('History').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page/history'); - cy.contains('History of'); - }); -}); diff --git a/cypress/tests/core/guillotina/login.js b/cypress/tests/core/guillotina/login.js deleted file mode 100644 index dd6be74f03..0000000000 --- a/cypress/tests/core/guillotina/login.js +++ /dev/null @@ -1,9 +0,0 @@ -describe('Login Tests', () => { - it('As registered user I can login', function () { - cy.visit('/login'); - cy.get('#login').type('admin').should('have.value', 'admin'); - cy.get('#password').type('admin').should('have.value', 'admin'); - cy.get('#login-form-submit').click(); - cy.get('body').should('have.class', 'has-toolbar'); - }); -}); diff --git a/cypress/tests/core/guillotina/sharing.js b/cypress/tests/core/guillotina/sharing.js deleted file mode 100644 index 7b0dcbbdbc..0000000000 --- a/cypress/tests/core/guillotina/sharing.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('Sharing Tests', () => { - beforeEach(() => { - // give a logged in editor and the site root - cy.autologin(); - cy.visit('/'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.waitForResourceToLoad(''); - }); - it('As editor I can add a page and access sharing', function () { - // I add a page - cy.get('#toolbar-add').click(); - cy.get('#toolbar-add-document').click(); - cy.getSlateTitle().focus().click().type('My Page').contains('My Page'); - - // then a new page has been created - cy.get('#toolbar-save').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page'); - cy.contains('My Page'); - - // then I click on the Toolbar > More - cy.get('#toolbar-more').click(); - cy.get('.menu-more').contains('Sharing'); - - // and then I click on History - cy.get('.menu-more a[href*="/sharing"]').contains('Sharing').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/my-page/sharing'); - cy.contains('Sharing for'); - }); -}); diff --git a/news/4980.internal b/news/4980.internal new file mode 100644 index 0000000000..50a19b11ba --- /dev/null +++ b/news/4980.internal @@ -0,0 +1 @@ +Remove dangling out of place Guillotina Cypress tests @sneridagh From 9c5203b968b7665371c6cbbe476d6319a38c4856 Mon Sep 17 00:00:00 2001 From: Bhuvanesh Patil Date: Tue, 18 Jul 2023 13:14:10 +0530 Subject: [PATCH 2/4] handles condition for yearly frequency in recurrence (#4604) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Víctor Fernández de Alba Co-authored-by: Andrea Cecchi --- news/4498.bugfix | 1 + .../manage/Widgets/RecurrenceWidget/RecurrenceWidget.jsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 news/4498.bugfix diff --git a/news/4498.bugfix b/news/4498.bugfix new file mode 100644 index 0000000000..127f51ddf0 --- /dev/null +++ b/news/4498.bugfix @@ -0,0 +1 @@ +Handle condition for yearly frequency in recurrence @BhuvaneshPatil diff --git a/src/components/manage/Widgets/RecurrenceWidget/RecurrenceWidget.jsx b/src/components/manage/Widgets/RecurrenceWidget/RecurrenceWidget.jsx index bdc0c0f8b7..94ab5169ed 100644 --- a/src/components/manage/Widgets/RecurrenceWidget/RecurrenceWidget.jsx +++ b/src/components/manage/Widgets/RecurrenceWidget/RecurrenceWidget.jsx @@ -427,7 +427,7 @@ class RecurrenceWidget extends Component { break; } - if (value) { + if (value === 0 || value) { //set value values[field] = value; } else { From 8ccab387206fedcc0344e8eef21356c3d06d2add Mon Sep 17 00:00:00 2001 From: Mikel Larreategi Date: Tue, 18 Jul 2023 09:55:15 +0200 Subject: [PATCH 3/4] Add /ok route as an express middleware (#4432) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ionlizarazu Co-authored-by: Víctor Fernández de Alba Co-authored-by: Alin Voinea --- docs/source/configuration/settings-reference.md | 11 ++++++++++- news/4375.feature | 1 + src/config/index.js | 1 + src/config/server.js | 2 ++ src/express-middleware/ok.js | 16 ++++++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 news/4375.feature create mode 100644 src/express-middleware/ok.js diff --git a/docs/source/configuration/settings-reference.md b/docs/source/configuration/settings-reference.md index 0be76b4f02..58a576ed2d 100644 --- a/docs/source/configuration/settings-reference.md +++ b/docs/source/configuration/settings-reference.md @@ -387,8 +387,17 @@ excludeLinksAndReferencesMenuItem The content menu links to the {guilabel}`Links and references` view per default. Exclude this menu item by setting `excludeLinksAndReferencesMenuItem` to `true`. -``` +okRoute + Volto provides an `/ok` URL where it responds with a `text/plain ok` response, with an `HTTP 200` status code, to signal third party health check services that the Volto process is running correctly. + + Using this setting, one can modify such an URL and configure it to respond with another URL. + + The provided default URL matches the existing Plone Classic UI URL. + ```jsx + config.settings.okRoute = '/site-is-ok' + ``` +``` ## Views settings diff --git a/news/4375.feature b/news/4375.feature new file mode 100644 index 0000000000..fa8a87789a --- /dev/null +++ b/news/4375.feature @@ -0,0 +1 @@ +Add /ok route as an express middleware @ionlizarazu diff --git a/src/config/index.js b/src/config/index.js index ae852f5236..912f62106f 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -74,6 +74,7 @@ let config = { port, // The URL Volto is going to be served (see sensible defaults above) publicURL, + okRoute: '/ok', apiPath, apiExpanders: [ // Add the following expanders for only issuing a single request. diff --git a/src/config/server.js b/src/config/server.js index 8e8d7e4b61..49fd8b2fdc 100644 --- a/src/config/server.js +++ b/src/config/server.js @@ -1,6 +1,7 @@ import imagesMiddleware from '@plone/volto/express-middleware/images'; import filesMiddleware from '@plone/volto/express-middleware/files'; import robotstxtMiddleware from '@plone/volto/express-middleware/robotstxt'; +import okMiddleware from '@plone/volto/express-middleware/ok'; import sitemapMiddleware from '@plone/volto/express-middleware/sitemap'; import staticsMiddleware from '@plone/volto/express-middleware/static'; import devProxyMiddleware from '@plone/volto/express-middleware/devproxy'; @@ -11,6 +12,7 @@ const settings = { filesMiddleware(), imagesMiddleware(), robotstxtMiddleware(), + okMiddleware(), sitemapMiddleware(), staticsMiddleware(), ], diff --git a/src/express-middleware/ok.js b/src/express-middleware/ok.js new file mode 100644 index 0000000000..6d9d95fb41 --- /dev/null +++ b/src/express-middleware/ok.js @@ -0,0 +1,16 @@ +import express from 'express'; +import config from '@plone/volto/registry'; + +const ok = function (req, res, next) { + res.type('text/plain'); + res.set('Expires', 'Sat, 1 Jan 2000 00:00:00 GMT'); + res.set('Cache-Control', 'max-age=0, must-revalidate, private'); + res.send('ok'); +}; + +export default function () { + const middleware = express.Router(); + middleware.all(config?.settings?.okRoute || '/ok', ok); + middleware.id = 'ok'; + return middleware; +} From f5bf8972a78f0536ad58c0c08848e202b039d31a Mon Sep 17 00:00:00 2001 From: Alok Kumar Date: Tue, 18 Jul 2023 14:13:16 +0530 Subject: [PATCH 4/4] Fix search block input clear button doesn't reset the search (#4837) Co-authored-by: ionlizarazu Co-authored-by: Mikel Larreategi --- cypress/tests/core/blocks/blocks-grid.js | 2 + cypress/tests/core/blocks/blocks-search.js | 313 +++++++++++++++++- news/4828.bugfix | 1 + .../Blocks/Search/components/SearchInput.jsx | 11 +- .../manage/Blocks/Search/hocs/withSearch.jsx | 13 +- 5 files changed, 331 insertions(+), 9 deletions(-) create mode 100644 news/4828.bugfix diff --git a/cypress/tests/core/blocks/blocks-grid.js b/cypress/tests/core/blocks/blocks-grid.js index 27c9190c4f..b598940ca4 100644 --- a/cypress/tests/core/blocks/blocks-grid.js +++ b/cypress/tests/core/blocks/blocks-grid.js @@ -44,6 +44,7 @@ context('Blocks Acceptance Tests', () => { cy.get('button[aria-label="Add block in position 1"]').click(); cy.get('.blocks-chooser [aria-label="Unfold Text blocks"]').click(); + cy.wait(200); cy.get('.blocks-chooser .text .button.slate').click(); cy.getSlateEditorSelectorAndType( '.block.gridBlock.selected .slate-editor [contenteditable=true]', @@ -86,6 +87,7 @@ context('Blocks Acceptance Tests', () => { cy.get('button[aria-label="Add block in position 1"]').click(); cy.get('.blocks-chooser [aria-label="Unfold Text blocks"]').click(); + cy.wait(200); cy.get('.blocks-chooser .text .button.slate').click(); cy.scrollTo('top'); diff --git a/cypress/tests/core/blocks/blocks-search.js b/cypress/tests/core/blocks/blocks-search.js index cf81cef8db..aef05fabcf 100644 --- a/cypress/tests/core/blocks/blocks-search.js +++ b/cypress/tests/core/blocks/blocks-search.js @@ -36,7 +36,14 @@ describe('Search Block Tests', () => { cy.waitForResourceToLoad('@types'); }); - it('Add Search block', () => { + afterEach(() => { + cy.removeContent({ path: 'my-page' }); + cy.removeContent({ path: 'my-folder' }); + cy.removeContent({ path: 'my-event' }); + cy.removeContent({ path: 'my-search-page' }); + }); + + it('Search block - test checkbox facet', () => { cy.visit('/'); cy.get('#toolbar-add > .icon').click(); cy.get('#toolbar-add-document').click(); @@ -81,21 +88,315 @@ describe('Search Block Tests', () => { cy.get('.react-select__option').contains('Checkbox').click(); cy.get('label[for="field-multiple-3-facets-0"]').click(); + // Save the page + cy.get('#toolbar-save > .icon').click(); + + cy.wait(500); + + // test if type facet works + cy.get('.block.search .facets > .facet .entries > .entry label') + .contains('Event') + .click(); + cy.get('#page-document .listing-item:first-of-type a').should( + 'have.attr', + 'href', + '/my-event', + ); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22portal_type%22%2C%22o%22%3A%22paqo.list.contains%22%2C%22v%22%3A%5B%22Event%22%5D%7D', + ); + // clear facets + cy.get('.block.search .filter-list-header .ui.button').click(); + }); + + it('Search block - test date range facet', () => { + cy.visit('/'); + cy.get('#toolbar-add > .icon').click(); + cy.get('#toolbar-add-document').click(); + cy.getSlateTitle().focus().click().type('My Search Page'); + + // Add Search listing block + cy.addNewBlock('search'); + + // Add search query criteria + cy.get('#default-query-0-query .react-select__value-container').click(); + cy.get('#default-query-0-query .react-select__option') + .contains('Type') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Page') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Folder') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Event') + .click(); + // Add data range facet cy.get('.add-item-button-wrapper > button').click(); - cy.get('#field-field-1-facets-1 .react-select__value-container').click(); + cy.get('#field-field-1-facets-0 .react-select__value-container').click(); cy.get('.react-select__option').contains('Effective date').click(); - cy.get('#field-title-0-facets-1').type('Effective date'); - cy.get('#field-type-2-facets-1').click(); + cy.get('#field-title-0-facets-0').type('Effective date'); + cy.get('#field-type-2-facets-0').click(); cy.get('.react-select__option').contains('Date Range').click(); + // TODO: test if date range facet works + + // Save the page + cy.get('#toolbar-save > .icon').click(); + + cy.wait(500); + }); + + it('Search block - test live searchbox', () => { + cy.visit('/'); + cy.get('#toolbar-add > .icon').click(); + cy.get('#toolbar-add-document').click(); + cy.getSlateTitle().focus().click().type('My Search Page'); + + // Add Search listing block + cy.addNewBlock('search'); + + // Add search query criteria + cy.get('#default-query-0-query .react-select__value-container').click(); + cy.get('#default-query-0-query .react-select__option') + .contains('Type') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Page') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Folder') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Event') + .click(); + // Save the page cy.get('#toolbar-save > .icon').click(); cy.wait(500); + // test searching for Event + cy.get('.search-wrapper .search-input input').focus().type('Event'); + cy.get('#page-document .listing-item:first-of-type a').should( + 'have.attr', + 'href', + '/my-event', + ); + cy.get('.search-results-count-sort .search-details em').should( + 'contain', + 'Event', + ); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22SearchableText%22%2C%22o%22%3A%22paqo.string.contains%22%2C%22v%22%3A%22Event%22%7D', + ); + + // test removing one char + cy.get('.search-wrapper .search-input input').focus().type('{backspace}'); + cy.get('.search-results-count-sort .search-details em') + .should('not.contain', 'Event') + .and('contain', 'Even'); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22SearchableText%22%2C%22o%22%3A%22paqo.string.contains%22%2C%22v%22%3A%22Even%22%7D', + ); + + // test removing the text with the button cy.get( - '.block.search .facets > .facet .entries > .entry:nth-of-type(1) label', + '.search-wrapper .search-input .search-input-actions button.search-input-clear-icon-button', ).click(); - cy.get('.block.search .filter-list-header .ui.button').click(); + cy.get('.search-results-count-sort .search-details').should( + 'not.contain', + 'Searched for:', + ); + cy.url().should('not.contain', '%22SearchableText%22'); + + // test searching for Event + cy.get('.search-wrapper .search-input input').focus().type('Event'); + cy.get('#page-document .listing-item:first-of-type a').should( + 'have.attr', + 'href', + '/my-event', + ); + cy.get('.search-results-count-sort .search-details em').should( + 'contain', + 'Event', + ); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22SearchableText%22%2C%22o%22%3A%22paqo.string.contains%22%2C%22v%22%3A%22Event%22%7D', + ); + + // test removing one char + cy.get('.search-wrapper .search-input input').focus().type('{backspace}'); + cy.get('.search-results-count-sort .search-details em') + .should('not.contain', 'Event') + .and('contain', 'Even'); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22SearchableText%22%2C%22o%22%3A%22paqo.string.contains%22%2C%22v%22%3A%22Even%22%7D', + ); + + // test removing the whole text from the keyboard + cy.get('.search-wrapper .search-input input') + .focus() + .type('{selectAll}{del}'); + cy.get('.search-results-count-sort .search-details').should( + 'not.contain', + 'Searched for:', + ); + cy.url().should('not.contain', '%22SearchableText%22'); + }); + + it('Search block - test searchbox', () => { + cy.visit('/'); + cy.get('#toolbar-add > .icon').click(); + cy.get('#toolbar-add-document').click(); + cy.getSlateTitle().focus().click().type('My Search Page'); + + // Add Search listing block + cy.addNewBlock('search'); + + // Add search query criteria + cy.get('#default-query-0-query .react-select__value-container').click(); + cy.get('#default-query-0-query .react-select__option') + .contains('Type') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Page') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Folder') + .click(); + + cy.get('#default-query-0-query .fields:first-of-type > .field').click(); + cy.get( + '#default-query-0-query .fields:first-of-type > .field .react-select__option', + ) + .contains('Event') + .click(); + + // uncheck showSearchButton + cy.get('label[for=field-showSearchButton]').click(); + cy.get('.search-wrapper .ui.button').should('contain', 'Search'); + + // Save the page + cy.get('#toolbar-save > .icon').click(); + + cy.wait(500); + + // test searching for Event + cy.get('.search-wrapper .search-input input').focus().type('Event'); + cy.get('.search-wrapper > .ui.button').click(); + + cy.get('#page-document .listing-item:first-of-type a').should( + 'have.attr', + 'href', + '/my-event', + ); + cy.get('.search-results-count-sort .search-details em').should( + 'contain', + 'Event', + ); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22SearchableText%22%2C%22o%22%3A%22paqo.string.contains%22%2C%22v%22%3A%22Event%22%7D', + ); + + // test removing one char + cy.get('.search-wrapper .search-input input').focus().type('{backspace}'); + cy.get('.search-wrapper > .ui.button').click(); + cy.get('.search-results-count-sort .search-details em') + .should('not.contain', 'Event') + .and('contain', 'Even'); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22SearchableText%22%2C%22o%22%3A%22paqo.string.contains%22%2C%22v%22%3A%22Even%22%7D', + ); + + // test removing the text with the button + cy.get( + '.search-wrapper .search-input .search-input-actions button.search-input-clear-icon-button', + ).click(); + cy.get('.search-wrapper > .ui.button').click(); + cy.get('.search-results-count-sort .search-details').should( + 'not.contain', + 'Searched for:', + ); + cy.url().should('not.contain', '%22SearchableText%22'); + + // test searching for Event + cy.get('.search-wrapper .search-input input').focus().type('Event'); + cy.get('.search-wrapper > .ui.button').click(); + cy.get('#page-document .listing-item:first-of-type a').should( + 'have.attr', + 'href', + '/my-event', + ); + cy.get('.search-results-count-sort .search-details em').should( + 'contain', + 'Event', + ); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22SearchableText%22%2C%22o%22%3A%22paqo.string.contains%22%2C%22v%22%3A%22Event%22%7D', + ); + + // test removing one char + cy.get('.search-wrapper .search-input input').focus().type('{backspace}'); + cy.get('.search-wrapper > .ui.button').click(); + cy.get('.search-results-count-sort .search-details em') + .should('not.contain', 'Event') + .and('contain', 'Even'); + cy.url().should( + 'contain', + '%7B%22i%22%3A%22SearchableText%22%2C%22o%22%3A%22paqo.string.contains%22%2C%22v%22%3A%22Even%22%7D', + ); + + // test removing the whole text from the keyboard + cy.get('.search-wrapper .search-input input') + .focus() + .type('{selectAll}{del}'); + cy.get('.search-wrapper > .ui.button').click(); + cy.get('.search-results-count-sort .search-details').should( + 'not.contain', + 'Searched for:', + ); + cy.url().should('not.contain', '%22SearchableText%22'); }); }); diff --git a/news/4828.bugfix b/news/4828.bugfix new file mode 100644 index 0000000000..0e11502b6c --- /dev/null +++ b/news/4828.bugfix @@ -0,0 +1 @@ +Fix search block input clear button doesn't reset the search @iFlameing diff --git a/src/components/manage/Blocks/Search/components/SearchInput.jsx b/src/components/manage/Blocks/Search/components/SearchInput.jsx index 531be61858..1640dd08f0 100644 --- a/src/components/manage/Blocks/Search/components/SearchInput.jsx +++ b/src/components/manage/Blocks/Search/components/SearchInput.jsx @@ -13,7 +13,14 @@ const messages = defineMessages({ }); const SearchInput = (props) => { - const { data, searchText, setSearchText, isLive, onTriggerSearch } = props; + const { + data, + searchText, + setSearchText, + isLive, + onTriggerSearch, + removeSearchQuery, + } = props; const intl = useIntl(); return ( @@ -44,7 +51,7 @@ const SearchInput = (props) => { className="search-input-clear-icon-button" onClick={() => { setSearchText(''); - onTriggerSearch(''); + removeSearchQuery(); }} > diff --git a/src/components/manage/Blocks/Search/hocs/withSearch.jsx b/src/components/manage/Blocks/Search/hocs/withSearch.jsx index b810cc282f..1fb910b2aa 100644 --- a/src/components/manage/Blocks/Search/hocs/withSearch.jsx +++ b/src/components/manage/Blocks/Search/hocs/withSearch.jsx @@ -301,7 +301,7 @@ const withSearch = (options) => (WrappedComponent) => { id, query: data.query || {}, facets: toSearchFacets || facets, - searchText: toSearchText || searchText, + searchText: toSearchText ? toSearchText.trim() : '', sortOn: toSortOn || sortOn, sortOrder: toSortOrder || sortOrder, facetSettings, @@ -329,6 +329,16 @@ const withSearch = (options) => (WrappedComponent) => { ], ); + const removeSearchQuery = () => { + searchData.query = searchData.query.reduce( + // Remove SearchableText from query + (acc, kvp) => (kvp.i === 'SearchableText' ? acc : [...acc, kvp]), + [], + ); + setSearchData(searchData); + setLocationSearchData(getSearchFields(searchData)); + }; + const querystringResults = useSelector( (state) => state.querystringsearch.subrequests, ); @@ -347,6 +357,7 @@ const withSearch = (options) => (WrappedComponent) => { sortOrder={sortOrder} searchedText={urlSearchText} searchText={searchText} + removeSearchQuery={removeSearchQuery} setSearchText={setSearchText} onTriggerSearch={onTriggerSearch} totalItems={totalItems}