WIP-add new product

This commit is contained in:
Michalina Graczyk 2020-08-25 12:03:20 +02:00
parent c86206d35f
commit 6a72fae494
4 changed files with 80 additions and 29 deletions

View file

@ -0,0 +1,16 @@
/* eslint-disable sort-keys */
export const LEFT_MENU_SELECTORS = {
catalog: "[data-testid='catalog']",
PRODUCTS_SELECTORS: {
products: "[data-testid='catalogue']",
createProductBtn: "[data-test='add-product']",
productNameInput: "[name='name']",
productTypeInput: "data-test='product-type'",
categoryInput: "[data-test='category']",
categoryDropdown: "[data-test='singleautocomplete-select-option']",
visibleRadioBtn: "[name='isPublished']",
saveBtn: "[data-test='button-bar-confirm']",
confirmationMsg: "[data-test='notification']"
}
};

View file

@ -1,7 +1,9 @@
export const LOGIN_SELECTORS = {
accountSettings: "[data-test=accountSettingsButton]",
emailAddressInput: "input[name='email']",
emailPasswordInput: "input[name='password']",
signInButton: "[data-test=submit]",
userMenu: "[data-test=userMenu]",
warningCredentialMessage: "[data-test=loginErrorMessage]",
welcomePage: "[data-test=welcomeHeader]"
};

View file

@ -6,37 +6,33 @@ describe("User authorization", () => {
cy.clearSessionData();
});
describe("Login", () => {
it("should successfully log in an user", () => {
cy.visit("/");
cy.loginUser();
cy.get(LOGIN_SELECTORS.welcomePage);
});
it("should fail for wrong password", () => {
cy.visit("/")
.get(LOGIN_SELECTORS.emailAddressInput)
.type("admin@example.com")
.get(LOGIN_SELECTORS.emailPasswordInput)
.type("wrong-password")
.get(LOGIN_SELECTORS.signInButton)
.click()
.get(LOGIN_SELECTORS.warningCredentialMessage);
});
it("should successfully log in an user", () => {
cy.visit("/");
cy.loginUser();
cy.get(LOGIN_SELECTORS.welcomePage);
});
describe("Logout", () => {
it("should successfully log out an user", () => {
cy.window().then(win => {
win.sessionStorage.clear();
});
cy.visit("/");
cy.loginUser();
cy.get("[data-test=userMenu]")
.click()
.get("[data-test=accountSettingsButton]")
.click();
cy.location("pathname").should("contains", "/staff/");
it("should fail for wrong password", () => {
cy.visit("/")
.get(LOGIN_SELECTORS.emailAddressInput)
.type("admin@example.com")
.get(LOGIN_SELECTORS.emailPasswordInput)
.type("wrong-password")
.get(LOGIN_SELECTORS.signInButton)
.click()
.get(LOGIN_SELECTORS.warningCredentialMessage);
});
it("should successfully log out an user", () => {
cy.window().then(win => {
win.sessionStorage.clear();
});
cy.visit("/");
cy.loginUser();
cy.get(LOGIN_SELECTORS.userMenu)
.click()
.get(LOGIN_SELECTORS.accountSettings)
.click();
cy.location("pathname").should("contains", "/staff/");
});
});

View file

@ -0,0 +1,37 @@
import { LEFT_MENU_SELECTORS } from "../elements/account/left-menu/left-menu-selectors";
import { LOGIN_SELECTORS } from "../elements/account/login-selectors";
// <reference types="cypress" />
describe("Products", () => {
beforeEach(() => {
cy.clearSessionData();
cy.visit("/");
cy.loginUser();
});
it("should add new visible product", () => {
cy.get(LEFT_MENU_SELECTORS.catalog)
.click()
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.products)
.click()
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.createProductBtn)
.click()
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.productNameInput)
.click()
.type("Visible test product")
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.productTypeInput)
.click()
.type("Cushion{'enter'}")
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.categoryInput)
.click()
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.categoryDropdown)
.first()
.click()
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.visibleRadioBtn)
.click()
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.saveBtn)
.click()
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.confirmationMsg)
.contains("Product save");
});
});