Skip to content

Commit

Permalink
Add geolocation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatahalder01 committed Nov 19, 2024
1 parent ce345d5 commit e29b0bb
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 13 deletions.
20 changes: 13 additions & 7 deletions tests/pw/feature-map/feature-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
- page: 'Shortcode'
features:
admin:
admin can create page with Dokan shortcode: false
admin can create page with Dokan shortcode: true
vendor:
vendor can view Dokan dashboard (shortcode): true
vendor can view Dokan subscription packs (shortcode): true
Expand Down Expand Up @@ -815,10 +815,16 @@
features:
admin:
# admin can set Dokan geolocation settings [duplicate]: false
admin can set map location position: false
admin can set where to display store map: false
admin can enable filters before location map: false
admin can enable product location tab on single product page: false
admin can set map location position (top): true
admin can set map location position (left): true
admin can set map location position (right): true
admin can set map display page (all): true
admin can set map display page (store_listing): true
admin can set map display page (shop): true
admin can enable filters before location map: true
admin can disable filters before location map: true
admin can enable product location tab on single product page: true
admin can disable product location tab on single product page: true
admin can set map radius search unit and distance: false
admin can set map zoom level: false
admin can set map default location: false
Expand All @@ -833,8 +839,8 @@
# customer can view map on shop page [duplicate]: false
# customer can view map on store list page [duplicate]: false
# customer can view map on single product page [duplicate]: false
# customer can view product location on map [duplicate]: false
# customer can view store location on map [duplicate]: false
# customer can view product location [duplicate]: false
# customer can view store location [duplicate]: false
# customer can use filters on shop page [duplicate]: false
# customer can use filters on store list page [duplicate]: false

Expand Down
100 changes: 100 additions & 0 deletions tests/pw/pages/geolocationPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { Page } from '@playwright/test';
import { AdminPage } from '@pages/adminPage';
import { selector } from '@pages/selectors';
import { data } from '@utils/testData';
import { helpers } from '@utils/helpers';

