Skip to content
Open
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
Expand Up @@ -16,8 +16,10 @@ export class ContentRenderUiHelper extends UiBaseLocators {
await this.page.goto(umbracoConfig.environment.baseUrl + contentURL);
}

async doesContentRenderValueContainText(text: string, isEqual: boolean = false) {
if (isEqual) {
async doesContentRenderValueContainText(text: string, isEqual: boolean = false, isVisible: boolean = true) {
if (!isVisible) {
await expect(this.contentRenderValue).not.toContainText(text);
} else if (isEqual) {
await this.hasText(this.contentRenderValue, text);
} else {
await this.containsText(this.contentRenderValue, text);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect} from "@playwright/test";

Check notice on line 1 in tests/Umbraco.Tests.AcceptanceTest/lib/helpers/DocumentApiHelper.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Missing Arguments Abstractions

The average number of function arguments decreases from 4.19 to 4.13, threshold = 4.00. The functions in this file have too many arguments, indicating a lack of encapsulation or too many responsibilities in the same functions. Avoid adding more.

Check notice on line 1 in tests/Umbraco.Tests.AcceptanceTest/lib/helpers/DocumentApiHelper.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Primitive Obsession

The ratio of primitive types in function arguments decreases from 97.16% to 96.97%, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.

Check notice on line 1 in tests/Umbraco.Tests.AcceptanceTest/lib/helpers/DocumentApiHelper.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: String Heavy Function Arguments

The ratio of strings in function arguments decreases from 95.17% to 95.04%, threshold = 39.0%. The functions in this file have a high ratio of strings as arguments. Avoid adding more.
import {AliasHelper} from "./AliasHelper";
import {ApiHelpers} from "./ApiHelpers";
import {DocumentBuilder, DocumentDomainBuilder} from "../builders";
Expand Down Expand Up @@ -161,13 +161,34 @@
return response.status();
}

async publishWithCultures(id: string, cultures: string[]) {
const publishSchedulesData = {publishSchedules: cultures.map(culture => ({culture}))};
return await this.publish(id, publishSchedulesData);
}

async unpublish(id: string, cultures: string[] | null = null) {
if (id == null) {
return;
}
const response = await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id + '/unpublish', {cultures});
return response.status();
}

async getDocumentUrl(id: string) {
const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/document/urls?id=' + id);
const urls = await response.json();

return urls[0].urlInfos[0].url;
}

async getDocumentUrlByCulture(id: string, culture: string) {
const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/document/urls?id=' + id);
const urls = await response.json();
const urlInfo = urls[0].urlInfos.find(info => info.culture === culture);

return urlInfo ? urlInfo.url : null;
}
Comment on lines +184 to +190

async moveToRecycleBin(id: string) {
if (id == null) {
return;
Expand Down Expand Up @@ -1509,6 +1530,22 @@
return await this.publish(id, publishScheduleData);
}

async createVariantDocumentWithParent(documentTypeId: string, templateId: string, name: string, cultures: string[], parentId?: string) {
const documentBuilder = new DocumentBuilder()
.withDocumentTypeId(documentTypeId)
.withTemplateId(templateId);

if (parentId) {
documentBuilder.withParentId(parentId);
}
Comment on lines +1533 to +1540

for (const culture of cultures) {
documentBuilder.addVariant().withName(name).withCulture(culture).done();
}

return await this.create(documentBuilder.build());
}

async createDocumentWithTextContentAndParent(documentName: string, documentTypeId: string, textContent: string, dataTypeName: string, parentId: string) {
await this.ensureNameNotExists(documentName);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ApiHelpers} from "./ApiHelpers";

Check notice on line 1 in tests/Umbraco.Tests.AcceptanceTest/lib/helpers/DocumentTypeApiHelper.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: String Heavy Function Arguments

The ratio of strings in function arguments decreases from 86.93% to 86.70%, threshold = 39.0%. The functions in this file have a high ratio of strings as arguments. Avoid adding more.
import {DocumentTypeBuilder} from "../builders";
import {AliasHelper} from "./AliasHelper";

Expand Down Expand Up @@ -434,6 +434,29 @@
}


async createVariantDocumentTypeWithTemplateAndAllowedChildNode(documentTypeName: string, templateId: string, isAllowedAsRoot: boolean = false, allowedChildNodeId?: string) {
await this.ensureNameNotExists(documentTypeName);

const documentTypeBuilder = new DocumentTypeBuilder()
.withName(documentTypeName)
.withAlias(AliasHelper.toAlias(documentTypeName))
.withAllowedAsRoot(isAllowedAsRoot)
.withVariesByCulture(true)
.addAllowedTemplateId()
.withId(templateId)
.done()
.withDefaultTemplateId(templateId);

if (allowedChildNodeId !== undefined) {
documentTypeBuilder
.addAllowedDocumentType()
.withId(allowedChildNodeId)
.done();
}

return await this.create(documentTypeBuilder.build());
}

async createDocumentTypeWithAllowedTemplate(documentTypeName: string, allowedTemplateId: string, isAllowedAsRoot:boolean = false) {
await this.ensureNameNotExists(documentTypeName);

Expand Down
3 changes: 2 additions & 1 deletion tests/Umbraco.Tests.AcceptanceTest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"testSqlite": "npm run build && npx playwright test DefaultConfig --grep-invert \"Users\"",
"all": "npm run build && npx playwright test",
"createTest": "node createTest.js",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Medium] Typo in smokeTest script: RenderingContentWIthCulturePublishStatus has an uppercase I in "WIth", but the actual spec file is named RenderingContentWithCulturePublishStatus.spec.ts. On Linux (where CI runs), filesystem lookups are case-sensitive, so this script will likely find zero tests and exit silently.

Suggestion: change RenderingContentWIthCulturePublishStatusRenderingContentWithCulturePublishStatus.

Fix this →

"smokeTest": "npm run build && npx playwright test DefaultConfig --grep \"@smoke\"",
"smokeTest": "npm run build && npx playwright test RenderingContentWIthCulturePublishStatus",
"smokeTester": "npm run build && npx playwright test DefaultConfig --grep \"@smoke\"",
Comment on lines +26 to +27
"smokeTestSqlite": "npm run build && npx playwright test DefaultConfig --grep \"@smoke\" --grep-invert \"Users\"",
"releaseTest": "npm run build && npx playwright test DefaultConfig --grep \"@release\"",
"testWindows": "npm run build && npx playwright test DefaultConfig --grep-invert \"RelationType\""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {test} from '@umbraco/acceptance-test-helpers';

// Languages
const englishIsoCode = 'en-US';
const danishIsoCode = 'da';
const cultures = [englishIsoCode, danishIsoCode];

// Document Types
const rootDocumentTypeName = 'RootDocumentType';
const childDocumentTypeName = 'ChildDocumentType';
const grandchildDocumentTypeName = 'GrandchildDocumentType';

// Content
const rootContentName = 'RootContent';
const publishedChildName = 'PublishedChild';
const unpublishedChildName = 'UnpublishedChild';
const grandchildContentName = 'Grandchild';
Comment on lines +14 to +17

// Template
const renderTemplateName = 'RenderDescendantsTemplate';

let renderTemplateId = '';
let rootContentId = '';
let unpublishedChildId = '';

test.beforeEach(async ({umbracoApi}) => {
await umbracoApi.document.ensureNameNotExists(rootContentName);
await umbracoApi.language.ensureIsoCodeNotExists(danishIsoCode);
await umbracoApi.language.createDanishLanguage();
renderTemplateId = await umbracoApi.template.createTemplateWithDisplayingValue(renderTemplateName, '\n@foreach (var content in Model.Descendants())\n{\n\t<li>@content.Name</li>\n}');
const grandchildDocumentTypeId = await umbracoApi.documentType.createVariantDocumentTypeWithTemplateAndAllowedChildNode(grandchildDocumentTypeName, renderTemplateId);
const childDocumentTypeId = await umbracoApi.documentType.createVariantDocumentTypeWithTemplateAndAllowedChildNode(childDocumentTypeName, renderTemplateId, false, grandchildDocumentTypeId);
const rootDocumentTypeId = await umbracoApi.documentType.createVariantDocumentTypeWithTemplateAndAllowedChildNode(rootDocumentTypeName, renderTemplateId, true, childDocumentTypeId);

rootContentId = await umbracoApi.document.createVariantDocumentWithParent(rootDocumentTypeId, renderTemplateId, rootContentName, cultures);
await umbracoApi.document.publishWithCultures(rootContentId, cultures);
const publishedChildId = await umbracoApi.document.createVariantDocumentWithParent(childDocumentTypeId, renderTemplateId, publishedChildName, cultures, rootContentId);
await umbracoApi.document.publishWithCultures(publishedChildId, cultures);
unpublishedChildId = await umbracoApi.document.createVariantDocumentWithParent(childDocumentTypeId, renderTemplateId, unpublishedChildName, cultures, rootContentId);
await umbracoApi.document.publishWithCultures(unpublishedChildId, cultures);
const grandchildId = await umbracoApi.document.createVariantDocumentWithParent(grandchildDocumentTypeId, renderTemplateId, grandchildContentName, cultures, unpublishedChildId);
await umbracoApi.document.publishWithCultures(grandchildId, cultures);

const domainsData = await umbracoApi.document.getDomains(rootContentId);
domainsData.domains = [
{domainName: '/en', isoCode: englishIsoCode},
{domainName: '/da', isoCode: danishIsoCode}
];
await umbracoApi.document.updateDomains(rootContentId, domainsData);
});
Comment thread
andr317c marked this conversation as resolved.

test.afterEach(async ({umbracoApi}) => {
await umbracoApi.document.ensureNameNotExists(rootContentName);
await umbracoApi.documentType.ensureNameNotExists(rootDocumentTypeName);
await umbracoApi.documentType.ensureNameNotExists(childDocumentTypeName);
await umbracoApi.documentType.ensureNameNotExists(grandchildDocumentTypeName);
await umbracoApi.template.ensureNameNotExists(renderTemplateName);
await umbracoApi.language.ensureIsoCodeNotExists(danishIsoCode);
});

test('can see a descendant is rendered when its ancestor is published in the requested culture', async ({umbracoApi, umbracoUi}) => {

Check failure on line 61 in tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/RenderingContent/RenderingContentWithCulturePublishStatus.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add at least one assertion to this test case.

See more on https://sonarcloud.io/project/issues?id=umbraco_Umbraco-CMS&issues=AZ6JuAKkjzFPwmpxmd5A&open=AZ6JuAKkjzFPwmpxmd5A&pullRequest=23047
// Act
const rootDanishUrl = await umbracoApi.document.getDocumentUrlByCulture(rootContentId, danishIsoCode);
await umbracoUi.contentRender.navigateToRenderedContentPage(rootDanishUrl);

// Assert
await umbracoUi.contentRender.doesContentRenderValueContainText(grandchildContentName);
});

test('a descendant is not rendered when its ancestor is unpublished in the requested culture', async ({umbracoApi, umbracoUi}) => {

Check failure on line 70 in tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/RenderingContent/RenderingContentWithCulturePublishStatus.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add at least one assertion to this test case.

See more on https://sonarcloud.io/project/issues?id=umbraco_Umbraco-CMS&issues=AZ6JuAKkjzFPwmpxmd5B&open=AZ6JuAKkjzFPwmpxmd5B&pullRequest=23047
// Arrange
await umbracoApi.document.unpublish(unpublishedChildId, [englishIsoCode]);

// Act
const rootEnglishUrl = await umbracoApi.document.getDocumentUrlByCulture(rootContentId, englishIsoCode);
await umbracoUi.contentRender.navigateToRenderedContentPage(rootEnglishUrl);

// Assert
// In English the published child is a descendant, but the grandchild is excluded because its ancestor is unpublished in English
await umbracoUi.contentRender.doesContentRenderValueContainText(publishedChildName);
await umbracoUi.contentRender.doesContentRenderValueContainText(grandchildContentName, false, false);
});
Comment thread
andr317c marked this conversation as resolved.
Loading