Skip to content

Commit

Permalink
add delete language test (#11380)
Browse files Browse the repository at this point in the history
(cherry picked from commit ba73a39)
  • Loading branch information
jemayn authored and nul800sebastiaan committed Nov 3, 2021
1 parent 771dfdb commit ac83a32
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// <reference types="Cypress" />
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);
});

});
68 changes: 68 additions & 0 deletions src/Umbraco.Tests.AcceptanceTest/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}
});
});
});

0 comments on commit ac83a32

Please sign in to comment.