Saleor 3826 tests for customers (#1226)
* added test for customers * add test for customer
This commit is contained in:
parent
e6d6621816
commit
f847c76d67
10 changed files with 157 additions and 25 deletions
|
@ -63,3 +63,33 @@ export function getCustomers(startsWith) {
|
||||||
}`;
|
}`;
|
||||||
return cy.sendRequestWithQuery(query);
|
return cy.sendRequestWithQuery(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCustomer(customerId) {
|
||||||
|
const query = `query{
|
||||||
|
user(id:"${customerId}"){
|
||||||
|
id
|
||||||
|
email
|
||||||
|
firstName
|
||||||
|
lastName
|
||||||
|
isStaff
|
||||||
|
isActive
|
||||||
|
note
|
||||||
|
addresses{
|
||||||
|
firstName
|
||||||
|
lastName
|
||||||
|
companyName
|
||||||
|
streetAddress1
|
||||||
|
streetAddress2
|
||||||
|
city
|
||||||
|
cityArea
|
||||||
|
postalCode
|
||||||
|
country{
|
||||||
|
code
|
||||||
|
}
|
||||||
|
countryArea
|
||||||
|
phone
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
return cy.sendRequestWithQuery(query).its("body.data.user");
|
||||||
|
}
|
||||||
|
|
6
cypress/elements/customer/customer-details.js
Normal file
6
cypress/elements/customer/customer-details.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export const CUSTOMER_DETAILS = {
|
||||||
|
nameInput: '[name="customerFirstName"]',
|
||||||
|
lastNameInput: '[name="customerLastName"]',
|
||||||
|
emailInput: '[name="email"]',
|
||||||
|
noteInput: '[name="note"]'
|
||||||
|
};
|
3
cypress/elements/customer/customers-list.js
Normal file
3
cypress/elements/customer/customers-list.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const CUSTOMERS_LIST = {
|
||||||
|
createCustomerButton: '[data-test-id="createCustomer"]'
|
||||||
|
};
|
63
cypress/integration/allEnv/configuration/customer.js
Normal file
63
cypress/integration/allEnv/configuration/customer.js
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
import faker from "faker";
|
||||||
|
|
||||||
|
import { getCustomer } from "../../../apiRequests/Customer";
|
||||||
|
import { ONE_PERMISSION_USERS } from "../../../Data/users";
|
||||||
|
import { CUSTOMER_DETAILS } from "../../../elements/customer/customer-details";
|
||||||
|
import { CUSTOMERS_LIST } from "../../../elements/customer/customers-list";
|
||||||
|
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
|
||||||
|
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
|
||||||
|
import { fillUpAddressForm } from "../../../steps/shared/addressForm";
|
||||||
|
import { confirmationMessageShouldDisappear } from "../../../steps/shared/confirmationMessage";
|
||||||
|
import { urlList } from "../../../url/urlList";
|
||||||
|
|
||||||
|
describe("Tests for customer", () => {
|
||||||
|
const channelStartsWith = `Customers`;
|
||||||
|
|
||||||
|
it("should create customer", () => {
|
||||||
|
const randomName = `${channelStartsWith}${faker.datatype.number()}`;
|
||||||
|
const email = `${randomName}@example.com`;
|
||||||
|
const note = faker.lorem.paragraph();
|
||||||
|
let address;
|
||||||
|
|
||||||
|
cy.clearSessionData()
|
||||||
|
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.user)
|
||||||
|
.visit(urlList.customers)
|
||||||
|
.get(CUSTOMERS_LIST.createCustomerButton)
|
||||||
|
.click()
|
||||||
|
.get(SHARED_ELEMENTS.progressBar)
|
||||||
|
.should("not.be.visible")
|
||||||
|
.get(CUSTOMER_DETAILS.nameInput)
|
||||||
|
.type(randomName)
|
||||||
|
.get(CUSTOMER_DETAILS.lastNameInput)
|
||||||
|
.type(randomName)
|
||||||
|
.get(CUSTOMER_DETAILS.emailInput)
|
||||||
|
.type(email)
|
||||||
|
.fixture("addresses")
|
||||||
|
.then(({ usAddress }) => {
|
||||||
|
address = usAddress;
|
||||||
|
fillUpAddressForm(address);
|
||||||
|
})
|
||||||
|
.get(CUSTOMER_DETAILS.noteInput)
|
||||||
|
.type(note)
|
||||||
|
.addAliasToGraphRequest("CreateCustomer")
|
||||||
|
.get(BUTTON_SELECTORS.confirm)
|
||||||
|
.click();
|
||||||
|
confirmationMessageShouldDisappear();
|
||||||
|
cy.wait("@CreateCustomer")
|
||||||
|
.its("response.body.data.customerCreate.user")
|
||||||
|
.then(customer => {
|
||||||
|
getCustomer(customer.id);
|
||||||
|
})
|
||||||
|
.then(customer => {
|
||||||
|
chai
|
||||||
|
.softExpect(customer.firstName, "Expect correct first name")
|
||||||
|
.to.eq(randomName);
|
||||||
|
chai
|
||||||
|
.softExpect(customer.lastName, "Expect correct last name")
|
||||||
|
.to.eq(randomName);
|
||||||
|
chai.softExpect(customer.email, "Expect correct email").to.eq(email);
|
||||||
|
chai.softExpect(customer.note, "Expect correct note").to.eq(note);
|
||||||
|
cy.expectCorrectFullAddress(customer.addresses[0], address);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -50,28 +50,8 @@ describe("Warehouse settings", () => {
|
||||||
})
|
})
|
||||||
.then(warehouse => {
|
.then(warehouse => {
|
||||||
const addressResp = warehouse.address;
|
const addressResp = warehouse.address;
|
||||||
expect(warehouse.name).to.be.eq(name);
|
chai.softExpect(warehouse.name).to.be.eq(name);
|
||||||
expect(addressResp).to.have.property(
|
cy.expectCorrectBasicAddress(addressResp, usAddress);
|
||||||
"city",
|
|
||||||
usAddress.city.toUpperCase()
|
|
||||||
);
|
|
||||||
expect(addressResp).to.have.property(
|
|
||||||
"countryArea",
|
|
||||||
usAddress.countryArea
|
|
||||||
);
|
|
||||||
expect(addressResp).to.have.property("phone", usAddress.phone);
|
|
||||||
expect(addressResp).to.have.property(
|
|
||||||
"postalCode",
|
|
||||||
usAddress.postalCode
|
|
||||||
);
|
|
||||||
expect(addressResp).to.have.property(
|
|
||||||
"streetAddress1",
|
|
||||||
usAddress.streetAddress1
|
|
||||||
);
|
|
||||||
expect(addressResp).to.have.property(
|
|
||||||
"streetAddress2",
|
|
||||||
usAddress.streetAddress2
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,17 @@ import { ADDRESS_SELECTORS } from "../../elements/shared/addressForm";
|
||||||
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
|
||||||
import { fillAutocompleteSelect } from "./selects";
|
import { fillAutocompleteSelect } from "./selects";
|
||||||
|
|
||||||
|
export function fillUpAddressFormAndSubmit(address) {
|
||||||
|
fillUpAddressForm();
|
||||||
|
cy.get(BUTTON_SELECTORS.submit).click();
|
||||||
|
}
|
||||||
|
|
||||||
export function fillUpAddressForm(address) {
|
export function fillUpAddressForm(address) {
|
||||||
cy.get(ADDRESS_SELECTORS.firstName)
|
cy.get(ADDRESS_SELECTORS.firstName)
|
||||||
.type(address.firstName)
|
.type(address.firstName)
|
||||||
.get(ADDRESS_SELECTORS.lastName)
|
.get(ADDRESS_SELECTORS.lastName)
|
||||||
.type(address.lastName);
|
.type(address.lastName);
|
||||||
fillUpBasicAddress(address);
|
fillUpBasicAddress(address);
|
||||||
cy.get(BUTTON_SELECTORS.submit).click();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fillUpBasicAddress(address) {
|
export function fillUpBasicAddress(address) {
|
||||||
|
|
|
@ -91,3 +91,40 @@ Cypress.Commands.add("softAssertVisibility", selector => {
|
||||||
chai.softExpect(element, "element should be visible").to.be.visible
|
chai.softExpect(element, "element should be visible").to.be.visible
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Cypress.Commands.add(
|
||||||
|
"expectCorrectBasicAddress",
|
||||||
|
(responseAddress, expectedAddress) => {
|
||||||
|
chai
|
||||||
|
.softExpect(responseAddress)
|
||||||
|
.to.have.property("city", expectedAddress.city.toUpperCase());
|
||||||
|
chai
|
||||||
|
.softExpect(responseAddress)
|
||||||
|
.to.have.property("countryArea", expectedAddress.countryArea);
|
||||||
|
chai
|
||||||
|
.softExpect(responseAddress)
|
||||||
|
.to.have.property("phone", expectedAddress.phone);
|
||||||
|
chai
|
||||||
|
.softExpect(responseAddress)
|
||||||
|
.to.have.property("postalCode", expectedAddress.postalCode);
|
||||||
|
chai
|
||||||
|
.softExpect(responseAddress)
|
||||||
|
.to.have.property("streetAddress1", expectedAddress.streetAddress1);
|
||||||
|
chai
|
||||||
|
.softExpect(responseAddress)
|
||||||
|
.to.have.property("streetAddress2", expectedAddress.streetAddress2);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Cypress.Commands.add(
|
||||||
|
"expectCorrectFullAddress",
|
||||||
|
(responseAddress, expectedAddress) => {
|
||||||
|
chai
|
||||||
|
.softExpect(responseAddress)
|
||||||
|
.to.have.property("firstName", expectedAddress.firstName);
|
||||||
|
chai
|
||||||
|
.softExpect(responseAddress)
|
||||||
|
.to.have.property("firstName", expectedAddress.lastName);
|
||||||
|
cy.expectCorrectBasicAddress(responseAddress, expectedAddress);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -16,7 +16,8 @@ export const urlList = {
|
||||||
permissionsGroups: "permission-groups/",
|
permissionsGroups: "permission-groups/",
|
||||||
weightRete: "weight/",
|
weightRete: "weight/",
|
||||||
attributes: "attributes/",
|
attributes: "attributes/",
|
||||||
productTypes: "product-types/"
|
productTypes: "product-types/",
|
||||||
|
customers: "customers/"
|
||||||
};
|
};
|
||||||
|
|
||||||
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
|
export const productDetailsUrl = productId => `${urlList.products}${productId}`;
|
||||||
|
|
|
@ -52,7 +52,12 @@ const CustomerListPage: React.FC<CustomerListPageProps> = ({
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<PageHeader title={intl.formatMessage(sectionNames.customers)}>
|
<PageHeader title={intl.formatMessage(sectionNames.customers)}>
|
||||||
<Button color="primary" variant="contained" onClick={onAdd}>
|
<Button
|
||||||
|
color="primary"
|
||||||
|
variant="contained"
|
||||||
|
onClick={onAdd}
|
||||||
|
data-test-id="createCustomer"
|
||||||
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Create customer"
|
defaultMessage="Create customer"
|
||||||
description="button"
|
description="button"
|
||||||
|
|
|
@ -80752,6 +80752,7 @@ exports[`Storyshots Views / Customers / Customer list default 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="createCustomer"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -82347,6 +82348,7 @@ exports[`Storyshots Views / Customers / Customer list loading 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="createCustomer"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
@ -82759,6 +82761,7 @@ exports[`Storyshots Views / Customers / Customer list no data 1`] = `
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
|
||||||
|
data-test-id="createCustomer"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue