Skip to content

Commit bfc3068

Browse files
authored
Merge pull request #10056 from umbraco/v8/feature/new-cypress-content-tests
Add new cypress tests
2 parents b723b4d + 64724ac commit bfc3068

File tree

2 files changed

+204
-2
lines changed

2 files changed

+204
-2
lines changed

src/Umbraco.Tests.AcceptanceTest/cypress/integration/Content/content.ts

Lines changed: 203 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
/// <reference types="Cypress" />
2-
import { DocumentTypeBuilder, ContentBuilder, AliasHelper } from 'umbraco-cypress-testhelpers';
2+
import {
3+
DocumentTypeBuilder,
4+
ContentBuilder,
5+
AliasHelper,
6+
GridDataTypeBuilder,
7+
PartialViewMacroBuilder,
8+
MacroBuilder
9+
} from 'umbraco-cypress-testhelpers';
10+
311
context('Content', () => {
412

513
beforeEach(() => {
@@ -14,6 +22,23 @@ context('Content', () => {
1422
cy.get('.umb-tree-item__inner').should('exist', {timeout: 10000});
1523
}
1624

25+
function createSimpleMacro(name){
26+
const insertMacro = new PartialViewMacroBuilder()
27+
.withName(name)
28+
.withContent(`@inherits Umbraco.Web.Macros.PartialViewMacroPage
29+
<h1>Acceptance test</h1>`)
30+
.build();
31+
32+
const macroWithPartial = new MacroBuilder()
33+
.withName(name)
34+
.withPartialViewMacro(insertMacro)
35+
.withRenderInEditor()
36+
.withUseInEditor()
37+
.build();
38+
39+
cy.saveMacroWithPartial(macroWithPartial);
40+
}
41+
1742
it('Copy content', () => {
1843
const rootDocTypeName = "Test document type";
1944
const childDocTypeName = "Child test document type";
@@ -596,4 +621,181 @@ context('Content', () => {
596621
cy.umbracoEnsureTemplateNameNotExists(pickerDocTypeName);
597622
cy.umbracoEnsureDocumentTypeNameNotExists(pickedDocTypeName);
598623
});
624+
625+
it('Content with macro in RTE', () => {
626+
const viewMacroName = 'Content with macro in RTE';
627+
const partialFileName = viewMacroName + '.cshtml';
628+
629+
cy.umbracoEnsureMacroNameNotExists(viewMacroName);
630+
cy.umbracoEnsurePartialViewMacroFileNameNotExists(partialFileName);
631+
cy.umbracoEnsureDocumentTypeNameNotExists(viewMacroName);
632+
cy.umbracoEnsureTemplateNameNotExists(viewMacroName);
633+
cy.deleteAllContent();
634+
635+
// First thing first we got to create the macro we will be inserting
636+
createSimpleMacro(viewMacroName);
637+
638+
// Now we need to create a document type with a rich text editor where we can insert the macro
639+
// The document type must have a template as well in order to ensure that the content is displayed correctly
640+
const alias = AliasHelper.toAlias(viewMacroName);
641+
const docType = new DocumentTypeBuilder()
642+
.withName(viewMacroName)
643+
.withAlias(alias)
644+
.withAllowAsRoot(true)
645+
.withDefaultTemplate(alias)
646+
.addGroup()
647+
.addRichTextProperty()
648+
.withAlias('text')
649+
.done()
650+
.done()
651+
.build();
652+
653+
cy.saveDocumentType(docType).then((generatedDocType) => {
654+
// Might as wel initally create the content here, the less GUI work during the test the better
655+
const contentNode = new ContentBuilder()
656+
.withContentTypeAlias(generatedDocType["alias"])
657+
.withAction('saveNew')
658+
.addVariant()
659+
.withName(viewMacroName)
660+
.withSave(true)
661+
.done()
662+
.build();
663+
664+
cy.saveContent(contentNode);
665+
});
666+
667+
// Edit the macro template in order to have something to verify on when rendered.
668+
cy.editTemplate(viewMacroName, `@inherits Umbraco.Web.Mvc.UmbracoViewPage
669+
@using ContentModels = Umbraco.Web.PublishedModels;
670+
@{
671+
Layout = null;
672+
}
673+
@{
674+
if (Model.HasValue("text")){
675+
@(Model.Value("text"))
676+
}
677+
} `);
678+
679+
// Enter content
680+
refreshContentTree();
681+
cy.umbracoTreeItem("content", [viewMacroName]).click();
682+
683+
// Insert macro
684+
cy.get('#mceu_13-button').click();
685+
cy.get('.umb-card-grid-item').contains(viewMacroName).click();
686+
687+
// Save and publish
688+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
689+
cy.umbracoSuccessNotification().should('be.visible');
690+
691+
// Ensure that the view gets rendered correctly
692+
const expected = `<h1>Acceptance test</h1><p> </p>`;
693+
cy.umbracoVerifyRenderedViewContent('/', expected, true).should('be.true');
694+
695+
// Cleanup
696+
cy.umbracoEnsureMacroNameNotExists(viewMacroName);
697+
cy.umbracoEnsurePartialViewMacroFileNameNotExists(partialFileName);
698+
cy.umbracoEnsureDocumentTypeNameNotExists(viewMacroName);
699+
cy.umbracoEnsureTemplateNameNotExists(viewMacroName);
700+
});
701+
702+
it('Content with macro in grid', () => {
703+
const name = 'Content with macro in grid';
704+
const macroName = 'Grid macro';
705+
const macroFileName = macroName + '.cshtml';
706+
707+
cy.umbracoEnsureDataTypeNameNotExists(name);
708+
cy.umbracoEnsureDocumentTypeNameNotExists(name);
709+
cy.umbracoEnsureTemplateNameNotExists(name);
710+
cy.umbracoEnsureMacroNameNotExists(macroName);
711+
cy.umbracoEnsurePartialViewMacroFileNameNotExists(macroFileName);
712+
cy.deleteAllContent();
713+
714+
createSimpleMacro(macroName);
715+
716+
const grid = new GridDataTypeBuilder()
717+
.withName(name)
718+
.withDefaultGrid()
719+
.build();
720+
721+
const alias = AliasHelper.toAlias(name);
722+
// Save grid and get the ID
723+
cy.saveDataType(grid).then((dataType) => {
724+
// Create a document type using the data type
725+
const docType = new DocumentTypeBuilder()
726+
.withName(name)
727+
.withAlias(alias)
728+
.withAllowAsRoot(true)
729+
.withDefaultTemplate(alias)
730+
.addGroup()
731+
.addCustomProperty(dataType['id'])
732+
.withAlias('grid')
733+
.done()
734+
.done()
735+
.build();
736+
737+
cy.saveDocumentType(docType).then((generatedDocType) => {
738+
const contentNode = new ContentBuilder()
739+
.withContentTypeAlias(generatedDocType["alias"])
740+
.addVariant()
741+
.withName(name)
742+
.withSave(true)
743+
.done()
744+
.build();
745+
746+
cy.saveContent(contentNode);
747+
});
748+
});
749+
750+
// Edit the template to allow us to verify the rendered view
751+
cy.editTemplate(name, `@inherits Umbraco.Web.Mvc.UmbracoViewPage
752+
@using ContentModels = Umbraco.Web.PublishedModels;
753+
@{
754+
Layout = null;
755+
}
756+
@Html.GetGridHtml(Model, "grid")`);
757+
758+
// Act
759+
// Enter content
760+
refreshContentTree();
761+
cy.umbracoTreeItem("content", [name]).click();
762+
// Click add
763+
cy.get(':nth-child(2) > .preview-row > .preview-col > .preview-cell').click(); // Choose 1 column layout.
764+
cy.get('.umb-column > .templates-preview > :nth-child(2) > .ng-binding').click(); // Choose headline
765+
cy.get('.umb-cell-placeholder').click();
766+
// Click macro
767+
cy.get(':nth-child(4) > .umb-card-grid-item > :nth-child(1)').click();
768+
// Select the macro
769+
cy.get('.umb-card-grid-item').contains(macroName).click();
770+
771+
// Save and publish
772+
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
773+
cy.umbracoSuccessNotification().should('be.visible');
774+
775+
const expected = `
776+
<div class="umb-grid">
777+
<div class="grid-section">
778+
<div>
779+
<div class="container">
780+
<div class="row clearfix">
781+
<div class="col-md-12 column">
782+
<div>
783+
<h1>Acceptance test</h1>
784+
</div>
785+
</div>
786+
</div>
787+
</div>
788+
</div>
789+
</div>
790+
</div>`
791+
792+
cy.umbracoVerifyRenderedViewContent('/', expected, true).should('be.true');
793+
794+
// Clean
795+
cy.umbracoEnsureDataTypeNameNotExists(name);
796+
cy.umbracoEnsureDocumentTypeNameNotExists(name);
797+
cy.umbracoEnsureTemplateNameNotExists(name);
798+
cy.umbracoEnsureMacroNameNotExists(macroName);
799+
cy.umbracoEnsurePartialViewMacroFileNameNotExists(macroFileName);
800+
});
599801
});

src/Umbraco.Tests.AcceptanceTest/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"cypress": "^6.8.0",
1111
"ncp": "^2.0.0",
1212
"prompt": "^1.0.0",
13-
"umbraco-cypress-testhelpers": "^1.0.0-beta-52"
13+
"umbraco-cypress-testhelpers": "^1.0.0-beta-53"
1414
},
1515
"dependencies": {
1616
"typescript": "^3.9.2"

0 commit comments

Comments
 (0)