Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Booking products tests #2438

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions tests/pw/pages/productsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ export class ProductsPage extends AdminPage {
async cantAddGreaterMin(productName: string, minMaxOption: product['productInfo']['minMax']): Promise<void> {
await this.goToProductEdit(productName);
await this.clearAndType(productsVendor.minMax.minimumQuantity, minMaxOption.minimumProductQuantity);
await this.clearInputField(productsVendor.minMax.maximumQuantity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove redundant input field clearing

The clearInputField call is unnecessary since clearAndType on the next line already handles clearing the input field before typing the new value.

- await this.clearInputField(productsVendor.minMax.maximumQuantity);

Committable suggestion skipped: line range outside the PR's diff.

await this.clearAndType(productsVendor.minMax.maximumQuantity, minMaxOption.maximumProductQuantity);
await this.press('Tab'); // to trigger validation
await this.toHaveValue(productsVendor.minMax.maximumQuantity, minMaxOption.minimumProductQuantity);
Expand Down
60 changes: 35 additions & 25 deletions tests/pw/pages/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5229,7 +5229,13 @@ export const selector = {
accommodationBooking: '#\\_is_dokan_accommodation',
productCategory: '#select2-product_cat-container',
productCategoryInput: '.select2-search--dropdown > .select2-search__field',
tags: '.select2-search__field',
// tags
tags: {
tagInput: '//select[@id="product_tag"]/..//input[@class="select2-search__field"]',
searchedTag: (tagName: string) => `//li[@class="select2-results__option select2-results__option--highlighted" and normalize-space(text())="${tagName}"]`,
selectedTags: (tagName: string) => `//li[@class="select2-selection__choice" and contains(., "${tagName}")]`,
removeSelectedTags: (tagName: string) => `//li[@class="select2-selection__choice" and contains(., "${tagName}")]//span[@class="select2-selection__choice__remove"]`,
},
Comment on lines +5232 to +5238
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Review tag selector implementation for consistency and maintainability

The tag selector implementation has been updated with the following structure:

  • tagInput: Uses XPath to locate the tag input field with a fallback selector
  • searchedTag: Locates highlighted tag search results
  • selectedTags: Finds selected tag elements
  • removeSelectedTags: Locates remove buttons for selected tags

Consider the following improvements:

-    tagInput: '//select[@id="product_tag"]/..//input[@class="select2-search__field"]',
+    tagInput: '.select2-search__field',

-    searchedTag: (tagName: string) => `//li[@class="select2-results__option select2-results__option--highlighted" and normalize-space(text())="${tagName}"]`,
+    searchedTag: (tagName: string) => `.select2-results__option--highlighted:contains("${tagName}")`,

Rationale:

  1. Use simpler CSS selectors where possible for better maintainability
  2. Avoid complex XPath when CSS selectors can achieve the same result
  3. Keep selector structure consistent with other parts of the codebase

Committable suggestion skipped: line range outside the PR's diff.


// Accommodation Booking Options
minimumNumberOfNightsAllowedInABooking: '#\\_wc_booking_min_duration',
Expand All @@ -5240,9 +5246,9 @@ export const selector = {
// General Booking Options
bookingDurationType: '#\\_wc_booking_duration_type',
bookingDuration: 'input#\\_wc_booking_duration',
bookingDurationUnit: '#\\_wc_booking_duration_unit',
bookingDurationMin: 'input#\\_wc_booking_min_duration',
bookingDurationMax: 'input#\\_wc_booking_max_duration',
bookingDurationUnit: '#\\_wc_booking_duration_unit',

calendarDisplayMode: '#\\_wc_booking_calendar_display_mode',

Expand Down Expand Up @@ -5274,7 +5280,7 @@ export const selector = {
maximumBookingWindowIntoTheFutureDateUnit: '#\\_wc_booking_max_date_unit',
requireABufferPeriodOfMonthsBetweenBookings: '#\\_wc_booking_buffer_period',
adjacentBuffering: '#\\_wc_booking_apply_adjacent_buffer',
allDatesAre: '#\\_wc_booking_default_date_availability',
allDatesAvailability: '#\\_wc_booking_default_date_availability',
checkRulesAgainst: '#\\_wc_booking_check_availability_against',
restrictStartAndEndDays: '#dokan_booking_has_restricted_days_field',
sunday: '#\\_wc_booking_restricted_days\\[0\\]',
Expand Down Expand Up @@ -5313,34 +5319,38 @@ export const selector = {
// Extra Options

// Has Persons
hasPersons: '#\\_wc_booking_has_persons',
minPersons: '#\\_wc_booking_min_persons_group',
maxPersons: '#\\_wc_booking_max_persons_group',
multiplyAllCostsByPersonCount: '#\\_wc_booking_person_cost_multiplier',
countPersonsAsBookings: '#\\_wc_booking_person_qty_multiplier',
enablePersonTypes: '#\\_wc_booking_has_person_types',
hasPersons: 'input#\\_wc_booking_has_persons',
minPersons: 'div#bookings_persons #\\_wc_booking_min_persons_group',
maxPersons: 'div#bookings_persons #\\_wc_booking_max_persons_group',
multiplyAllCostsByPersonCount: 'div#bookings_persons #\\_wc_booking_person_cost_multiplier',
countPersonsAsBookings: 'div#bookings_persons #\\_wc_booking_person_qty_multiplier',
enablePersonTypes: 'div#bookings_persons #\\_wc_booking_has_person_types',

// Add Person
addPersonType: '.add_person',
personTypeName: '//label[contains(text(),"Person Type Name:")]/..//input',
personBaseCost: '//label[contains(text(),"Base Cost:")]/..//input',
personBlockCost: '//label[contains(text(),"Block Cost:")]/..//input',
description: '.person_description',
min: '//label[contains(text(),"Min:")]/..//input',
max: '//label[contains(text(),"Max:")]/..//input',
unlink: '.unlink_booking_person', // invokes default js alert
addPersonType: 'button.add_person',
person: {
typeName: '//div[@id="bookings_persons"]//label[contains(text(),"Person Type Name:")]/..//input',
baseCost: '//div[@id="bookings_persons"]//label[contains(text(),"Base Cost:")]/..//input',
blockCost: '//div[@id="bookings_persons"]//label[contains(text(),"Block Cost:")]/..//input',
description: 'input.person_description',
min: '//div[@id="bookings_persons"]//label[contains(text(),"Min:")]/..//input',
max: '//div[@id="bookings_persons"]//label[contains(text(),"Max:")]/..//input',
},
unlink: 'button.unlink_booking_person', // invokes default js alert
remove: 'button.remove_booking_person',
confirmRemove: 'button.swal2-confirm',

// Has Resources
hasResources: '#\\_wc_booking_has_resources',
hasResources: 'input#\\_wc_booking_has_resources',

// Add Resource
label: '#\\_wc_booking_resource_label',
resourcesAre: '#\\_wc_booking_resources_assignment',
addResourceId: '.add_resource_id',
addResource: '.add_resource',
resourceBaseCost: '//label[contains(text(),"Base Cost:")]/..//input',
resourceBlockCost: '//label[contains(text(),"Block Cost:")]/..//input',
removeResource: '.remove_booking_resource.button', // invokes default js alert
label: 'div#bookings_resources input#\\_wc_booking_resource_label',
resourcesAllocation: 'div#bookings_resources select#\\_wc_booking_resources_assignment',
addResourceId: 'div#bookings_resources select.add_resource_id',
addResource: 'button.add_resource',
resourceBaseCost: '//div[@id="bookings_resources"]//label[contains(text(),"Base Cost:")]/..//input',
resourceBlockCost: '//div[@id="bookings_resources"]//label[contains(text(),"Block Cost:")]/..//input',
removeResource: 'button.remove_booking_resource', // invokes default js alert

// Short Description
shortDescriptionIframe: '.dokan-product-short-description iframe',
Expand Down
1 change: 1 addition & 0 deletions tests/pw/pages/vendorAuctionsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ export class AuctionsPage extends VendorPage {
await this.toBeVisible(productsVendor.attribute.savedAttribute(attribute.attributeName));
}

// can't add already added attribute
async cantAddAlreadyAddedAttribute(productName: string, attributeName: string): Promise<void> {
await this.goToAuctionProductEditById(productName);
await this.toBeVisible(productsVendor.attribute.savedAttribute(attributeName));
Expand Down
Loading
Loading