saleor-dashboard/cypress/integration/configuration/translations.js
2021-09-02 12:36:46 +02:00

82 lines
3.1 KiB
JavaScript

import faker from "faker";
import { createCategory, getCategory } from "../../apiRequests/Category";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { SHARED_ELEMENTS } from "../../elements/shared/sharedElements";
import { ELEMENT_TRANSLATION } from "../../elements/translations/element-translation";
import { LANGUAGES_LIST } from "../../elements/translations/languages-list";
import { confirmationMessageShouldDisappear } from "../../steps/shared/confirmationMessages";
import { findElementOnTable } from "../../steps/shared/tables";
import filterTests from "../../support/filterTests";
import { urlList } from "../../url/urlList";
import { deleteCategoriesStartsWith } from "../../utils/categoryUtils";
filterTests(["all"], () => {
describe("Tests for translations", () => {
const startsWith = "Translations";
const randomNumber = faker.datatype.number();
const name = `${startsWith}${randomNumber}`;
let category;
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteCategoriesStartsWith(startsWith);
createCategory(name).then(categoryResp => (category = categoryResp));
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should create translation", () => {
cy.visit(urlList.translations)
.get(LANGUAGES_LIST.polishLanguageButton)
.click();
findElementOnTable(category.name);
cy.get(ELEMENT_TRANSLATION.editNameButton)
.click()
.get(SHARED_ELEMENTS.skeleton)
.should("not.exist")
.get(ELEMENT_TRANSLATION.translationInputField)
.type(`TranslatedName${randomNumber}`)
.get(BUTTON_SELECTORS.confirm)
.click();
confirmationMessageShouldDisappear();
cy.get(ELEMENT_TRANSLATION.editDescriptionButton)
.click()
.get(SHARED_ELEMENTS.richTextEditor.loader)
.should("not.exist")
.get(ELEMENT_TRANSLATION.translationInputField)
.type(`TranslatedDescription${randomNumber}`)
.wait(500)
.get(BUTTON_SELECTORS.confirm)
.click();
confirmationMessageShouldDisappear();
cy.get(ELEMENT_TRANSLATION.editSeoTitleButton)
.click()
.get(ELEMENT_TRANSLATION.translationInputField)
.type(`TranslatedSeoTitle${randomNumber}`)
.get(BUTTON_SELECTORS.confirm)
.click();
confirmationMessageShouldDisappear();
cy.get(ELEMENT_TRANSLATION.editSeoDescriptionButton)
.click()
.get(ELEMENT_TRANSLATION.translationInputField)
.type(`TranslatedSeoDescription${randomNumber}`)
.get(BUTTON_SELECTORS.confirm)
.click();
confirmationMessageShouldDisappear();
getCategory(category.id, "PL").then(({ translation }) => {
expect(translation.name).to.eq(`TranslatedName${randomNumber}`);
expect(translation.description).to.includes(
`TranslatedDescription${randomNumber}`
);
expect(translation.seoTitle).to.eq(`TranslatedSeoTitle${randomNumber}`);
expect(translation.seoDescription).to.eq(
`TranslatedSeoDescription${randomNumber}`
);
});
});
});
});