export class GeolocationPage extends AdminPage {
constructor(page: Page) {
super(page);
}

async goToProductDetails(productName: string): Promise<void> {
await this.gotoUntilNetworkidle(data.subUrls.frontend.productDetails(helpers.slugify(productName)));
}

// view map position
async viewMapPosition(position: 'top' | 'left' | 'right'): Promise<void> {
await this.gotoUntilNetworkidle(data.subUrls.frontend.storeListing);
switch (position) {
case 'top':
await this.toHaveAttribute(selector.customer.cStoreList.map.locationMap, 'class', 'dokan-geolocation-locations-map-top');
break;

case 'left':
await this.toHaveAttribute(selector.customer.cStoreList.map.locationMap, 'class', 'dokan-geolocation-locations-map-left');
break;

case 'right':
await this.toHaveAttribute(selector.customer.cStoreList.map.locationMap, 'class', 'dokan-geolocation-locations-map-right');
break;

default:
break;
}
}

// view map
async viewMap(position: 'all' | 'store_listing' | 'shop'): Promise<void> {
switch (position) {
case 'all':
await this.gotoUntilNetworkidle(data.subUrls.frontend.shop);
await this.toBeVisible(selector.customer.cStoreList.map.locationMap);
await this.gotoUntilNetworkidle(data.subUrls.frontend.storeListing);
await this.toBeVisible(selector.customer.cStoreList.map.locationMap);
break;

case 'store_listing':
await this.gotoUntilNetworkidle(data.subUrls.frontend.shop);
await this.notToBeVisible(selector.customer.cStoreList.map.locationMap);
await this.gotoUntilNetworkidle(data.subUrls.frontend.storeListing);
await this.toBeVisible(selector.customer.cStoreList.map.locationMap);
break;

case 'shop':
await this.gotoUntilNetworkidle(data.subUrls.frontend.shop);
await this.toBeVisible(selector.customer.cStoreList.map.locationMap);
await this.gotoUntilNetworkidle(data.subUrls.frontend.storeListing);
await this.notToBeVisible(selector.customer.cStoreList.map.locationMap);
break;

default:
break;
}
}

// view map filters
async viewMapFilters(status: 'enable' | 'disable'): Promise<void> {
await this.gotoUntilNetworkidle(data.subUrls.frontend.shop);
switch (status) {
case 'enable':
await this.toBeVisible(selector.customer.cShop.filters.filterDiv);
break;

case 'disable':
await this.notToBeVisible(selector.customer.cShop.filters.filterDiv);
break;

default:
break;
}
}

// view product location
async viewProductLocationTab(productName: string, status: 'enable' | 'disable'): Promise<void> {
switch (status) {
case 'enable':
await this.goToProductDetails(productName);
await this.toBeVisible(selector.customer.cSingleProduct.menus.location);
break;

case 'disable':
await this.goToProductDetails(productName);
await this.notToBeVisible(selector.customer.cSingleProduct.menus.location);
break;

default:
break;
}
}
}
3 changes: 2 additions & 1 deletion tests/pw/pages/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7012,6 +7012,7 @@ export const selector = {

// Filter
filters: {
filterDiv: 'form.dokan-geolocation-location-filters',
searchProduct: 'input.dokan-form-control[placeholder="Search Products"]',
location: '.location-address input',
selectCategory: '#product_cat',
Expand Down Expand Up @@ -7268,7 +7269,7 @@ export const selector = {
storeListText: '//h1[normalize-space()="Store List"]',

map: {
locationMap: '#dokan-geolocation-locations-map',
locationMap: 'div#dokan-geolocation-locations-map',
map: '//button[normalize-space()="Map"]',
satellite: '//button[normalize-space()="Satellite"]',
fullScreenToggle: '//button[@title="Toggle fullscreen view"]',
Expand Down
2 changes: 1 addition & 1 deletion tests/pw/pages/singleProductPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class SingleProductPage extends CustomerPage {
async productLocation(productName: string) {
await this.goToProductDetails(productName);
await this.click(singleProductCustomer.menus.location);
// await this.multipleElementVisible(singleProductCustomer.location); //todo: need to resolve: product location gets reset by other tests, skipeed for now
// await this.multipleElementVisible(singleProductCustomer.location); //todo: need to resolve: product location gets reset by other tests, skipped for now
await this.toBeVisible(singleProductCustomer.location.map);
}

Expand Down
49 changes: 49 additions & 0 deletions tests/pw/tests/e2e/geolocation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { test, Page } from '@playwright/test';
import { GeolocationPage } from '@pages/geolocationPage';
import { dbData } from '@utils/dbData';
import { dbUtils } from '@utils/dbUtils';
import { data } from '@utils/testData';

test.describe('Geolocation test', () => {
let admin: GeolocationPage;
let aPage: Page;

test.beforeAll(async ({ browser }) => {
const adminContext = await browser.newContext(data.auth.adminAuth);
aPage = await adminContext.newPage();
admin = new GeolocationPage(aPage);
});

test.afterAll(async () => {
await dbUtils.setOptionValue(dbData.dokan.optionName.geolocation, dbData.dokan.geolocationSettings);
await aPage.close();
});

['top', 'left', 'right'].forEach((position: string) => {
test(`admin can set map position (${position})`, { tag: ['@pro', '@admin'] }, async () => {
await dbUtils.updateOptionValue(dbData.dokan.optionName.geolocation, { show_locations_map: position });
await admin.viewMapPosition(position as 'top' | 'left' | 'right');
});
});

['all', 'store_listing', 'shop'].forEach((place: string) => {
test(`admin can set map display page (${place})`, { tag: ['@pro', '@admin'] }, async () => {
await dbUtils.updateOptionValue(dbData.dokan.optionName.geolocation, { show_location_map_pages: place });
await admin.viewMap(place as 'all' | 'store_listing' | 'shop');
});
});

['enable', 'disable'].forEach((status: string) => {
test(`admin can ${status} filters before location map`, { tag: ['@pro', '@admin'] }, async () => {
await dbUtils.updateOptionValue(dbData.dokan.optionName.geolocation, { show_filters_before_locations_map: status === 'enable' ? 'on' : 'off' });
await admin.viewMapFilters(status as 'enable' | 'disable');
});
});

['enable', 'disable'].forEach((status: string) => {
test(`admin can ${status} product location tab on single product page`, { tag: ['@pro', '@admin'] }, async () => {
await dbUtils.updateOptionValue(dbData.dokan.optionName.geolocation, { show_product_location_in_wc_tab: status === 'enable' ? 'on' : 'off' });
await admin.viewProductLocationTab(data.predefined.simpleProduct.product1.name, status as 'enable' | 'disable');
});
});
});
8 changes: 4 additions & 4 deletions tests/pw/utils/dbData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,10 @@ export const dbData = {
},

geolocationSettings: {
show_locations_map: 'top',
show_location_map_pages: 'all',
show_filters_before_locations_map: 'on',
show_product_location_in_wc_tab: 'on',
show_locations_map: 'top', // top, left, right
show_location_map_pages: 'all', // all, store_listing, shop
show_filters_before_locations_map: 'on', // on, off
show_product_location_in_wc_tab: 'on', // on, off
distance_unit: 'km',
distance_min: '0',
distance_max: '10',
Expand Down

0 comments on commit e29b0bb

Please sign in to comment.