Saleor 3826 tests for customers (#1226)

* added test for customers

* add test for customer
This commit is contained in:
Karolina Rakoczy 2021-07-15 13:25:39 +03:00 committed by GitHub
parent e6d6621816
commit f847c76d67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 157 additions and 25 deletions

View file

@ -63,3 +63,33 @@ export function getCustomers(startsWith) {
}`;
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");
}

View file

@ -0,0 +1,6 @@
export const CUSTOMER_DETAILS = {
nameInput: '[name="customerFirstName"]',
lastNameInput: '[name="customerLastName"]',
emailInput: '[name="email"]',
noteInput: '[name="note"]'
};

View file

@ -0,0 +1,3 @@
export const CUSTOMERS_LIST = {
createCustomerButton: '[data-test-id="createCustomer"]'
};

View 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);
});
});
});

View file

@ -50,28 +50,8 @@ describe("Warehouse settings", () => {
})
.then(warehouse => {
const addressResp = warehouse.address;
expect(warehouse.name).to.be.eq(name);
expect(addressResp).to.have.property(
"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
);
chai.softExpect(warehouse.name).to.be.eq(name);
cy.expectCorrectBasicAddress(addressResp, usAddress);
});
});

View file

@ -2,13 +2,17 @@ import { ADDRESS_SELECTORS } from "../../elements/shared/addressForm";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { fillAutocompleteSelect } from "./selects";
export function fillUpAddressFormAndSubmit(address) {
fillUpAddressForm();
cy.get(BUTTON_SELECTORS.submit).click();
}
export function fillUpAddressForm(address) {
cy.get(ADDRESS_SELECTORS.firstName)
.type(address.firstName)
.get(ADDRESS_SELECTORS.lastName)
.type(address.lastName);
fillUpBasicAddress(address);
cy.get(BUTTON_SELECTORS.submit).click();
}
export function fillUpBasicAddress(address) {

View file

@ -91,3 +91,40 @@ Cypress.Commands.add("softAssertVisibility", selector => {
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);
}
);

View file

@ -16,7 +16,8 @@ export const urlList = {
permissionsGroups: "permission-groups/",
weightRete: "weight/",
attributes: "attributes/",
productTypes: "product-types/"
productTypes: "product-types/",
customers: "customers/"
};
export const productDetailsUrl = productId => `${urlList.products}${productId}`;

View file

@ -52,7 +52,12 @@ const CustomerListPage: React.FC<CustomerListPageProps> = ({
return (
<Container>
<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
defaultMessage="Create customer"
description="button"

View file

@ -80752,6 +80752,7 @@ exports[`Storyshots Views / Customers / Customer list default 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
data-test-id="createCustomer"
tabindex="0"
type="button"
>
@ -82347,6 +82348,7 @@ exports[`Storyshots Views / Customers / Customer list loading 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
data-test-id="createCustomer"
tabindex="0"
type="button"
>
@ -82759,6 +82761,7 @@ exports[`Storyshots Views / Customers / Customer list no data 1`] = `
>
<button
class="MuiButtonBase-root-id MuiButton-root-id MuiButton-contained-id MuiButton-containedPrimary-id"
data-test-id="createCustomer"
tabindex="0"
type="button"
>