From ba73a3955807c1cedb5b593cf689170977e1f837 Mon Sep 17 00:00:00 2001 From: Jesper Mayntzhusen <79840720+jemayn@users.noreply.github.com> Date: Tue, 26 Oct 2021 17:40:37 +0200 Subject: [PATCH] add delete language test (#11380) --- .../integration/Languages/languages.ts | 38 +++++++++++ .../cypress/support/commands.js | 68 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts 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..123109816482 --- /dev/null +++ b/src/Umbraco.Tests.AcceptanceTest/cypress/integration/Languages/languages.ts @@ -0,0 +1,38 @@ +/// +context('Languages', () => { + + beforeEach(() => { + cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'), false); + }); + + it('Deletes language', () => { + // Setup + const language1 = 'da'; + const language2 = 'en-GB'; + cy.umbracoEnsureLanguageNotExists(language1); + cy.umbracoEnsureLanguageNotExists(language2); + cy.umbracoCreateLanguage(language1, true, '1'); + cy.umbracoCreateLanguage(language2, true, '1'); + cy.umbracoSection('settings'); + + // Enter language tree and select the language we just created + cy.umbracoTreeItem('settings', ['Languages']).click(); + + // Assert there are 3 languages + cy.get('tbody > tr').should('have.length', 3); + + // Delete the Danish language + cy.get('tr').contains('Danish').parents('tr').within(() => { + cy.get('umb-button[label-key="general_delete"]').click() + }); + cy.umbracoButtonByLabelKey('contentTypeEditor_yesDelete').click(); + + // Assert there is only 2 language + cy.get('tbody > tr').should('have.length', 3); + + // Cleanup + cy.umbracoEnsureLanguageNotExists(language1); + cy.umbracoEnsureLanguageNotExists(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 5b0be47114e1..34da26d04e5f 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js +++ b/tests/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', (culture) => { + cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => { + console.log('hit commands') + 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.culture === culture) { + 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