Merge pull request #673 from mirumee/create-visible-product
Create visible product
This commit is contained in:
commit
e00d9a7159
8 changed files with 127 additions and 34 deletions
|
@ -1,8 +1,5 @@
|
||||||
{
|
{
|
||||||
"baseUrl": "http://localhost:9000",
|
"baseUrl": "http://localhost:9000",
|
||||||
"env": {
|
|
||||||
"API_URI": "https://pwa.demo.saleor.rocks/graphql/"
|
|
||||||
},
|
|
||||||
"defaultCommandTimeout": 15000,
|
"defaultCommandTimeout": 15000,
|
||||||
"requestTimeout": 15000,
|
"requestTimeout": 15000,
|
||||||
"viewportWidth": 1400,
|
"viewportWidth": 1400,
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
/* eslint-disable sort-keys */
|
||||||
|
export const LEFT_MENU_SELECTORS = {
|
||||||
|
catalog: "[data-testid='catalogue']"
|
||||||
|
};
|
|
@ -1,7 +1,9 @@
|
||||||
export const LOGIN_SELECTORS = {
|
export const LOGIN_SELECTORS = {
|
||||||
|
accountSettings: "[data-test=accountSettingsButton]",
|
||||||
emailAddressInput: "input[name='email']",
|
emailAddressInput: "input[name='email']",
|
||||||
emailPasswordInput: "input[name='password']",
|
emailPasswordInput: "input[name='password']",
|
||||||
signInButton: "[data-test=submit]",
|
signInButton: "[data-test=submit]",
|
||||||
|
userMenu: "[data-test=userMenu]",
|
||||||
warningCredentialMessage: "[data-test=loginErrorMessage]",
|
warningCredentialMessage: "[data-test=loginErrorMessage]",
|
||||||
welcomePage: "[data-test=welcomeHeader]"
|
welcomePage: "[data-test=welcomeHeader]"
|
||||||
};
|
};
|
||||||
|
|
13
cypress/elements/catalog/product-selectors.js
Normal file
13
cypress/elements/catalog/product-selectors.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/* eslint-disable sort-keys */
|
||||||
|
export const PRODUCTS_SELECTORS = {
|
||||||
|
products: "[href='/dashboard/products?']",
|
||||||
|
createProductBtn: "[data-test='add-product']",
|
||||||
|
productNameInput: "[name='name']",
|
||||||
|
productTypeInput: "[data-test='product-type']",
|
||||||
|
categoryInput: "[data-test='category']",
|
||||||
|
categoryItem: "[data-test='singleautocomplete-select-option']",
|
||||||
|
firstCategoryItem: "#downshift-0-item-0",
|
||||||
|
visibleRadioBtn: "[name='isPublished']",
|
||||||
|
saveBtn: "[data-test='button-bar-confirm']",
|
||||||
|
confirmationMsg: "[data-test='notification']"
|
||||||
|
};
|
|
@ -6,7 +6,6 @@ describe("User authorization", () => {
|
||||||
cy.clearSessionData();
|
cy.clearSessionData();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Login", () => {
|
|
||||||
it("should successfully log in an user", () => {
|
it("should successfully log in an user", () => {
|
||||||
cy.visit("/");
|
cy.visit("/");
|
||||||
cy.loginUser();
|
cy.loginUser();
|
||||||
|
@ -23,20 +22,17 @@ describe("User authorization", () => {
|
||||||
.click()
|
.click()
|
||||||
.get(LOGIN_SELECTORS.warningCredentialMessage);
|
.get(LOGIN_SELECTORS.warningCredentialMessage);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe("Logout", () => {
|
|
||||||
it("should successfully log out an user", () => {
|
it("should successfully log out an user", () => {
|
||||||
cy.window().then(win => {
|
cy.window().then(win => {
|
||||||
win.sessionStorage.clear();
|
win.sessionStorage.clear();
|
||||||
});
|
});
|
||||||
cy.visit("/");
|
cy.visit("/");
|
||||||
cy.loginUser();
|
cy.loginUser();
|
||||||
cy.get("[data-test=userMenu]")
|
cy.get(LOGIN_SELECTORS.userMenu)
|
||||||
.click()
|
.click()
|
||||||
.get("[data-test=accountSettingsButton]")
|
.get(LOGIN_SELECTORS.accountSettings)
|
||||||
.click();
|
.click();
|
||||||
cy.location("pathname").should("contains", "/staff/");
|
cy.location("pathname").should("contains", "/staff/");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
43
cypress/integration/products.js
Normal file
43
cypress/integration/products.js
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import { LEFT_MENU_SELECTORS } from "../elements/account/left-menu/left-menu-selectors";
|
||||||
|
import { PRODUCTS_SELECTORS } from "../elements/catalog/product-selectors";
|
||||||
|
|
||||||
|
// <reference types="cypress" />
|
||||||
|
describe("Products", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should add new visible product", () => {
|
||||||
|
cy.visit("/")
|
||||||
|
.get(LEFT_MENU_SELECTORS.catalog)
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.products)
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.createProductBtn)
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.productNameInput)
|
||||||
|
.click()
|
||||||
|
.type("Visible test product")
|
||||||
|
.get(PRODUCTS_SELECTORS.productTypeInput)
|
||||||
|
.click()
|
||||||
|
.type("Cushion")
|
||||||
|
.get(PRODUCTS_SELECTORS.categoryItem)
|
||||||
|
.should("have.length", 1)
|
||||||
|
.get(PRODUCTS_SELECTORS.firstCategoryItem)
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.categoryInput)
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.categoryItem)
|
||||||
|
.first()
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.visibleRadioBtn)
|
||||||
|
.first()
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.saveBtn)
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.confirmationMsg, {
|
||||||
|
timeout: 1000
|
||||||
|
})
|
||||||
|
.contains("Product created");
|
||||||
|
});
|
||||||
|
});
|
|
@ -16,6 +16,7 @@
|
||||||
* @type {Cypress.PluginConfig}
|
* @type {Cypress.PluginConfig}
|
||||||
*/
|
*/
|
||||||
module.exports = (on, config) => {
|
module.exports = (on, config) => {
|
||||||
// `on` is used to hook into various events Cypress emits
|
config.env.API_URI = process.env.API_URI;
|
||||||
// `config` is the resolved Cypress config
|
|
||||||
|
return config;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable sort-keys */
|
||||||
import { LOGIN_SELECTORS } from "../../elements/account/login-selectors";
|
import { LOGIN_SELECTORS } from "../../elements/account/login-selectors";
|
||||||
|
|
||||||
Cypress.Commands.add("loginUser", () =>
|
Cypress.Commands.add("loginUser", () =>
|
||||||
|
@ -9,3 +10,39 @@ Cypress.Commands.add("loginUser", () =>
|
||||||
.get(LOGIN_SELECTORS.signInButton)
|
.get(LOGIN_SELECTORS.signInButton)
|
||||||
.click()
|
.click()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Cypress.Commands.add("loginUserViaRequest", () => {
|
||||||
|
const logInMutationQuery = `mutation TokenAuth($email: String!, $password: String!) {
|
||||||
|
tokenCreate(email: $email, password: $password) {
|
||||||
|
token
|
||||||
|
errors: accountErrors {
|
||||||
|
code
|
||||||
|
field
|
||||||
|
message
|
||||||
|
__typename
|
||||||
|
}
|
||||||
|
user {
|
||||||
|
id
|
||||||
|
__typename
|
||||||
|
}
|
||||||
|
__typename
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
|
return cy
|
||||||
|
.request({
|
||||||
|
method: "POST",
|
||||||
|
url: Cypress.env("API_URI"),
|
||||||
|
body: {
|
||||||
|
operationName: "TokenAuth",
|
||||||
|
variables: {
|
||||||
|
email: Cypress.env("USER_NAME"),
|
||||||
|
password: Cypress.env("USER_PASSWORD")
|
||||||
|
},
|
||||||
|
query: logInMutationQuery
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(resp => {
|
||||||
|
window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue