Skip to content

Commit cd596b4

Browse files
ZeegaanNikolaj Geisleelit0451
authored
v9: Implemented new routing tests (#11571)
* Implemented new routing tests * Update package-lock.json * Cleanup * Updated routing to cleanup before and after tests Co-authored-by: Nikolaj Geisle <[email protected]> Co-authored-by: Elitsa Marinovska <[email protected]>
1 parent 740c2e4 commit cd596b4

File tree

3 files changed

+373
-4
lines changed

3 files changed

+373
-4
lines changed
Lines changed: 369 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,369 @@
1+
/// <reference types="Cypress" />
2+
import {
3+
DocumentTypeBuilder,
4+
ContentBuilder
5+
} from 'umbraco-cypress-testhelpers';
6+
7+
context('Routing', () => {
8+
9+
let swedishLanguageId = 0;
10+
const swedishCulture = "sv";
11+
const danishCulture = "da"
12+
const nodeName = "Root";
13+
const childNodeName = "Child";
14+
const grandChildNodeName = "Grandchild";
15+
const rootDocTypeName = "Test document type";
16+
17+
function refreshContentTree() {
18+
// Refresh to update the tree
19+
cy.get('li .umb-tree-root:contains("Content")').should("be.visible").rightclick();
20+
cy.umbracoContextMenuAction("action-refreshNode").click();
21+
// We have to wait in case the execution is slow, otherwise we'll try and click the item before it appears in the UI
22+
cy.get('.umb-tree-item__inner').should('exist', {timeout: 10000});
23+
}
24+
25+
function saveNewLanguages() {
26+
// Save Danish
27+
const url = "/umbraco/backoffice/umbracoapi/language/SaveLanguage";
28+
const danishRequestBody = {
29+
culture: danishCulture
30+
}
31+
32+
cy.umbracoApiRequest(url, "POST", danishRequestBody);
33+
34+
// Save Swedish
35+
const swedishRequestBody = {
36+
culture: swedishCulture
37+
}
38+
cy.umbracoApiRequest(url, "POST", swedishRequestBody).then((responseBody) => {
39+
swedishLanguageId = responseBody["id"];
40+
});
41+
}
42+
43+
function configureDomain(id, name, lang) {
44+
//Save domain for child node
45+
const url = "/umbraco/backoffice/umbracoapi/content/PostSaveLanguageAndDomains"
46+
const body = {
47+
nodeId : id,
48+
domains : [
49+
{
50+
name : name,
51+
lang : lang
52+
}],
53+
language : 0
54+
}
55+
cy.umbracoApiRequest(url, 'POST', body);
56+
}
57+
58+
beforeEach(() => {
59+
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'));
60+
cy.umbracoEnsureLanguageNotExists(danishCulture);
61+
cy.umbracoEnsureLanguageNotExists(swedishCulture);
62+
});
63+
64+
afterEach(() => {
65+
cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName);
66+
cy.umbracoEnsureLanguageNotExists(danishCulture);
67+
cy.umbracoEnsureLanguageNotExists(swedishCulture);
68+
})
69+
70+
it('Root node published in language A, Child node published in language A', () => {
71+
72+
const rootDocType = new DocumentTypeBuilder()
73+
.withName(rootDocTypeName)
74+
.withAllowAsRoot(true)
75+
.withAllowCultureVariation(true)
76+
.build();
77+
78+
cy.deleteAllContent();
79+
cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName);
80+
81+
saveNewLanguages();
82+
83+
cy.saveDocumentType(rootDocType).then((generatedRootDocType) => {
84+
const rootContentNode = new ContentBuilder()
85+
.withContentTypeAlias(generatedRootDocType["alias"])
86+
.withAction("publishNew")
87+
.addVariant()
88+
.withCulture('en-US')
89+
.withName(nodeName)
90+
.withSave(true)
91+
.withPublish(true)
92+
.done()
93+
.build();
94+
95+
cy.saveContent(rootContentNode).then((generatedRootContent) => {
96+
const childContentNode = new ContentBuilder()
97+
.withContentTypeAlias(generatedRootDocType["alias"])
98+
.withAction("saveNew")
99+
.withParent(generatedRootContent["id"])
100+
.addVariant()
101+
.withCulture('en-US')
102+
.withName(childNodeName)
103+
.withSave(true)
104+
.done()
105+
.build();
106+
107+
cy.saveContent(childContentNode);
108+
});
109+
});
110+
111+
// Refresh to update the tree
112+
refreshContentTree();
113+
114+
cy.umbracoTreeItem("content", [nodeName, childNodeName]).click();
115+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
116+
// Pop-up with what cultures you want to publish shows, click it
117+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click();
118+
119+
// Assert
120+
cy.get('.alert-success').should('exist');
121+
});
122+
123+
124+
it('Root node published in language A, Child node published in language B', () => {
125+
126+
const rootDocType = new DocumentTypeBuilder()
127+
.withName(rootDocTypeName)
128+
.withAllowAsRoot(true)
129+
.withAllowCultureVariation(true)
130+
.build();
131+
132+
cy.deleteAllContent();
133+
cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName);
134+
135+
saveNewLanguages();
136+
137+
cy.saveDocumentType(rootDocType).then((generatedRootDocType) => {
138+
const rootContentNode = new ContentBuilder()
139+
.withContentTypeAlias(generatedRootDocType["alias"])
140+
.withAction("publishNew")
141+
.addVariant()
142+
.withCulture('en-US')
143+
.withName(nodeName)
144+
.withSave(true)
145+
.withPublish(true)
146+
.done()
147+
.build();
148+
149+
cy.saveContent(rootContentNode).then((generatedRootContent) => {
150+
const childContentNode = new ContentBuilder()
151+
.withContentTypeAlias(generatedRootDocType["alias"])
152+
.withAction("saveNew")
153+
.withParent(generatedRootContent["id"])
154+
.addVariant()
155+
.withCulture('en-US')
156+
.withName(childNodeName)
157+
.withSave(true)
158+
.done()
159+
.addVariant()
160+
.withCulture(swedishCulture)
161+
.withName("Bärn")
162+
.withSave(true)
163+
.done()
164+
.build();
165+
166+
cy.saveContent(childContentNode);
167+
});
168+
});
169+
170+
// Refresh to update the tree
171+
refreshContentTree();
172+
173+
cy.umbracoTreeItem("content", [nodeName, childNodeName]).click();
174+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
175+
// Pop-up with what cultures you want to publish shows, click it
176+
cy.get('.umb-list').contains("Swedish").click();
177+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click();
178+
179+
// Assert
180+
cy.get('.alert-success').should('have.length', 2);
181+
cy.get('.alert-warning').should('exist');
182+
});
183+
184+
it('Root node published in language A, Child node published in language A + B, Grandchild published in A + B', () => {
185+
186+
const rootDocType = new DocumentTypeBuilder()
187+
.withName(rootDocTypeName)
188+
.withAllowAsRoot(true)
189+
.withAllowCultureVariation(true)
190+
.build();
191+
192+
cy.deleteAllContent();
193+
cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName);
194+
195+
saveNewLanguages();
196+
197+
cy.saveDocumentType(rootDocType).then((generatedRootDocType) => {
198+
const rootContentNode = new ContentBuilder()
199+
.withContentTypeAlias(generatedRootDocType["alias"])
200+
.withAction("publishNew")
201+
.addVariant()
202+
.withCulture('en-US')
203+
.withName(nodeName)
204+
.withSave(true)
205+
.withPublish(true)
206+
.done()
207+
.build();
208+
209+
cy.saveContent(rootContentNode).then((generatedRootContent) => {
210+
211+
configureDomain(generatedRootContent["id"], "/en", 1);
212+
const childContentNode = new ContentBuilder()
213+
.withContentTypeAlias(generatedRootDocType["alias"])
214+
.withAction("saveNew")
215+
.withParent(generatedRootContent["id"])
216+
.addVariant()
217+
.withCulture('en-US')
218+
.withName(childNodeName)
219+
.withSave(true)
220+
.done()
221+
.addVariant()
222+
.withCulture(swedishCulture)
223+
.withName("Barn")
224+
.withSave(true)
225+
.done()
226+
.build();
227+
228+
cy.saveContent(childContentNode).then((generatedChildContent) => {
229+
230+
configureDomain(generatedChildContent["id"], "/sv", swedishLanguageId);
231+
const grandChildContentNode = new ContentBuilder()
232+
.withContentTypeAlias(generatedRootDocType["alias"])
233+
.withAction("saveNew")
234+
.withParent(generatedChildContent["id"])
235+
.addVariant()
236+
.withCulture('en-US')
237+
.withName(grandChildNodeName)
238+
.withSave(true)
239+
.done()
240+
.addVariant()
241+
.withCulture(swedishCulture)
242+
.withName("Barnbarn")
243+
.withSave(true)
244+
.done()
245+
.build();
246+
247+
cy.saveContent(grandChildContentNode);
248+
});
249+
});
250+
});
251+
252+
// Refresh to update the tree
253+
refreshContentTree();
254+
255+
// Publish Child
256+
cy.umbracoTreeItem("content", [nodeName, childNodeName]).click();
257+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
258+
//Pop-up with what cultures you want to publish shows, click it
259+
cy.get('.umb-list').contains("Swedish").click();
260+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click();
261+
262+
// Publish Grandchild
263+
cy.umbracoTreeItem("content", [nodeName, childNodeName, grandChildNodeName]).click();
264+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
265+
// Pop-up with what cultures you want to publish shows, click it
266+
cy.get('.umb-list').contains("Swedish").click();
267+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click();
268+
269+
// Assert
270+
cy.get('.alert-success').should('have.length', 2);
271+
cy.get('.alert-warning').should('not.exist');
272+
});
273+
274+
it('Root node published in language A, Child node published in language A + B, Grandchild published in A + B + C', () => {
275+
276+
const rootDocType = new DocumentTypeBuilder()
277+
.withName(rootDocTypeName)
278+
.withAllowAsRoot(true)
279+
.withAllowCultureVariation(true)
280+
.build();
281+
282+
cy.deleteAllContent();
283+
cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName);
284+
285+
saveNewLanguages();
286+
287+
cy.saveDocumentType(rootDocType).then((generatedRootDocType) => {
288+
const rootContentNode = new ContentBuilder()
289+
.withContentTypeAlias(generatedRootDocType["alias"])
290+
.withAction("publishNew")
291+
.addVariant()
292+
.withCulture('en-US')
293+
.withName(nodeName)
294+
.withSave(true)
295+
.withPublish(true)
296+
.done()
297+
.build();
298+
299+
cy.saveContent(rootContentNode).then((generatedRootContent) => {
300+
301+
configureDomain(generatedRootContent["id"], "/en", 1);
302+
const childContentNode = new ContentBuilder()
303+
.withContentTypeAlias(generatedRootDocType["alias"])
304+
.withAction("saveNew")
305+
.withParent(generatedRootContent["id"])
306+
.addVariant()
307+
.withCulture('en-US')
308+
.withName(childNodeName)
309+
.withSave(true)
310+
.done()
311+
.addVariant()
312+
.withCulture(swedishCulture)
313+
.withName("Barn")
314+
.withSave(true)
315+
.done()
316+
.build();
317+
318+
cy.saveContent(childContentNode).then((generatedChildContent) => {
319+
320+
configureDomain(generatedChildContent["id"], "/sv", swedishLanguageId);
321+
const grandChildContentNode = new ContentBuilder()
322+
.withContentTypeAlias(generatedRootDocType["alias"])
323+
.withAction("saveNew")
324+
.withParent(generatedChildContent["id"])
325+
.addVariant()
326+
.withCulture('en-US')
327+
.withName(grandChildNodeName)
328+
.withSave(true)
329+
.done()
330+
.addVariant()
331+
.withCulture(swedishCulture)
332+
.withName("Barnbarn")
333+
.withSave(true)
334+
.done()
335+
.addVariant()
336+
.withCulture(danishCulture)
337+
.withName("Barnebarn")
338+
.withSave(true)
339+
.done()
340+
.build();
341+
342+
cy.saveContent(grandChildContentNode);
343+
});
344+
});
345+
});
346+
347+
// Refresh to update the tree
348+
refreshContentTree();
349+
350+
// Publish Child
351+
cy.umbracoTreeItem("content", [nodeName, childNodeName]).click();
352+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
353+
// Pop-up with what cultures you want to publish shows, click it
354+
cy.get('.umb-list').contains("Swedish").click();
355+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click();
356+
357+
// Publish Grandchild
358+
cy.umbracoTreeItem("content", [nodeName, childNodeName, grandChildNodeName]).click();
359+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
360+
// Pop-up with what cultures you want to publish shows, click it
361+
cy.get('.umb-list').contains("Swedish").click();
362+
cy.get('.umb-list').contains("Danish").click();
363+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click();
364+
365+
// Assert
366+
cy.get('.alert-success').should('exist');
367+
cy.get('.alert-warning').should('exist');
368+
});
369+
});

tests/Umbraco.Tests.AcceptanceTest/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Umbraco.Tests.AcceptanceTest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"del": "^6.0.0",
1414
"ncp": "^2.0.0",
1515
"prompt": "^1.2.0",
16-
"umbraco-cypress-testhelpers": "^1.0.0-beta-60"
16+
"umbraco-cypress-testhelpers": "^1.0.0-beta-61"
1717
},
1818
"dependencies": {
1919
"typescript": "^3.9.2"

0 commit comments

Comments
 (0)