diff --git a/src/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts b/src/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts new file mode 100644 index 000000000000..70cc51bb4aa6 --- /dev/null +++ b/src/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts @@ -0,0 +1,31 @@ +/// +context('Languages', () => { + + beforeEach(() => { + cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'), false); + }); + + it('Updates language', () => { + // Setup + const language = 'Danish'; + cy.umbracoEnsureLanguageNotExists(language); + cy.umbracoCreateLanguage('da', true, '1'); + cy.umbracoSection('settings'); + + // Enter language tree and select the language we just created + cy.umbracoTreeItem('settings', ['Languages']).click(); + cy.get('tr').contains('Danish').click(); + + // Edit the language + cy.get('div[ng-click="vm.toggleMandatory()"]').children('button').click(); // the mandatory language toggle + cy.get('select[name="fallbackLanguage"]').select('No fall back language') + + // Save and assert success + cy.umbracoButtonByLabelKey('buttons_save').click(); + cy.umbracoSuccessNotification().should('be.visible'); + + // Cleanup + cy.umbracoEnsureLanguageNotExists(language); + }); + +}); \ No newline at end of file diff --git a/src/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js b/src/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js index 5b0be47114e1..846ebb6aaf67 100644 --- a/src/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js +++ b/src/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js @@ -26,5 +26,73 @@ import {Command} from 'umbraco-cypress-testhelpers'; import {Chainable} from './chainable'; +import { JsonHelper } from 'umbraco-cypress-testhelpers'; + new Chainable(); new Command().registerCypressCommands(); + +Cypress.Commands.add('umbracoCreateLanguage', (culture, isMandatory = false, fallbackLanguageId = 1) => { + + var langData = + { + "culture": culture, + "isMandatory": isMandatory, + "fallbackLanguageId": fallbackLanguageId + }; + + // Create language through API + cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => { + cy.request({ + method: 'POST', + url: '/umbraco/backoffice/umbracoapi/language/SaveLanguage', + followRedirect: true, + headers: { + Accept: 'application/json', + 'X-UMB-XSRF-TOKEN': token.value, + }, + body: langData, + log: false, + }).then((response) => { + return; + }); + }); +}); + +Cypress.Commands.add('umbracoEnsureLanguageNotExists', (name) => { + cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => { + cy.request({ + method: 'GET', + url: '/umbraco/backoffice/umbracoapi/language/GetAllLanguages', + followRedirect: true, + headers: { + Accept: 'application/json', + 'X-UMB-XSRF-TOKEN': token.value, + }, + log: false, + }).then((response) => { + const searchBody = JsonHelper.getBody(response); + if (searchBody.length > 0) { + let languageId = null; + for (const sb of searchBody) { + if (sb.name === name) { + languageId = sb.id; + } + } + + if (languageId !== null) { + cy.request({ + method: 'POST', + url: '/umbraco/backoffice/umbracoapi/language/DeleteLanguage?id=' + languageId, + followRedirect: false, + headers: { + ContentType: 'application/json', + 'X-UMB-XSRF-TOKEN': token.value, + }, + }).then((resp) => { + return; + }); + } + } + }); + }); +}); \ No newline at end of file