Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cy create language #11546

Merged
merged 6 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
/// <reference types="Cypress" />

context('Languages', () => {

beforeEach(() => {
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'), false);
});

it('Creates language', () => {
// Setup
const language = 'Danish';
const culture = 'da';
cy.umbracoEnsureLanguageCultureNotExists(culture);
cy.umbracoSection('settings');

// Enter language tree and create new language
cy.umbracoTreeItem('settings', ['Languages']).click();
cy.umbracoButtonByLabelKey('languages_addLanguage').click();
cy.get('select[name="newLang"]').select(language);

// Save and assert success
cy.umbracoButtonByLabelKey('buttons_save').click();
cy.umbracoSuccessNotification().should('be.visible');

// Cleanup
cy.umbracoEnsureLanguageCultureNotExists(culture);
});

it('Deletes language', () => {
// Setup
const language1 = 'da';
const language2 = 'en-GB';
cy.umbracoEnsureLanguageNotExists(language1);
cy.umbracoEnsureLanguageNotExists(language2);
cy.umbracoEnsureLanguageCultureNotExists(language1);
cy.umbracoEnsureLanguageCultureNotExists(language2);

cy.umbracoCreateLanguage(language1, true, '1');
cy.umbracoCreateLanguage(language2, true, '1');
cy.umbracoSection('settings');
Expand All @@ -28,11 +50,11 @@ context('Languages', () => {
cy.umbracoButtonByLabelKey('contentTypeEditor_yesDelete').click();

// Assert there is only 2 language
cy.get('tbody > tr').should('have.length', 3);
cy.get('tbody > tr').should('have.length', 2);

// Cleanup
cy.umbracoEnsureLanguageNotExists(language1);
cy.umbracoEnsureLanguageNotExists(language2);
cy.umbracoEnsureLanguageCultureNotExists(language1);
cy.umbracoEnsureLanguageCultureNotExists(language2);
});

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ Cypress.Commands.add('umbracoCreateLanguage', (culture, isMandatory = false, fal
});
});

Cypress.Commands.add('umbracoEnsureLanguageNotExists', (culture) => {
Cypress.Commands.add('umbracoEnsureLanguageCultureNotExists', (culture) => {
cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => {
console.log('hit commands')
cy.request({
method: 'GET',
url: '/umbraco/backoffice/umbracoapi/language/GetAllLanguages',
Expand Down
25 changes: 25 additions & 0 deletions tests/Umbraco.Tests.AcceptanceTest/cypress/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,28 @@

// type definitions for custom commands like "createDefaultTodos"
// <reference types="support" />

export {};

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable<Subject> {
/**
* Checks to see if the language with specified culture does not exist
* If it does it will automatically delete it
* @param {string} culture Culture of language to delete
* @example cy.umbracoEnsureLanguageCultureNotExists('da-DK');
*/
umbracoEnsureLanguageCultureNotExists: (culture: string) => Chainable<void>;
/**
* Creates a language from a culture
* @param {string} culture Culture of the language - fx "da_DK"
* @param {boolean} isMandatory Set whether the language is mandatory or not. Defaults to false
* @param {string} fallbackLanguageId of the language to fallback to. Defaults to 1 which is en_US
* @example cy.umbracoCreateLanguage('da', true, '1');
*/
umbracoCreateLanguage: (culture: string, isMandatory: boolean, fallbackLanguageId: string) => Chainable<void>;
}
}
}