From bcde1554b65bb27ff92c33f420289f747f6ce82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Odini?= Date: Thu, 23 May 2024 15:41:40 +0200 Subject: [PATCH] refactor(Search page): Many small improvements on the search form (#582) --- src/components/LocationSelectorDialog.vue | 1 + src/constants.js | 1 + src/views/Search.vue | 30 ++++++++++++++++++---- tests/e2e/spec.cy.js | 13 ++++++++++ tests/fixtures/products_3011360030498.json | 28 ++++++++++++++++++++ 5 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 tests/fixtures/products_3011360030498.json diff --git a/src/components/LocationSelectorDialog.vue b/src/components/LocationSelectorDialog.vue index 3a818b59e01..c015664b611 100644 --- a/src/components/LocationSelectorDialog.vue +++ b/src/components/LocationSelectorDialog.vue @@ -169,6 +169,7 @@ export default { } }, search() { + this.$refs.locationInput.blur() this.results = null this.loading = true api.openstreetmapSearch(this.locationSearchForm.q, this.searchProvider) diff --git a/src/constants.js b/src/constants.js index d3b71adf6d8..20833c79380 100644 --- a/src/constants.js +++ b/src/constants.js @@ -33,6 +33,7 @@ export default { { key: 'opf', value: OPF_NAME, icon: OPF_ICON }, { key: 'opff', value: OPFF_NAME, icon: OPFF_ICON }, ], + QUERY_PARAM: 'q', FILTER_PARAM: 'filter', PRODUCT_FILTER_LIST: [ { key: 'hide_price_count_gte_1', value: 'FilterProductWithPriceCountHide' }, diff --git a/src/views/Search.vue b/src/views/Search.vue index c3b98cce19e..07cbab9976d 100644 --- a/src/views/Search.vue +++ b/src/views/Search.vue @@ -8,17 +8,21 @@ + + @@ -44,6 +48,7 @@ diff --git a/tests/e2e/spec.cy.js b/tests/e2e/spec.cy.js index 6213b19439e..5d9cbb0fbdd 100644 --- a/tests/e2e/spec.cy.js +++ b/tests/e2e/spec.cy.js @@ -1,10 +1,12 @@ describe('Basic tests', () => { beforeEach(() => { cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/products?page=1&size=10&order_by=-price_count', { fixture: 'products.json' }) + cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/products?page=1&size=10&code=3011360030498', { fixture: 'products_3011360030498.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/products/code/3011360030498', { fixture: 'product_3011360030498.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/products/code/0000000000000', { statusCode: 404, body: { "detail": "Product with code 35647000112700 not found" }}) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=1&order_by=-created*', { fixture: 'prices.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=10&order_by=-created', { fixture: 'prices.json' }) + cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=1&order_by=-date&product_code=3011360030498', { fixture: 'product_3011360030498_prices.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=10&order_by=-date&product_code=3011360030498', { fixture: 'product_3011360030498_prices.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=10&order_by=-date&category_tag=en%3Apitted-apricot', { fixture: 'pitted_apricot_prices.json' }) cy.intercept('GET', 'http://127.0.0.1:8000/api/v1/prices?page=1&size=10&order_by=-date&category_tag=en%3Aaaaaaaaaaaaa', { body: {"items":[],"total":0,"page":1,"size":10,"pages":0} }) @@ -81,4 +83,15 @@ describe('Basic tests', () => { cy.get('[data-name="price-card"]').should('have.length', 0) cy.contains('Load more').should('not.exist') }) + + it('displays the search page', () => { + cy.visit('/search?q=3011360030498') + cy.contains('Welcome to Open Prices!').should('not.exist') + cy.get('#product-title').contains('Mayonnaise Classique') + cy.get('#price-count').contains('1') + cy.contains('Latest price') + cy.get('[data-name="product-missing-chip"]').should('have.length', 0) + cy.get('[data-name="price-card"]').should('have.length', 0) + cy.contains('Load more').should('not.exist') + }) }) diff --git a/tests/fixtures/products_3011360030498.json b/tests/fixtures/products_3011360030498.json new file mode 100644 index 00000000000..56431b22186 --- /dev/null +++ b/tests/fixtures/products_3011360030498.json @@ -0,0 +1,28 @@ +{ + "items": [ + { + "code": "3011360030498", + "price_count": 1, + "id": 368, + "source": "off", + "product_name": "Mayonnaise Classique", + "product_quantity": 175, + "product_quantity_unit": null, + "categories_tags": [], + "brands": "Lesieur", + "brands_tags": [], + "labels_tags": [], + "image_url": "https://images.openfoodfacts.net/images/products/301/136/003/0498/front_en.119.400.jpg", + "nutriscore_grade": null, + "ecoscore_grade": null, + "nova_group": null, + "unique_scans_n": 78, + "created": "2024-02-18T19:39:38.162303+01:00", + "updated": "2024-02-18T19:39:38.186691+01:00" + } + ], + "total": 1, + "page": 1, + "size": 10, + "pages": 1 +}