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

fix: move and stabilize CreateLinkTypeCategory task #197

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/page-objects/administration/Categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Categories implements PageObject {
public readonly categoryMenuItemList: Locator;
public readonly createCategoryInput: Locator;
public readonly confirmCategoryCreationButton: Locator;
public readonly confirmCategoryCancelButton: Locator;
public readonly categoryItems: Locator;

/**
Expand All @@ -30,6 +31,7 @@ export class Categories implements PageObject {
public readonly filtersResultPopoverItemList: Locator;
public readonly saveButton: Locator;
public readonly loadingSpinner: Locator;
public readonly fadingBar: Locator;

/**
* Customisable link
Expand All @@ -54,7 +56,8 @@ export class Categories implements PageObject {
this.categoryMenuItemList = page.locator('.sw-context-button__menu-popover').locator('.sw-context-menu-item');
this.createCategoryInput = page.getByPlaceholder('Create category').getByRole('textbox');
this.confirmCategoryCreationButton = page.locator('.sw-confirm-field').locator('.sw-button--primary');
this.categoryItems = this.categoryTree.locator('.sw-tree-item__label');
this.categoryItems = this.categoryTree.locator('.tree-link');
this.confirmCategoryCancelButton = page.locator('.sw-confirm-field').locator('.sw-confirm-field__button--cancel');
this.nameInput = page.getByLabel('Name');
this.activeCheckbox = page.getByRole('checkbox', { name: 'Active' });
this.saveButton = page.getByRole('button', { name: 'Save' });
Expand All @@ -81,6 +84,7 @@ export class Categories implements PageObject {
this.filterResultPopoverTreeCheckboxItemList = this.popoverCategoryTree.locator('.sw-tree__content').locator('.sw-tree-item');
this.openInNewTabCheckbox = page.getByRole('checkbox', { name: 'Open in new tab' });
this.loadingSpinner = page.locator('.sw-loader');
this.fadingBar = page.locator('.fade-leave-active');
}

async getLandingPageByName(landingPageName: string) : Promise<Locator> {
Expand Down
4 changes: 3 additions & 1 deletion src/tasks/shop-admin-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { mergeTests } from '@playwright/test';

import { SaveProduct } from './shop-admin/Product/SaveProduct';
import { ExpectNotification } from './shop-admin/ExpectNotification';
import { CreateLinkTypeCategory } from './shop-admin/Category/CreateLinkTypeCategory';

export const test = mergeTests(
SaveProduct,
ExpectNotification
ExpectNotification,
CreateLinkTypeCategory,
);
56 changes: 56 additions & 0 deletions src/tasks/shop-admin/Category/CreateLinkTypeCategory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { test as base, Locator } from '@playwright/test';
import type { Task } from '../../../types/Task';
import type { FixtureTypes} from '../../../types/FixtureTypes';

export const CreateLinkTypeCategory = base.extend<{ CreateLinkTypeCategory: Task }, FixtureTypes>({
CreateLinkTypeCategory: async ({ AdminCategories, AdminCategoryDetail, TestDataService }, use) => {

const task = (categoryData, categoryCustomizableLinkData) => {
return async function CreateLinkTypeCategory() {
await AdminCategories.homeCategoryContextButton.click();
await AdminCategories.categoryMenuItemList.filter({ hasText: 'New category after' }).click();
await AdminCategories.createCategoryInput.fill(categoryData.name);
await AdminCategories.confirmCategoryCreationButton.click();
await AdminCategories.fadingBar.first().waitFor({ state: 'hidden' });
await AdminCategories.confirmCategoryCancelButton.click();
await AdminCategories.categoryItems.filter({ hasText: categoryData.name }).click();
await AdminCategories.nameInput.fill(categoryData.name);
await AdminCategories.activeCheckbox.setChecked(categoryData.status);
await AdminCategories.categoryTypeSelectionList.click();
await AdminCategories.filtersResultPopoverItemList.filter({ hasText: categoryData.categoryType }).click();
await AdminCategories.linkTypeSelectionList.click();
await AdminCategories.filtersResultPopoverItemList.filter({ hasText: categoryCustomizableLinkData.linkType }).click();
await AdminCategories.entitySelectionList.click();
await AdminCategories.filtersResultPopoverItemList.filter({ hasText: categoryCustomizableLinkData.entity }).click();

let locator: Locator;
switch (categoryCustomizableLinkData.entity) {
case 'Category':
await AdminCategories.categorySelectionList.click();
locator = await AdminCategories.getPopOverCategoryByName(categoryCustomizableLinkData.category);
await locator.getByRole('checkbox').click();
break;
case 'Product':
await AdminCategories.productSelectionList.click();
await AdminCategories.filtersResultPopoverItemList.filter({ hasText: categoryCustomizableLinkData.product }).click();
break;
case 'Landing page':
await AdminCategories.landingPageSelectionList.click();
await AdminCategories.filtersResultPopoverItemList.filter({ hasText: categoryCustomizableLinkData.landingPage }).click();
break;
default:
throw new Error('Entity type not found');
}

await AdminCategories.openInNewTabCheckbox.setChecked(categoryCustomizableLinkData.openInNewTab);
await AdminCategories.saveButton.click();
await AdminCategories.loadingSpinner.waitFor({ state: 'hidden' });
const url = AdminCategoryDetail.page.url();
const categoryId = url.split('/')[url.split('/').length - 2];
TestDataService.addCreatedRecord('category', categoryId);
};
};

await use(task);
},
});
Loading