Skip to content

Commit

Permalink
Cy create language (umbraco#11546)
Browse files Browse the repository at this point in the history
* add create language test

* add create language test

* fix bug, move test to new folder and add type definitions

* update to use culture command

Co-authored-by: Jesper <[email protected]>
  • Loading branch information
jemayn and jmayntzhusen authored Nov 14, 2021
1 parent 837cef0 commit ea9d691
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
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>;
}
}
}

0 comments on commit ea9d691

Please sign in to comment.