Add no UI login
This commit is contained in:
parent
6a72fae494
commit
2a63f9d85c
6 changed files with 59 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,
|
||||||
|
|
|
@ -1,16 +1,4 @@
|
||||||
/* eslint-disable sort-keys */
|
/* eslint-disable sort-keys */
|
||||||
export const LEFT_MENU_SELECTORS = {
|
export const LEFT_MENU_SELECTORS = {
|
||||||
catalog: "[data-testid='catalog']",
|
catalog: "[data-testid='catalogue']"
|
||||||
|
|
||||||
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']"
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
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']"
|
||||||
|
};
|
|
@ -1,37 +1,43 @@
|
||||||
import { LEFT_MENU_SELECTORS } from "../elements/account/left-menu/left-menu-selectors";
|
import { LEFT_MENU_SELECTORS } from "../elements/account/left-menu/left-menu-selectors";
|
||||||
import { LOGIN_SELECTORS } from "../elements/account/login-selectors";
|
import { PRODUCTS_SELECTORS } from "../elements/catalog/product-selectors";
|
||||||
|
|
||||||
// <reference types="cypress" />
|
// <reference types="cypress" />
|
||||||
describe("Products", () => {
|
describe("Products", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.clearSessionData();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
cy.visit("/");
|
|
||||||
cy.loginUser();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add new visible product", () => {
|
it("should add new visible product", () => {
|
||||||
cy.get(LEFT_MENU_SELECTORS.catalog)
|
cy.visit("/")
|
||||||
|
.get(LEFT_MENU_SELECTORS.catalog)
|
||||||
.click()
|
.click()
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.products)
|
.get(PRODUCTS_SELECTORS.products)
|
||||||
.click()
|
.click()
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.createProductBtn)
|
.get(PRODUCTS_SELECTORS.createProductBtn)
|
||||||
.click()
|
.click()
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.productNameInput)
|
.get(PRODUCTS_SELECTORS.productNameInput)
|
||||||
.click()
|
.click()
|
||||||
.type("Visible test product")
|
.type("Visible test product")
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.productTypeInput)
|
.get(PRODUCTS_SELECTORS.productTypeInput)
|
||||||
.click()
|
.click()
|
||||||
.type("Cushion{'enter'}")
|
.type("Cushion")
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.categoryInput)
|
.get(PRODUCTS_SELECTORS.categoryItem)
|
||||||
|
.should("have.length", 1)
|
||||||
|
.get(PRODUCTS_SELECTORS.firstCategoryItem)
|
||||||
.click()
|
.click()
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.categoryDropdown)
|
.get(PRODUCTS_SELECTORS.categoryInput)
|
||||||
|
.click()
|
||||||
|
.get(PRODUCTS_SELECTORS.categoryItem)
|
||||||
.first()
|
.first()
|
||||||
.click()
|
.click()
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.visibleRadioBtn)
|
.get(PRODUCTS_SELECTORS.visibleRadioBtn)
|
||||||
|
.first()
|
||||||
.click()
|
.click()
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.saveBtn)
|
.get(PRODUCTS_SELECTORS.saveBtn)
|
||||||
.click()
|
.click()
|
||||||
.get(LEFT_MENU_SELECTORS.PRODUCTS_SELECTORS.confirmationMsg)
|
.get(PRODUCTS_SELECTORS.confirmationMsg, {
|
||||||
.contains("Product save");
|
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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,3 +9,23 @@ Cypress.Commands.add("loginUser", () =>
|
||||||
.get(LOGIN_SELECTORS.signInButton)
|
.get(LOGIN_SELECTORS.signInButton)
|
||||||
.click()
|
.click()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Cypress.Commands.add("loginUserViaRequest", () =>
|
||||||
|
cy
|
||||||
|
.request({
|
||||||
|
method: "POST",
|
||||||
|
url: Cypress.env("API_URI"),
|
||||||
|
body: {
|
||||||
|
operationName: "TokenAuth",
|
||||||
|
variables: {
|
||||||
|
email: Cypress.env("USER_NAME"),
|
||||||
|
password: Cypress.env("USER_PASSWORD")
|
||||||
|
},
|
||||||
|
query:
|
||||||
|
"mutation TokenAuth($email: String!, $password: String!) {\n tokenCreate(email: $email, password: $password) {\n token\n errors: accountErrors {\n code\n field\n message\n __typename\n }\n user {\n id\n __typename\n }\n __typename\n }\n}\n"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(resp => {
|
||||||
|
window.sessionStorage.setItem("auth", resp.body.data.tokenCreate.token);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in a new issue