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

Added support for multiples pages #8

Merged
merged 1 commit into from
Jan 22, 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/node_modules/*
dist
/dist

## IDE
/.vscode/
25 changes: 23 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"homepage": "https://github.com/PrestaShop/ui-testing-library#readme",
"dependencies": {
"@faker-js/faker": "^8.3.1",
"@playwright/test": "^1.40.1",
"semver": "^7.5.4"
},
Expand Down
18 changes: 18 additions & 0 deletions src/data/demo/customers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import SocialTitles from '@data/demo/socialTitles';
import CustomerData from '@data/faker/customer';

export default {
johnDoe: new CustomerData({
id: 2,
socialTitle: SocialTitles.Mr.name,
firstName: 'John',
lastName: 'DOE',
birthDate: new Date('1970-01-15'),
email: '[email protected]',
password: '123456789',
enabled: true,
newsletter: true,
partnerOffers: true,
defaultCustomerGroup: 'Customer',
}),
};
22 changes: 22 additions & 0 deletions src/data/demo/groups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import GroupData from '@data/faker/group';

export default {
visitor: new GroupData({
id: 1,
name: 'Visitor',
discount: 0,
shownPrices: true,
}),
guest: new GroupData({
id: 2,
name: 'Guest',
discount: 0,
shownPrices: true,
}),
customer: new GroupData({
id: 3,
name: 'Customer',
discount: 0,
shownPrices: true,
}),
};
59 changes: 59 additions & 0 deletions src/data/demo/modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import ModuleData from '@data/faker/module';

export default {
blockwishlist: new ModuleData({
tag: 'blockwishlist',
name: 'Wishlist',
}),
psApiResources: new ModuleData({
tag: 'ps_apiresources',
name: 'PrestaShop API Resources',
}),
psCashOnDelivery: new ModuleData({
tag: 'ps_cashondelivery',
name: 'Cash on delivery (COD)',
}),
psCheckPayment: new ModuleData({
tag: 'ps_checkpayment',
name: 'Payments by check',
}),
psEmailAlerts: new ModuleData({
tag: 'ps_emailalerts',
name: 'Mail alerts',
releaseZip: 'https://github.com/PrestaShop/ps_emailalerts/releases/download/v2.4.2/ps_emailalerts.zip',
}),
psEmailSubscription: new ModuleData({
tag: 'ps_emailsubscription',
name: 'Newsletter subscription',
}),
psFacetedSearch: new ModuleData({
tag: 'ps_facetedsearch',
name: 'Faceted search',
releaseZip: 'https://github.com/PrestaShop/ps_facetedsearch/releases/download/v3.14.1/ps_facetedsearch.zip',
}),
psThemeCusto: new ModuleData({
tag: 'ps_themecusto',
name: 'Theme Customization',
}),
contactForm: new ModuleData({
tag: 'contactform',
name: 'Contact form',
}),
themeCustomization: new ModuleData({
tag: 'ps_themecusto',
name: 'Theme Customization',
}),
availableQuantities: new ModuleData({
tag: 'statsstock',
name: 'Available quantities',
}),
mainMenu: new ModuleData({
tag: 'ps_mainmenu',
name: 'Main menu',
}),
keycloak: new ModuleData({
tag: 'keycloak_connector_demo',
name: 'Keycloak OAuth2 connector demo',
releaseZip: 'https://github.com/PrestaShop/keycloak_connector_demo/releases/download/v1.0.4/keycloak_connector_demo.zip',
}),
};
10 changes: 10 additions & 0 deletions src/data/demo/socialTitles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
Mr: {
id: 1,
name: 'Mr.',
},
Mrs: {
id: 2,
name: 'Mrs',
},
};
14 changes: 14 additions & 0 deletions src/data/demo/titles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import TitleData from '@data/faker/title';

export default {
Mrs: new TitleData({
id: 2,
name: 'Mrs.',
gender: 'Female',
}),
Mr: new TitleData({
id: 1,
name: 'Mr.',
gender: 'Male',
}),
};
117 changes: 117 additions & 0 deletions src/data/faker/customer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import Groups from '@data/demo/groups';
import Titles from '@data/demo/titles';
import type GroupData from '@data/faker/group';
import type TitleData from '@data/faker/title';
import type {CustomerCreator} from '@data/types/customer';

import {faker} from '@faker-js/faker';

const genders: string[] = Object.values(Titles).map((title: TitleData) => title.name);
const groups: string[] = Object.values(Groups).map((group: GroupData) => group.name);
const risksRating: string[] = ['None', 'Low', 'Medium', 'High'];

/**
* Create new customer to use on creation form on customer page on BO and FO
* @class
*/
export default class CustomerData {
public readonly id: number;

public readonly socialTitle: string;

public readonly firstName: string;

public readonly lastName: string;

public email: string;

public password: string;

public readonly birthDate: Date;

public readonly yearOfBirth: string;

public readonly monthOfBirth: string;

public readonly dayOfBirth: string;

public readonly enabled: boolean;

public readonly partnerOffers: boolean;

public readonly newsletter: boolean;

public readonly defaultCustomerGroup: string;

public readonly company: string;

public readonly allowedOutstandingAmount: number;

public readonly riskRating: string;

/**
* Constructor for class CustomerData
* @param customerToCreate {CustomerCreator} Could be used to force the value of some members
*/
constructor(customerToCreate: CustomerCreator = {}) {
/** @type {number} ID of the customer */
this.id = customerToCreate.id || 0;

/** @type {string} Social title of the customer (Mr, Mrs) */
this.socialTitle = customerToCreate.socialTitle || faker.helpers.arrayElement(genders);

/** @type {string} Firstname of the customer */
this.firstName = customerToCreate.firstName || faker.person.firstName();

/** @type {string} Lastname of the customer */
this.lastName = customerToCreate.lastName || faker.person.lastName();

/** @type {string} Email for the customer account */
this.email = customerToCreate.email || faker.internet.email(
{
firstName: this.firstName,
lastName: this.lastName,
provider: 'prestashop.com',
},
);

/** @type {string} Password for the customer account */
this.password = customerToCreate.password === undefined ? faker.internet.password() : customerToCreate.password;

/** @type {Date} Birthdate of the customer */
this.birthDate = customerToCreate.birthDate || faker.date.between({from: '1950-01-01', to: '2000-12-31'});

/** @type {string} Year of the birth 'yyyy' */
this.yearOfBirth = customerToCreate.yearOfBirth || this.birthDate.getFullYear().toString();

/** @type {string} Month of the birth 'mm' */
this.monthOfBirth = customerToCreate.monthOfBirth || (`0${this.birthDate.getMonth() + 1}`).slice(-2);

/** @type {string} Day of the birth 'dd' */
this.dayOfBirth = customerToCreate.dayOfBirth || (`0${this.birthDate.getDate()}`).slice(-2).toString();

/** @type {boolean} Status of the customer */
this.enabled = customerToCreate.enabled === undefined ? true : customerToCreate.enabled;

/** @type {boolean} True to enable partner offers */
this.partnerOffers = customerToCreate.partnerOffers === undefined ? true : customerToCreate.partnerOffers;

/** @type {string} Default group for the customer */
this.defaultCustomerGroup = customerToCreate.defaultCustomerGroup || faker.helpers.arrayElement(groups);

/** @type {boolean} True to enable sending newsletter to the customer */
this.newsletter = customerToCreate.newsletter === undefined ? false : customerToCreate.newsletter;

/** @type {string} Company for the customer */
this.company = customerToCreate.company || faker.company.name();

/** @type {Number} Allowed outstanding amount for the customer */
this.allowedOutstandingAmount = customerToCreate.allowedOutstandingAmount || faker.number.int({
min: 0,
max: 100,
});

/** @type {string} Risk rating for the customer */
this.riskRating = customerToCreate.riskRating || faker.helpers.arrayElement(risksRating);
}
}
47 changes: 47 additions & 0 deletions src/data/faker/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {GroupCreator} from '@data/types/group';

import {faker} from '@faker-js/faker';

const priceDisplayMethod: string[] = ['Tax included', 'Tax excluded'];

/**
* Create new group to use on creation form on group page on BO
* @class
*/
export default class GroupData {
public readonly id: number;

public readonly name: string;

public readonly frName: string;

public readonly discount: number;

public readonly priceDisplayMethod: string;

public readonly shownPrices: boolean;

/**
* Constructor for class GroupData
* @param groupToCreate {GroupCreator} Could be used to force the value of some members
*/
constructor(groupToCreate: GroupCreator = {}) {
/** @type {number} ID of the group */
this.id = groupToCreate.id || 0;

/** @type {string} Name of the group */
this.name = groupToCreate.name || faker.person.jobType();

/** @type {string} French name of the group */
this.frName = groupToCreate.frName || this.name;

/** @type {number} Basic discount for the group */
this.discount = groupToCreate.discount || 0;

/** @type {string} Price display method of the group */
this.priceDisplayMethod = groupToCreate.priceDisplayMethod || faker.helpers.arrayElement(priceDisplayMethod);

/** @type {boolean} True to show prices for the group */
this.shownPrices = groupToCreate.shownPrices === undefined ? true : groupToCreate.shownPrices;
}
}
27 changes: 27 additions & 0 deletions src/data/faker/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type {ModuleDataCreator} from '@data/types/module';

/**
* @class
*/
export default class ModuleData {
public readonly tag: string;

public readonly name: string;

public readonly releaseZip: string;

/**
* Constructor for class ModuleData
* @param valueToCreate {ModuleDataCreator} Could be used to force the value of some members
*/
constructor(valueToCreate: ModuleDataCreator = {}) {
/** @type {string} Technical Name of the module */
this.tag = valueToCreate.tag || '';

/** @type {string} Name of the module */
this.name = valueToCreate.name || '';

/** @type {string} Release URL */
this.releaseZip = valueToCreate.releaseZip || '';
}
}
Loading