Commit Graph

504 Commits

Author SHA1 Message Date
Karol Manijak 25bac5f030 Add condition to register blocks and variation in single product temp… (https://github.com/woocommerce/woocommerce-blocks/pull/10978)
* Add condition to register blocks and variation in single product template

* Improve the fix by providing default ancestor value to block registered for single product

* add E2E test

* add insert block

---------

Co-authored-by: Luigi Teschio <gigitux@gmail.com>
2023-09-22 08:27:12 +02:00
Daniel Dudzic 8b470177f4 Product Gallery: CSS styling tightening up (https://github.com/woocommerce/woocommerce-blocks/pull/10867)
* Product Gallery: Fix conflicts between block settings and CSS

* Product Gallery: Final CSS polishes

* Product Gallery: Minor CSS refactor

* Product Gallery: Revert the minor css refactor

* add custom class on the main div

* Product Gallery: Combine inner block styles and optimize them

* Product Gallery Inner Blocks: Remove imports to no longer existing stylesheet files

* Product Gallery: Change all references from wp-block to wc-block

* Product Gallery Inner Blocks: Remove loading of non-existent inner blocks stylesheet files

* Product Gallery: Add additional class to ensure correct width for single product gallery despite of the Next/Previous mode selected

* Product Gallery: Add final polishing

* fix zoom

* Product Gallery Thumbnails: Fix css

* Product Gallery Large Image Next Previous Buttons: Skip failing tests

---------

Co-authored-by: Luigi <gigitux@gmail.com>
2023-09-21 11:31:16 +00:00
Alexandre Lara 3ecd34e01a Upgrade webpack to version 5 (https://github.com/woocommerce/woocommerce-blocks/pull/8013)
* Upgrade terser-webpack-plugin to version 4.2.3

* Upgrade webpack-bundle-analyzer to 4.7.0

* Upgrade to Webpack version 5

* Upgrade @wordpress/dependency-extraction-webpack-plugin to 4.6.0

* Upgrade dependency copy-webpack-plugin to version 11.0.0

* Upgrade dependency terser-webpack-plugin to version 5.3.6

* Replace webpack-rtl-plugin with the new @automattic/webpack-rtl-plugin

* Replace module.issuer with the new ModuleGraph API

There is a warning appearing in the console when running the application. This is due to the fact that the module.issuer has been deprecated on Webpack 5 and replaced with the new ModuleGraph API. This commit replaces the deprecated API with the new one.

* Upgrade babel and babel plugins to latest version

* Replace jsonpFunction with the new uniqueName property

Add a unique name of the webpack build to avoid multiple webpack runtimes to conflict when using globals. It defaults to output.library name or the package name from package.json in the context, if both aren't found, it is set to an ''.

* Replace cacheDirectory inline configuration with options.cacheDirectory

* Upgrade @wordpress/e2e-tests dependency to version 5.6.0

* Remove babel-plugin-transform-react-jsx dependency

Remove babel-plugin-transform-react-jsx dependency because it is already included in @wordpress/babel-preset-default

* Remove unnecessary Babel dependencies

Remove some unnecessary babel dependencies that are already included in the @babel/preset-env package.

* Upgrade puppeteer dependency to version 16.2.0

* Remove caret from package.json dependencies

* Fix Storybook build error

This commit fixes the Storybook build error that was being caused because of Storybook by default uses Webpack 4, but since we are currently upgrading our webpack to version 5, we need to install some required dependencies and also explicitly tell Storybook to use Webpack 5.

* Fix package-lock.json after merging with trunk

* Add own webpack-rtl-plugin implementation to the project

Before upgrading Webpack to version 5, we were using the original `webpack-rtl-plugin` released by Romain Berger; unfortunately, this plugin is not compatible with Webpack 5, so we replaced it with `@automattic/webpack-rtl-plugin`. The problem is that `@automattic/webpack-rtl-plugin` by default generates files with the '.rtl.css' suffix and does not provide a way to change that.

This commit adds our own implementation of the `webpack-rtl-plugin` (adapted from `@automattic/webpack-rtl-plugin`) that is compatible with Webpack 5 and allows us to change the suffix of the generated files to follow the recommended way defined by Wordpress (https://codex.wordpress.org/Right-to-Left_Language_Support)

* Change conditional clause to be multiline

* Fix package-lock.json after merge with trunk

* Fix package-lock.json after merge with trunk

* Rename files to fix ESLint errors

This commit renames files that have the .js extension but contain JSX code. This is causing ESLint to throw errors because by default our Eslint configuration expects only files with the .jsx extension to contain JSX code.

* Fix package-lock.json file

* Add is-plain-obj module to the transformIgnorePatterns of jest config

* Update package-lock.json

* Fix package-lock.json

* Upgrade @wordpress/i18n dependency to version 4.31.0

* Update package-lock.json

* Update composer lock file

* Fix Webpack config for Webpack 5

* Add the package-lock.json

* Remove unsupported config from webpack

* Fix error with Webpack build

* Add wait for network idle to the tests

* Attempt to fix e2e test

* Restore promise.all

* Upgrade puppeteer to v17.1.3

* Upgrade expect-puppeteer

* Update expect-puppeteer

* Downgrade expect-puppeteer

* Revert "Upgrade puppeteer to v17.1.3"

This reverts commit 61ed52a56f131961f3970b6fb22cdd8b540bada3.

* Upgrade Puppeteer to version 17.1.3

* Fix executionContext.frame is not a function error

* Fix e2e tests

* Remove isExperimentalBuild from Product Gallery inner blocks

* Upgrade Webpack and Webpack-cli to latest version

* Upgrade postcss and mini-css plugins

* Fix error with mini-cart block

* Fix styling error with filter blocks

* Fix issue when running unit tests

* Fix storybook script not loading

* Fix a11y issue in Storybook

* Fix error when multiple isExperimentalBuild was being used

* Prevent error when layout is not present in the attributes object

* Update `chunkIds` to `named` in Webpack

* Add cache groups to the Webpack configs
2023-09-20 17:31:52 -03:00
Mike Jolley edf4a95b23 Feature Branch: Blockified Order Confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/10056)
* Main block types for confirmation

* Initial blocks

* Styling and placeholders

* Make blocks experimental

* Update summary icon

* Add name/description for status block and missing text descriptions in the block.

Closes woocommerce/woocommerce-blocks#10057

* Order confirmation: Convert Order Details Templates to Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10095)

* Move code from templates into the details block

* Details -> Totals

* Downloads block

* Sample content for downloads block

* Add block icon

* Add conversion template (https://github.com/woocommerce/woocommerce-blocks/pull/10077)

* Update inner block name

* Add default title constant

* Revert "Add default title constant"

This reverts commit 1dd3bbfecc1be83c367b1ab064f5032ea58cb678.

* Add global styles for order confirmation status block (https://github.com/woocommerce/woocommerce-blocks/pull/10164)

* Implement style controls

* Prevent link color spilling over onto wrapper

* Add styles and remove class names

* Remove __experimentalWritingMode

* Add global styles for order confirmation summary block (https://github.com/woocommerce/woocommerce-blocks/pull/10179)

* Styles for summary

* Remove __experimentalWritingMode

* Add table styles for order details (https://github.com/woocommerce/woocommerce-blocks/pull/10185)

* Add table styles for order details

* __experimentalFontWeight

* Add link styles

* Handle preview link styles

* Unauthenticated views for Order Confirmation template (https://github.com/woocommerce/woocommerce-blocks/pull/10414)

* Different views by permission

* check user id matches when logged out

* Add order confirmation wrapper block (https://github.com/woocommerce/woocommerce-blocks/pull/10286)

* Add a heading wrapper block

* Register the BillingWrapper Block server side

* Fix exception 'render_content' error

* Add the Billing Wrapper Block to the template

* Fix wrong block name error

* Fix php error

* Conditionally render Billing Address within the Wrapper

* Fix parent rendering

* Clean up code (remove billing address from the template)

* Update titles, descriptions, and icons of the billing Block and inner block

* Fix broken block by removing the "parent" keyword

* Use a user-friendly title and description for the Billing Wrapper

* Update Billing Wrapper Block's title case

Co-authored-by: Mike Jolley <mike.jolley@me.com>

* Fix PHP failing unit test

---------

Co-authored-by: Mike Jolley <mike.jolley@me.com>

* Remove "thanks" for authenticated page

* Introduce shipping wrapper based on billing wrapper

Closes woocommerce/woocommerce-blocks#10053

* Order confirmation block: Verify email address for guest customers (https://github.com/woocommerce/woocommerce-blocks/pull/10567)

* Add verify step for guest orders

* Render content to pass through block content

* Revert package changes

* Customer orders cannot use email to verify

* Add style controls for order shipping and billing address blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10633)

* Order confirmation block styling (https://github.com/woocommerce/woocommerce-blocks/pull/10780)

* Add missing heading to order details

* Summary block spacing

* Update css variables

* table styles

* Inherit border styles for cells

* Alignment and address styles

* Add downloads wrapper

* Style controls

* Fix typo

* Update Download Wrapper's Icon

* Fix TS error

* Disable Download Block's server side rendering in the editor

This fixes the loading after each style change from the style controls

* Clean up Downloads render functions

* Fix client side Downloads Block's table border

* Download + Total wrappers and tables styling

* small screen

* Remove server side render for previews

---------

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>

* Shorten template description

* Update test address data

* Avoid leaking order key in permission form

* Remove todo

* Make email form required.

* Remove edit page link

* Remove empty columns from address wrapper

* Remove IIFE

* typo

* Update description to mention billing

* Adjust link scss

* Fix wrapper markup and spacing controls

* Add link preview in editor

* Add initial E2E setup for the Order Confirmation Block (https://github.com/woocommerce/woocommerce-blocks/pull/10840)

* Fix WC_DateTime check

* Move form outside of block markup

* Add additional information block (https://github.com/woocommerce/woocommerce-blocks/pull/10842)

* Add block which contains hooks

* Use skeleton for placeholder instead of illustration

* Remove duplicate methods

* Remove duplicate align tag

* Update meta styles

* Tests for order confirmation conditional blocks (https://github.com/woocommerce/woocommerce-blocks/pull/10972)

* Add tests for conditional blocks

* Move setup into test

* Add E2E to the the Order Confirmation Block (https://github.com/woocommerce/woocommerce-blocks/pull/10863)

* Add editor util functions

* Update editor template E2E test

* Add the "exact" property for consistency

* Skip test

Can't get the element in the page. More investigation needed! Skipping
for now.

* Fix "transformIntoBlocks" logic

* Add tests for logged in user

* Fix "beforeAll" config

* Confirm downloads section is visible when logged in

* Create "verifyOrderConfirmationDetails" util function

* Add logged in test case

* Add Guest user test case

* Fix editor e2e testing

* Apply a proper teardown

* Fix failing tests after logout

* Ensure we are logged in before visiting the editor

* Ensure to have shipping selected

* Wait for changes to be saved on the editor

* Ensure shipping options is selected

* Remove comment

* Ensure we are logged in before going to the admin page

* Mark the Order Confirmation as a side effect test

* OrderConfirmation blocks are not experimental

* resolve merge conflict

* Revert package lock changes

* Fix enqueue_assets

* Fix CSS 404s

* Make template tests more robust

* Fix page URL for default confirmation page

* Try afterEach to log back in

* Skip guest/logout use cases

Login out causes other tests to fail. We will implement these case when
the multiple sign in roles are introduced in the codebase.

* Remove tests requiring login out & add comments

* Remove unused util functions

* Hide confirmation blocks from post editor

---------

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
2023-09-20 13:56:00 +01:00
Luigi Teschio 35e82fe4ec Fix: Password Protection not respected on single product template (https://github.com/woocommerce/woocommerce-blocks/pull/10999)
* Add password protection on the blockified Single Product Template

* Add E2E test

* fix unit test

* remove empty space
2023-09-20 07:17:13 +00:00
Mike Jolley 68064c115b Refactor Cart and Checkout Page Templates (https://github.com/woocommerce/woocommerce-blocks/pull/10773)
* Rename checkout template slug

* Remove redirect and custom title

* Classic shortcode block for checkout

* Empty title

* WIP placeholder

* Change blockified template

* Prefix cart and checkout templates with "Page: "

* Template migration routine

* Apply same treatment to cart template

* Notices

* Update placeholder text

* Classic shortcodes block

* Page content wrapper for templates

* Update default

* Do not save attributes

* Update templates

* Remove cart classic template

* Reverted endpoints for Cart & Checkout templates. This reverts PR 9406

* Migrate page content wrapper.

* Removed useless method arg. Minor tweaks.

* Skip migration if the theme has a template file for this page.

* Removed impossible condition.

* Migrate page content wrapper.

* Remove TemplateNotice in favour of DefaultNotice

* Documentation links in shortcode placeholder

* Hide cart and checkout page selector when using block themes

* Unused var

* Add tests for template changes

* Revert changes to classic-template

* Allow frontend redirect

* Unused file

* Bump version for updater

* Support x template naming as well as page-x

* Need to add item to cart to test checkout

* Fix header test by fixing utility for adding to cart

* Remove permalink tests

* Click body

* Wait for content to finish loading

* Wait for add to cart response when adding to cart without item name

* Wait for save before visiting frontend

* Set content instead of inserting block

* Perform test in site editor rather than page editor

* Prevent notice to set the default cart/checkout page from showing on the site editor.

---------

Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2023-09-19 10:58:18 +01:00
Patricia Hillebrandt 067626a155 Store Customization > Create a new endpoint within Store API for updating patterns with AI-generated content (https://github.com/woocommerce/woocommerce-blocks/pull/10881)
* Add the Jetpack Connection Package as a dependency for WooCommerce Blocks.

* Introduce the new Configuration Class for registering and enabling the Jetpack connection for sites and users.

* Introduce the Connection class for making requests to the GPT AI API.

* Update the get_jwt_token method.

* Update the error messages for the get_jwt_token method.

* Update the register_site method.

* Update the Configuration class structure and add Dependency Injection.

* Update structure for the Connection Class.

* Update the return type for the get_jwt_token method.

* Update method visibility for get_site_id

* Update the name and params for methods within the Connection Class

* Add tests for the Connecction class.

* Update the Constructor for the Configuration class.

* Add the Patterns class.

* Update the VerticalsSelector class.

* Update the constructor for PatternImages.

* Update the Store API Route for Patterns.

* Update the create_patterns_content method to ensure it returns the results of update_option.

* Add the new Patterns route to the RoutesController class.

* Update the route path and remove the business description validation as that is done via create_patterns_content

* Introduce the PatternsSchema

* Update the prompt, errors messages and output format for the Verticals Selector.

* Fix the missing file error for the Patterns Dictionary.

* Introduce the new get_patterns_dictionary method and update the create_patterns_content method to better handle errors.

* Update the returned response for the endpoint.

* Add the get_item_response method to the PatternsSchema class.

* Update response for when allow_ai_connection option is not set.

* Enable authentication for the endpoint.

* Modify and temporarily remove some failing tests for the AI API: a separate PR will be opened to clear those out later.
2023-09-15 15:44:15 +00:00
Luigi Teschio 11062e8600 Product Gallery Block: Add Product Gallery template to allow users to edit full mode view (https://github.com/woocommerce/woocommerce-blocks/pull/10823)
* Product Gallery: add support for On Sale Badge Block

* add align support

* Add E2E tests

* set margin via Block Styles

* disable experimental flag

* add next previous block

* restore support file

* fix TS error

* fix layout

* change product

* change product

* Product Gallert Block: Add zoom on hover

* set to true by default

* remove block is already registered error

* remove unecessary await

* Improve zoom logic

Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>

* Product Gallery Full view mode: Add the logic to render the dedicated template

* use template-part instead template

* add E2E tests

* update selectors

* add feature flag product gallery template part

* fix E2E tests

* remove not necessary file

---------

Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
2023-09-15 08:54:49 +00:00
Patricia Hillebrandt deb71f97fa Store Customization > Implement Client for requests to the GPT API (https://github.com/woocommerce/woocommerce-blocks/pull/10846)
* Add the Jetpack Connection Package as a dependency for WooCommerce Blocks.

* Introduce the new Configuration Class for registering and enabling the Jetpack connection for sites and users.

* Introduce the Connection class for making requests to the GPT AI API.

* Update the get_jwt_token method.

* Update the error messages for the get_jwt_token method.

* Update the register_site method.

* Update the Configuration class structure and add Dependency Injection.

* Update structure for the Connection Class.

* Update the return type for the get_jwt_token method.

* Update method visibility for get_site_id

* Update the name and params for methods within the Connection Class

* Add tests for the Connecction class.

* Update the Constructor for the Configuration class.
2023-09-12 08:41:43 +00:00
Daniel Dudzic 9db927de30 Product Gallery Thumbnails: Interactivity API directives (https://github.com/woocommerce/woocommerce-blocks/pull/10776)
* Fix "On sale" badge class for shop

* Add class to sale badge

* Move the thumbnails featching logic to an utils file. Add context directive with thumbnails data to the Product Gallery block. Add on-click directives to the Thumbnails block

* Product Gallery Thumbnails: Remove the legacy thumbnail markup

* Product Gallery Thumbnails: Add Large Image replacing

* update the main image when the thumbnail is clicked

* add E2E tests

* fix typo

* fix warning on the frontend

* address feedback

* update E2E test

* improve comment

* fix indentation

* improve E2E test

* improve flaky test

* improve E2E test

* improve comments

* improve E2E test

* try now

* add comment

* skip test

* reset script

* update todo comment

---------

Co-authored-by: Alba Rincón <alba.rincon@automattic.com>
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
Co-authored-by: Luigi <gigitux@gmail.com>
2023-09-12 09:36:44 +02:00
Alba Rincón 2d5d336aad [Store Customization] Make request to the Verticals API to fetch matching images and classify them (https://github.com/woocommerce/woocommerce-blocks/pull/10789)
* Add the Verticals API client

* Add tests

* Refactor error handling

* Create first version of the prompt class

* Improve Vertical selector and add tests

* Remove testing code

* Update class comment

* Add PatternImages class

* Pass the dictionary as param

* Add tests

---------

Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-09-11 15:39:15 +00:00
Alba Rincón 9d803a287a [Store Customization] Create a service to get the selected vertical from the business description and the verticals (https://github.com/woocommerce/woocommerce-blocks/pull/10778)
* Add the Verticals API client

* Add tests

* Refactor error handling

* Create first version of the prompt class

* Improve Vertical selector and add tests

* Remove testing code

* Update class comment

---------

Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-09-11 15:24:43 +00:00
Luigi Teschio 3c7b47b7d1 Product Gallery: fix warning (https://github.com/woocommerce/woocommerce-blocks/pull/10839)
* Product Gallery: fix warning

* address feedback

* fix logic

* rename function
2023-09-08 16:06:48 +02:00
Luigi Teschio 43c56e5383 Product Gallery Block: Add zoom on hovering on the frontend (https://github.com/woocommerce/woocommerce-blocks/pull/10791)
* Product Gallery: add support for On Sale Badge Block

* add align support

* Add E2E tests

* set margin via Block Styles

* disable experimental flag

* add next previous block

* restore support file

* fix TS error

* fix layout

* change product

* change product

* Product Gallert Block: Add zoom on hover

* set to true by default

* remove block is already registered error

* remove unecessary await

* Improve zoom logic

Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>

* Product Gallery Block: Add E2E tests for zoom while hovering setting (https://github.com/woocommerce/woocommerce-blocks/pull/10795)

---------

Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
2023-09-05 15:22:17 +02:00
Karol Manijak d9e17accf1 Fix the artifacts path for classic theme (https://github.com/woocommerce/woocommerce-blocks/pull/10837) 2023-09-05 15:03:56 +02:00
Alexandre Lara 2ebe7bd0c9 Product Gallery > Pager block: Fix block alignment (https://github.com/woocommerce/woocommerce-blocks/pull/10782)
* Fix block alignment with Large Image block

* Prevent error when layout is not present in the attributes object

* Add Large Image and Pager to its own group

* Fix issue when moving around the thumbnails block

* Fix e2e tests for Product Gallery block

* Change ancestor block for the Pager block
2023-09-05 09:52:19 -03:00
Sam Seay abd41cae11 Fixes for jest transpilation issues. (https://github.com/woocommerce/woocommerce-blocks/pull/10788)
* Fix bug where is-plain-obj is not transpiled by Jest, update lock.
* Update packages.
* Mock useSelect for a handful of RichText selectors in test.
* Resolve react to single version to avoid invalid hook errors.
* Patch trim-html locally to avoid a bug in the released npm source.
* Mock out resizeObserver to avoid https://github.com/FezVrasta/react-resize-aware/issues/58
* Don't transpile config package: https://github.com/node-config/node-config/issues/628
2023-09-05 04:03:35 +00:00
Karol Manijak ac7e115c3e Update @wordpress/env to 8.1.1 and re-enable PHP Unit Tests for PHP v 8.1 and 8.2 (https://github.com/woocommerce/woocommerce-blocks/pull/9875)
Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
Co-authored-by: Alexandre Lara <allexandrelara@gmail.com>
Co-authored-by: Luigi Teschio <gigitux@gmail.com>
Co-authored-by: Alba Rincón <alba.rincon@automattic.com>
Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
Co-authored-by: Tung Du <dinhtungdu@gmail.com>
2023-09-01 16:07:55 +07:00
Luigi Teschio 22b9f6a952 Product Gallery Block: add support for the on Sale Badge block (https://github.com/woocommerce/woocommerce-blocks/pull/10764)
* Product Gallery: add support for On Sale Badge Block

* add align support

* Add E2E tests

* set margin via Block Styles

* disable experimental flag

* add next previous block

* restore support file

* fix TS error

* fix layout

* change product
2023-08-31 18:15:31 +02:00
Luigi Teschio 2d89f4892d add side_effects suffix to the Product Gallery Large Image Next Previous Block (https://github.com/woocommerce/woocommerce-blocks/pull/10766) 2023-08-29 16:19:20 +02:00
Alba Rincón 035d8249ab [Store Customization MVP] Verticals API client (https://github.com/woocommerce/woocommerce-blocks/pull/10687)
* Add the Verticals API client

* Add tests

* Refactor error handling
2023-08-29 10:13:25 +02:00
Tung Du a92b8a432f E2E: ensure the shop page is created by creating it manually (https://github.com/woocommerce/woocommerce-blocks/pull/10744) 2023-08-29 08:00:29 +07:00
Luigi Teschio c126731347 Product Gallery Block: Next/Previous block (https://github.com/woocommerce/woocommerce-blocks/pull/10235)
* Add Product Gallery Next Previous block

* update description

* update registration

* improve style

* use context instead of attributes

* add eslint and ts lint exception

* improve CSS

* E2E Next Previous block (https://github.com/woocommerce/woocommerce-blocks/pull/10329)

* Add E2E tests

* fix e2e tests path after rebase

* add screenshots

* improve E2E test

* improve E2E test

* improve E2E test

---------

Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>

* fix webpack conf

* Next Previous Button block - Add layout support (https://github.com/woocommerce/woocommerce-blocks/pull/10668)

* Add layout support

* Product Gallery Next Previous: Fix block crashing in the editor when vertical alignment has not been customized yet

* Product Gallery Next Previous: Position fixes for the Next/Previous button both in the editor and frontend

* add E2E test

* fix import

---------

Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>

* Next Previous Buttons: hide buttons when the product has only one image (https://github.com/woocommerce/woocommerce-blocks/pull/10743)

* Next Previous Buttons: hide buttons when the product has only one image

* update URL

* fix import

* set default value

* fix E2E test

---------

Co-authored-by: Manish Menaria <the.manish.menaria@gmail.com>
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
2023-08-28 18:32:45 +02:00
Thomas Roberts 55f65cdf17 Move cart widget tests to playwright and ensure classic/block theme configs are executed correctly (https://github.com/woocommerce/woocommerce-blocks/pull/10669) 2023-08-28 03:04:28 -07:00
Tung Du 69d5f47048 E2E: Refactor Mini Cart to be ready for fully parallel (https://github.com/woocommerce/woocommerce-blocks/pull/10704) 2023-08-24 20:33:20 +07:00
Tung Du e20c605408 E2E: Ensure the Shop page is created (https://github.com/woocommerce/woocommerce-blocks/pull/10695) 2023-08-24 08:09:59 +07:00
Thomas Roberts 38594b3c9f Cart e2e test housekeeping (https://github.com/woocommerce/woocommerce-blocks/pull/10663) 2023-08-22 16:31:38 -07:00
Tung Du 1868b62ba0 E2E: Improve the setup script (https://github.com/woocommerce/woocommerce-blocks/pull/10611) 2023-08-22 17:32:05 +07:00
Daniel Dudzic 601adc6e1f Product Gallery Large Image: Add E2E test (https://github.com/woocommerce/woocommerce-blocks/pull/10482) 2023-08-18 14:02:06 +02:00
Manish Menaria f40131c33e Remove client side navigation from Products beta block (https://github.com/woocommerce/woocommerce-blocks/pull/10636)
* Remove client side navigation from Products beta block

Changes:
- Removed the `add_navigation_id_directive` method and its associated filter. This method previously added a `data-wc-navigation-id` attribute to the query block for client-side navigation, which is no longer required.
- Removed the `add_navigation_link_directives` method and its associated filter. This method previously added interactive directives to pagination links inside the Query Pagination block. This specific functionality has been removed as it is no longer needed.
- Introduced a new method `mark_block_as_interactive`, which is designed to mark the Product Query as an interactive region so that interactive elements can work inside it. This is achieved using the 'data-wc-interactive' attribute.

* add data-wc-interactive to product button block

* Remove unnecessary code

As we have added `data-wc-interactive` on Product button therefore we don't need to add it in Product Query block.

* Boolean attribute doesn't need explicit value equal to true

* Skip failing i18n-related E2E tests

* Skip failing i18n-related E2E test

---------

Co-authored-by: Luigi <gigitux@gmail.com>
Co-authored-by: Niels Lange <info@nielslange.de>
2023-08-17 15:45:59 +02:00
Karol Manijak 1d3cffff42 Add E2E tests for Product Collection with Compatibility Layer (https://github.com/woocommerce/woocommerce-blocks/pull/10540)
* Add E2E tests for Product Collection with Compatibility Layer

* Remove unnecessary changes

* Rename the file so it covers side effects and improve imports

* Rename the file to the correct suffix - side_effects instead of side-effects
2023-08-16 11:54:09 +02:00
Tung Du 97b22cc17a Better handling tests with global side effects (https://github.com/woocommerce/woocommerce-blocks/pull/10508) 2023-08-16 12:23:43 +07:00
Thomas Roberts ad9b732629 Convert shipping selection Checkout tests to playwright (https://github.com/woocommerce/woocommerce-blocks/pull/10532)
* Create selectAndVerifyShippingOption method

* Add goToCheckout util

* Add emptyCart util

* Add selectAndVerifyShippingOption to FrontendUtils class

* Add initial checkout shopper test file and a shipping options test

* Remove selectAndVerifyShippingOptions from frontendUtils

* Re-add selectAndVerifyShippingOption to checkout block test

* Move cart and checkout blocks into their own directories

* Create CheckoutPage class to keep utils for checkout

* Use CheckoutPage class in Checkout tests

* Update name of test suite

* Remove nested describe

* Move to correct folder, make selectAndVerifyShippingOption return

* Remove networkidle and goToCheckout from frontendutils

* Add placeOrder util

* Add fillBilingDetails util to checkout page

* Add fillShippingDetails util to checkout page

* Add fillInCheckoutWithTestData util to checkout page

* Add checkCustomerPushCompleted util to checkout page

* Change test to focus on free shipping and flat rate in separate tests

* Instead of waiting for selector, just wait for the shipping name

* Check element visibility instead of count

* Use postcode id rather than autocomplete value

* Don't instantiate FrontendUtils

* Delete tests that have been moved to playwright

* Add test to side effects project because it adds items to cart

* Remove unused method

* Go to cart page before removing items

This is to ensure the cart data store is loaded

* Empty cart before proceeding with tests

* Re-implement goToCheckout to frontendUtils

* Remove check for whether customer data has been pushed

Rely instead on order complete page to check for address details.

* Ensure request to set shipping option is complete

* Get email address from page not billing form (its not there)

* Move testData to class property

* Add verifyAddressDetails util

* Make test check for setting different addresses and shipping in same run

* Remove User can have different shipping and billing addresses from jest

* Pass in playwright's request to the frontend utils file

* Update emptyCart function to use API requests to empty the cart

* Pass request utils to frontendUtils class

* Update frontendUtils to use requestUtils for API requests
2023-08-15 03:42:29 -07:00
Mike Jolley 566513e3ed Simplify code path and remove todo (https://github.com/woocommerce/woocommerce-blocks/pull/10526) 2023-08-11 10:44:50 +01:00
Tung Du 40d8eb8ac9 Fix: Adjust Playwright E2E tests for WP 6.3 (https://github.com/woocommerce/woocommerce-blocks/pull/10516)
Co-authored-by: Luigi <gigitux@gmail.com>

- Updates the `@wordpress/e2e-test-utils-playwright` package to use the npm release.
- Removes hard-coded WP version in `.wp-env.json` to use the latest Core release.
- Fixes failing Playwright tests when using WP 6.3.
- Pins the core version (6.2.2) for Jest E2E tests so they can keep passing. We decided not to fix those tests because we're moving to Playwright.
2023-08-11 06:28:38 +07:00
Luigi Teschio b90e0ffdc9 Interactivity API and Product Button (https://github.com/woocommerce/woocommerce-blocks/pull/10006)
* Update Interactivity API JS files

* Disable TS checks in the Interactivity API for now

* Add new SSR files

* Replace wp_ prefixes with wc_ ones

* Replace wp- prefix with wc-

* Replace guternberg_ prefix with woocommerce_

* Remove file comments from Gutenberg

* Rename files with `wp` prefix

* Fix code to load Interactivity API php files

* Remove TODO comments

* Replace @wordpress with @woocommerce

* Update Webpack configuration

* Fix directive prefix

* Remove interactivity folder from tsconfig exclude

* Add client-side navigation meta tag code

* Remove unneeded blocks.php file

* Fix store tag id

* Register Interactivity API runtime script

* Fix Interactivity API runtime registering

* Remove all files related to directive processing in PHP

* Move json_encode to Store's render method

* WIP

* WIP

* WIP

* WIP

* Preserve previous context

* Ignore Minicart block on client-side navigation

* Refresh page on store updatRefresh page on store updatee

* Refactor logic

* Add console error when a path is missing

* fix PHP lint error

* WIP store

* use store approach

* update jest configuration

* restore Mini Cart changes

* move cart store subscription to interactivity package

* move interactivity flag

* format HTML

* move addToCartText to the context

* Load product-query stylesheet when rendering the Products block

* update sideEffects array

* fix catch

* rename moreThanOneItem to isThereMoreThanOneItem

* improve how scripts are enqueued

* update default value for the filter woocommerce_blocks_enable_interactivity_api

* Update assets/js/atomic/blocks/product-elements/button/block.json

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

* Update assets/js/interactivity/cart/cart-store.ts

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

* fix block.json

* remove updateStore function

* restore interactivity api changes

* import cart store

* show notice when there is an error

* add logic to dequeue script on classic themes and block themes

* imrpove logic about notice

* Interactivity API: add `afterLoad` callbacks to `store()` function (https://github.com/woocommerce/woocommerce-blocks/pull/10338)

* show notice when there is an error

* Add initial implementation for store callbacks

* Run `afterLoad` callbacks after `init`

* Move cart state subscription to Product button

* Remove cart-store from Interactivity API internals

* Change callbacks with options and save only afterLoad callbacks

* ProductButton: Add animation (https://github.com/woocommerce/woocommerce-blocks/pull/10351)

* implement animation

* improve logic

* refactor logic

* refactor code

* address feedback about code style

* add support for woocommerce_add_to_cart_quantity

* Fix animation flickering

* Introduce wp-effect, reduce the amount of numberOfItem variables to 2 and consolidate animation status

* add support for added class

* Remove unnecessary selector

* Don't fetch cart if it was already fetched

* remove added class

---------

Co-authored-by: Luis Herranz <luisherranz@gmail.com>

---------

Co-authored-by: Luigi <gigitux@gmail.com>
Co-authored-by: Luis Herranz <luisherranz@gmail.com>

* update deepsignal

* remove added class

* update deepsignal

* Interactivity API and Product Button: Add E2E tests (https://github.com/woocommerce/woocommerce-blocks/pull/10036)

* Add FrontendUtils class

* fix conflicts

* use locator

* restore click usage

* Product Button: Add E2E test

* fix util

* fix E2E tests

* remove comment

* Add E2E test to ensure that woocommerce_product_add_to_cart_text works

* update sideEffects array

* add zip and unzip as package

* fix wp-env configuration

* fix E2E test

* add report

* try now

* try now

* try now

* fix E2E test

* E2E: Add documentation for testing actions and filters. Fixes woocommerce/woocommerce-blocks#10135 (https://github.com/woocommerce/woocommerce-blocks/pull/10206)

* update description

* fix label

* rename files

* make requestUtils private

* remove page.goto

* use toHaveCount

* use productsToDisplay variable

* fix E2E tests

* rename class utils

---------

Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>

---------

Co-authored-by: David Arenas <david.arenas@automattic.com>
Co-authored-by: Luis Herranz <luisherranz@gmail.com>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
2023-08-10 14:02:33 +00:00
Mike Jolley 4fd16267be Refactor Push Changes Readability and Performance (https://github.com/woocommerce/woocommerce-blocks/pull/10315)
* Add local state to address-form

* Update test with valid postcode and required fields

* Push changes refactoring

* Avoid loops due to retrying same data

* Callbacks to prevent rerenders

* Move validation functions

* Filter incoming values to only those included as fields to prevent errors

* Keep track of country changes to prevent excessive updates of addressFormFields.

* Use helpers in test

* Fill company

* Revert local state in address form

* Update address form to remove validation handling for postcode (country clears the field).

* Revert "Update test with valid postcode and required fields"

This reverts commit 718a6006df24f6e957297ad4d1ef9d6f690793bd.

* Clear postcode when country changes if invalid

* Revalidate fields when country changes

* Comment for pick

* Revert unneccessary test change

* Revery moving of functions to reduce diff size

* Increase push timeout in tests

* Revert test changes
2023-08-09 18:24:51 +01:00
Thomas Roberts f3bdfaee98 Update E2E util to allow adding to cart by name from the shop page (https://github.com/woocommerce/woocommerce-blocks/pull/10507)
* Allow adding to cart by name from the shop page

* Remove networkidle
2023-08-09 16:17:05 +02:00
Mike Jolley 2b80d3e830 Rename commands and directories for Playwright and JEST e2e tests (https://github.com/woocommerce/woocommerce-blocks/pull/10493)
* Move e2e to e2e-jest

* Move e2e-pw to e2e

* Update e2e usage + scripts

* Missed some directory renames

* Update gitignore

* Remove test results as its in gitignore
2023-08-08 17:58:12 +01:00
Luigi Teschio be1cefc4b4 Add ESLint `eslint-plugin-playwright` package (https://github.com/woocommerce/woocommerce-blocks/pull/10487)
* Add eslint playwright plugin configuration

* replace networkidle with commit

* address  Unnecessary await expression. This method does not return a Promise error

* address 'Unexpected usage of not.toBeVisible(). Use toBeHidden() instead' error

* address 'Unexpected use of the .skip()  annotation.' error

* address 'toHaveCount' must be awaited or returned' error

* address ''page' is defined but never used '

* address ''toBeVisible' must be awaited or returned'

* address 'Unexpected use of element handles'

* address 'Unnecessary await expression. This method does not return a Promise'

* address 'Test has no assertions'

* address 'Unexpected use of page.waitForTimeout()'

* address 'Avoid having conditionals in tests'
2023-08-08 13:25:45 +00:00
Thomas Roberts 8e79fdcc45 Preliminary work to add Playwright E2E tests for the Cart block & merchant cart tests (https://github.com/woocommerce/woocommerce-blocks/pull/9739)
* Add cartCheckout project

* Add navigation utils

* Add global block inserter utils to EditorUtils class

* Add initial Cart block tests

* Add slug to block data type

* Get block editor selector when navigating in editor

* add test for inner block filtering

* Update navigation util to use block name instead of title

* Add view switcher test

* Update block name/title

* Run only cart/checkout tests in cartCheckout project

* Remove old comment

* Update selector to use locator instead

* Revert selector type change

* Fix TS issues

* Remove unnecessary admin state

* Update tests to use editorUtils and fix TS issue with selector

* Replace string concatenation with template

* Rename cart test to contain block_theme suffix

* Change page to editor.page and use canvas where necessary

* Rename directory to cart-checkout

* Wait for editor response before continuing

* Remove cartcheckout playwright project

* Remove typecast and switch to .toNotBeHidden

* Remove double comment

* Force click the empty cart button

* Wait for empty cart button for longer

* Isolate test to run in CI

* Dispatch click event instead of simulating click

* Remove timeouts

* Revert "Isolate test to run in CI"

This reverts commit 28af5a50700476639d0a4f12fca9800a4a5aed91.
2023-08-07 08:59:06 -07:00
Mike Jolley 427fe33af3 Fix wcSettings inconsistent property naming style (https://github.com/woocommerce/woocommerce-blocks/pull/10439)
* Mass convert all snake case settings keys to camel case

* Handling for payment method data props
2023-08-07 11:30:53 +01:00
Daniel Dudzic c411137ba4 E2E: Product Gallery Thumbnails block tests (https://github.com/woocommerce/woocommerce-blocks/pull/10370)
* WIP Product Gallery: Add the Thumbnails block

* Product Gallery Thumbnails: Add block settings

* Add template for the Product Gallery block

* Add template for the Product Gallery block. Add the rest of the files.

* Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block.

* Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block.

* Product Gallery Thumbnails: Move the static template ouside of the component

* Make sure the context is set before accesing the array values

* Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc

* Product Gallery Thumbnails: Fix TS error

* Product Gallery Thumbnails: Remove unused stylesheet

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend.

* Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically

* E2E: Add tests for the Product Gallery Thumbnails block

* Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down

* Product Gallery Thumbnails: Add failure handling

* Product Gallery Thumbnails: Fix the eslint dependency error

* Product Gallery Thumbnails: Add inner blocks to the sideEffects array

* Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file

* Product Gallery Thumbnails: Update the utils file

* Product Gallery Thumbnails: Update the utils file. Fix comment indentation

* Product Gallery Thumbnails: Fix failing tests

* Revert unrelated package.json changes

* Product Gallery Thumbnails: Further package.json reverts

* Product Gallery Thumbnails: Rename the test screenshots

* Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set

* Product Gallery: Rename clientId to productGalleryClientId

* Product Gallery Thumbnails: Combine the useEffect code having the same dependencies

* Product Gallery Thumbnails: Combine all useEffect code together

* Product Gallery Thumbnails: Add a ThumbnailsPosition enum

* Product Gallery Thumbnails: Update the thumbnailsPosition to an enum

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Fix TS errors

* Product Gallery Thumbnails: Add missing dependency

* Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block

* Product Gallery Thumbnails: Fix E2E tests

* Product Gallery Thumbnails: Remove unused function from frontend utils

* Product Gallery Thumbnails: Remove unused screenshots and config amendment

* Product Gallery Thumbnails: Add check for the order of block on the frontend

* Product Gallery: Add crop, zoom and full-screen settings

* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error

* Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error

* Product Gallery Thumbnails: Revert back to ts-ignore

* Revert "Product Gallery: Add crop, zoom and full-screen settings"

This reverts commit 840654197619e2611029b81990493387ae0b543d.

* Product Gallery: Add crop, zoom and full-screen settings

* Product Gallery: Remove the redundant React Fragment

* Product Gallery E2E: Simplify and combine the tests
2023-08-04 13:07:31 +02:00
Manish Menaria bf60eb60e7 Product collection - Fix test_merging_filter_by_attribute_queries unit test (https://github.com/woocommerce/woocommerce-blocks/pull/10302)
* Add PHPUnit tests for the ProductCollection block type

This commit introduces PHPUnit tests for the ProductCollection block type. A new test file, `ProductCollection.php`, has been added under the `BlockTypes` directory within the tests. The test file sets up a mock instance of `ProductCollection` and verifies its behavior. Particularly, it tests the merging of on-sale queries, ensuring the results are as expected.

To assist in the testing, a new mock class, `ProductCollectionMock`, has been created under the `Mocks` directory. This class extends the `ProductCollection` block type and provides methods for setting parsed block data and attribute filter query arguments.

These tests should help ensure the correctness and reliability of the `ProductCollection` block type.

* Expand PHPUnit tests for ProductCollection block to cover stock status queries

This commit expands the existing PHPUnit tests for the ProductCollection block type to cover scenarios involving stock status queries. Specifically, a new test method, `test_merging_stock_status_queries`, has been added.

This method tests if the 'woocommerceStockStatus' attribute is correctly merged into the query parameters. It verifies that the stock status is correctly incorporated into the 'meta_query' array as part of the constructed query.

This addition enhances the coverage of our test suite, ensuring that the ProductCollection block behaves as expected in scenarios involving stock status queries.

* Add extensive testing for ProductCollection block's query merging

The following test methods were added:

1. `test_merging_default_stock_queries`: This tests the merging of default stock queries, verifying the absence of meta_query in certain conditions.

2. `test_merging_attribute_queries`: This tests the merging of attribute queries, ensuring the correct taxonomy and terms are used in the merged tax_query.

3. `test_merging_order_by_rating_queries` and `test_merging_order_by_popularity_queries`: These test the merging of order by queries, checking for the right orderby and meta_key in the merged query.

4. `test_product_visibility_query_exist_in_merged_query`: This tests if the product visibility query exists in the merged query.

This additional testing improves the reliability and coverage of our tests, ensuring the correct functionality of the ProductCollection block's query merging process.

* Add unit tests for merged queries in ProductCollection block

- Merging multiple queries
- Merging filter by max price queries
- Merging filter by min price queries
- Merging filter by min and max price queries
- Merging filter by stock status queries
- Merging filter by attribute queries
- Merging multiple filter queries

These tests use PHPUnit assertions to validate the correctness of the merged queries.

* Add tests for REST query modifications in ProductCollection block

This commit adds two new test cases and a helper method to the `ProductCollection` test class.

The helper method, `build_request()`, constructs a simplified `WP_REST_Request` object for testing purposes. This request object simulates a typical request from the ProductCollection block, including potential WooCommerce parameters such as 'woocommerceOnSale', 'woocommerceAttributes', and 'woocommerceStockStatus'.

The first new test, `test_updating_rest_query_without_attributes()`, tests the block's capability to modify a REST query that doesn't include any product attribute filters. It verifies that the correct '_stock_status' and 'product_visibility' parameters are set in the meta and tax queries respectively.

The second test, `test_updating_rest_query_with_attributes()`, does the same as the previous one but with the inclusion of a product attribute filter in the REST request. This test verifies that the block can handle REST queries with attribute filters correctly.

These tests improve coverage on the ProductCollection block's REST query handling, ensuring that it can merge different filter queries correctly.

* Add test for merging taxonomies query in ProductCollection block

This commit introduces a new test, `test_merging_taxonomies_query()`, in the `ProductCollection` test class.

The test simulates a situation where the block has to merge taxonomy queries related to product categories and tags. The parsed block attributes are configured to include 'product_cat' and 'product_tag' taxonomies with certain term IDs.

The test then asserts that the merged query correctly includes these taxonomies with the appropriate term IDs and 'include_children' set to false. This confirms that the block correctly merges taxonomy filters when building the final query.

* Fix failing test

* Try again

* Try again

* Remove test_merging_filter_by_attribute_queries test

This commit removes the `test_merging_filter_by_attribute_queries()` test from the `ProductCollection` test class.

* Reintroduce test for merging attribute filter queries

This commit reintroduces the `test_merging_filter_by_attribute_queries()` test in the `ProductCollection` test class.

The test checks the correct merging of queries when filtering by color and size attributes. It sets various query variables and asserts the correct structure and content of the merged query.

This could be because the previous removal of this test was a mistake, or because changes in the code have once again made this test relevant.

* fix: passing correct block instance to build_frontend_query method

---------

Co-authored-by: Tung Du <dinhtungdu@gmail.com>
2023-07-31 14:12:03 +05:30
dependabot[bot] f218cfb51e Bump phpunit/phpunit from 8.5.33 to 9.2.6 (https://github.com/woocommerce/woocommerce-blocks/pull/9188)
* Bump phpunit/phpunit from 8.5.33 to 9.2.6

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 8.5.33 to 9.2.6.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.2.6/ChangeLog-9.2.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/8.5.33...9.2.6)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update dependencies to avoid conflicts in php8

* Fix test due to array order of values

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-07-28 16:19:45 +01:00
dependabot[bot] 5ca496c20b Bump yoast/phpunit-polyfills from 1.0.5 to 2.0.0 (https://github.com/woocommerce/woocommerce-blocks/pull/9795)
* Bump yoast/phpunit-polyfills from 1.0.5 to 2.0.0

Bumps [yoast/phpunit-polyfills](https://github.com/Yoast/PHPUnit-Polyfills) from 1.0.5 to 2.0.0.
- [Release notes](https://github.com/Yoast/PHPUnit-Polyfills/releases)
- [Changelog](https://github.com/Yoast/PHPUnit-Polyfills/blob/2.x/CHANGELOG.md)
- [Commits](https://github.com/Yoast/PHPUnit-Polyfills/compare/1.0.5...2.0.0)

---
updated-dependencies:
- dependency-name: yoast/phpunit-polyfills
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Remove expect exception usage

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-07-28 12:53:40 +01:00
Albert Juhé Lluveras 22be5a532a Add tests in Playwright for Mini-Cart drawer closing (https://github.com/woocommerce/woocommerce-blocks/pull/10305)
* Add tests in Playwright for Mini-Cart drawer closing

* Make use of waitForSelector instead of waitForTimeout

* Make use of waitForSelector instead of waitForTimeout (II)
2023-07-27 08:53:24 +02:00
Manish Menaria 6e10e2fbcb Product Collection - Add PHP unit tests (https://github.com/woocommerce/woocommerce-blocks/pull/10289)
* Add PHPUnit tests for the ProductCollection block type

This commit introduces PHPUnit tests for the ProductCollection block type. A new test file, `ProductCollection.php`, has been added under the `BlockTypes` directory within the tests. The test file sets up a mock instance of `ProductCollection` and verifies its behavior. Particularly, it tests the merging of on-sale queries, ensuring the results are as expected.

To assist in the testing, a new mock class, `ProductCollectionMock`, has been created under the `Mocks` directory. This class extends the `ProductCollection` block type and provides methods for setting parsed block data and attribute filter query arguments.

These tests should help ensure the correctness and reliability of the `ProductCollection` block type.

* Expand PHPUnit tests for ProductCollection block to cover stock status queries

This commit expands the existing PHPUnit tests for the ProductCollection block type to cover scenarios involving stock status queries. Specifically, a new test method, `test_merging_stock_status_queries`, has been added.

This method tests if the 'woocommerceStockStatus' attribute is correctly merged into the query parameters. It verifies that the stock status is correctly incorporated into the 'meta_query' array as part of the constructed query.

This addition enhances the coverage of our test suite, ensuring that the ProductCollection block behaves as expected in scenarios involving stock status queries.

* Add extensive testing for ProductCollection block's query merging

The following test methods were added:

1. `test_merging_default_stock_queries`: This tests the merging of default stock queries, verifying the absence of meta_query in certain conditions.

2. `test_merging_attribute_queries`: This tests the merging of attribute queries, ensuring the correct taxonomy and terms are used in the merged tax_query.

3. `test_merging_order_by_rating_queries` and `test_merging_order_by_popularity_queries`: These test the merging of order by queries, checking for the right orderby and meta_key in the merged query.

4. `test_product_visibility_query_exist_in_merged_query`: This tests if the product visibility query exists in the merged query.

This additional testing improves the reliability and coverage of our tests, ensuring the correct functionality of the ProductCollection block's query merging process.

* Add unit tests for merged queries in ProductCollection block

- Merging multiple queries
- Merging filter by max price queries
- Merging filter by min price queries
- Merging filter by min and max price queries
- Merging filter by stock status queries
- Merging filter by attribute queries
- Merging multiple filter queries

These tests use PHPUnit assertions to validate the correctness of the merged queries.

* Add tests for REST query modifications in ProductCollection block

This commit adds two new test cases and a helper method to the `ProductCollection` test class.

The helper method, `build_request()`, constructs a simplified `WP_REST_Request` object for testing purposes. This request object simulates a typical request from the ProductCollection block, including potential WooCommerce parameters such as 'woocommerceOnSale', 'woocommerceAttributes', and 'woocommerceStockStatus'.

The first new test, `test_updating_rest_query_without_attributes()`, tests the block's capability to modify a REST query that doesn't include any product attribute filters. It verifies that the correct '_stock_status' and 'product_visibility' parameters are set in the meta and tax queries respectively.

The second test, `test_updating_rest_query_with_attributes()`, does the same as the previous one but with the inclusion of a product attribute filter in the REST request. This test verifies that the block can handle REST queries with attribute filters correctly.

These tests improve coverage on the ProductCollection block's REST query handling, ensuring that it can merge different filter queries correctly.

* Add test for merging taxonomies query in ProductCollection block

This commit introduces a new test, `test_merging_taxonomies_query()`, in the `ProductCollection` test class.

The test simulates a situation where the block has to merge taxonomy queries related to product categories and tags. The parsed block attributes are configured to include 'product_cat' and 'product_tag' taxonomies with certain term IDs.

The test then asserts that the merged query correctly includes these taxonomies with the appropriate term IDs and 'include_children' set to false. This confirms that the block correctly merges taxonomy filters when building the final query.

* Fix failing test

* Try again

* Try again

* Remove test_merging_filter_by_attribute_queries test

This commit removes the `test_merging_filter_by_attribute_queries()` test from the `ProductCollection` test class.
2023-07-21 15:43:22 +05:30
Darren Ethier f708593adb Add Color Panel (https://github.com/woocommerce/woocommerce-blocks/pull/10062)
* Add new ColorPanel component

* Implement new ColorPanel component for the Mini-Cart

* Move ColorPanel types into their own types.ts file alongside the ColorPanel component

* Add useColorPanelStyles hook

* Rename classes to className

* Disable @wordpress/no-unsafe-wp-apis

* Fix tests: Move defaultColorItem object to utils file

* Remove unnecssary types from QuantityBadge

* Fix conflicts

* Remove context

* Fix color picker JS error

* Migrate attribute data to be compatible with ColorPanel component

* Fix incompatible attributes

* Remove useColorPanelStyles hook

* migrateAttributesToColorPanel JS unit tests

* PHP MiniCartUtils tests

* Remove unncessary code for classNames in MiniCart edit

---------

Co-authored-by: tjcafferkey <tjcafferkey@gmail.com>
2023-07-21 10:35:32 +01:00
Albert Juhé Lluveras d248d62db1 Add Mini-Cart block Playwright e2e tests (https://github.com/woocommerce/woocommerce-blocks/pull/9757)
* Add Mini-Cart block Playwright e2e tests

* Verify tests fail

* Revert "Verify tests fail"

This reverts commit 47f666657d8a37bb486a4510ece44fd4d82c031d.

* Fix permalink-settings test
2023-07-21 09:44:01 +02:00