diff --git a/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts b/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts index 123109816482..9a7342b7f2d8 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts +++ b/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts @@ -1,16 +1,38 @@ /// + 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'); @@ -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); }); -}); \ No newline at end of file +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js b/tests/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js index 34da26d04e5f..4a2a6d31a299 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js +++ b/tests/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js @@ -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', diff --git a/tests/Umbraco.Tests.AcceptanceTest/cypress/typings.d.ts b/tests/Umbraco.Tests.AcceptanceTest/cypress/typings.d.ts index 3b7cf0b3e9d2..88626d5f0f3f 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/cypress/typings.d.ts +++ b/tests/Umbraco.Tests.AcceptanceTest/cypress/typings.d.ts @@ -3,3 +3,28 @@ // type definitions for custom commands like "createDefaultTodos" // + +export {}; + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + interface Chainable { + /** + * 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; + /** + * 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; + } + } +} \ No newline at end of file