Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add update language test #11333

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// <reference types="Cypress" />
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);
});

});
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;
});
});
});
Comment on lines +34 to +59
Copy link
Member

@Zeegaan Zeegaan Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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('umbracoCreateLanguage', (culture, isMandatory = false, fallbackLanguageId = 1) => {
var langData =
{
"culture": culture,
"isMandatory": isMandatory,
"fallbackLanguageId": fallbackLanguageId
};
// Create language through API
let url = '/umbraco/backoffice/umbracoapi/language/SaveLanguage';
cy.umbracoApiRequest(url, 'POST', langData);
});

Should probably use cy.umbracoApiRequest instead of manually calling the API


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;
});
}
}
});
});
});
Copy link
Member

@Zeegaan Zeegaan Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have already have a helper function that does this! its called umbracoEnsureLanguageNameNotExists (i just make that a few weeks ago for my system information tests 🙈 )