forked from umbraco/Umbraco-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikolaj
committed
Aug 13, 2020
1 parent
9a2fb1e
commit 1512496
Showing
1 changed file
with
128 additions
and
19 deletions.
There are no files selected for viewing
147 changes: 128 additions & 19 deletions
147
src/Umbraco.Tests.AcceptanceTest/cypress/integration/Settings/templates.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,166 @@ | ||
/// <reference types="Cypress" /> | ||
import {DocumentTypeBuilder, TemplateBuilder} from "umbraco-cypress-testhelpers"; | ||
import { TemplateBuilder } from 'umbraco-cypress-testhelpers'; | ||
|
||
context('Templates', () => { | ||
|
||
beforeEach(() => { | ||
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password')); | ||
}); | ||
|
||
it('Create template', () => { | ||
const name = "Test template"; | ||
|
||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
beforeEach(() => { | ||
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password')); | ||
}); | ||
|
||
function navigateToSettings() { | ||
cy.umbracoSection('settings'); | ||
cy.get('li .umb-tree-root:contains("Settings")').should("be.visible"); | ||
} | ||
|
||
function createTemplate() { | ||
navigateToSettings(); | ||
cy.umbracoTreeItem("settings", ["Templates"]).rightclick(); | ||
|
||
cy.umbracoContextMenuAction("action-create").click(); | ||
} | ||
|
||
|
||
|
||
it('Create template', () => { | ||
const name = "Test template test"; | ||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
|
||
createTemplate(); | ||
//Type name | ||
cy.umbracoEditorHeaderName(name); | ||
/* Make an edit, if you don't the file will be create twice, | ||
only happens in testing though, probably because the test is too fast | ||
Certifiably mega wonk regardless */ | ||
cy.get('.ace_content').type("var num = 5;"); | ||
|
||
//Save | ||
cy.get("form[name='contentForm']").submit(); | ||
cy.get('.btn-success').click(); | ||
|
||
//Assert | ||
cy.umbracoSuccessNotification().should('be.visible'); | ||
|
||
//Clean up | ||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
}); | ||
}); | ||
|
||
it('Unsaved changes stay', () => { | ||
const name = "Templates Unsaved Changes Stay test"; | ||
const edit = "var num = 5;"; | ||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
|
||
const template = new TemplateBuilder() | ||
.withName(name) | ||
.withContent('@inherits Umbraco.Web.Mvc.UmbracoViewPage\n') | ||
.build(); | ||
|
||
cy.saveTemplate(template); | ||
|
||
navigateToSettings(); | ||
|
||
// Open partial view | ||
cy.umbracoTreeItem("settings", ["Templates", name]).click(); | ||
// Edit | ||
cy.get('.ace_content').type(edit); | ||
// Navigate away | ||
cy.umbracoSection('content'); | ||
// Click stay button | ||
cy.get('umb-button[label="Stay"] button:enabled').click(); | ||
|
||
// Assert | ||
// That the same document is open | ||
cy.get('#headerName').should('have.value', name); | ||
cy.get('.ace_content').contains(edit); | ||
|
||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
}); | ||
|
||
it('Discard unsaved changes', () => { | ||
const name = "Discard changes test"; | ||
const edit = "var num = 5;"; | ||
|
||
it('Delete template', () => { | ||
const name = "Test template"; | ||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
|
||
const template = new TemplateBuilder() | ||
.withName(name) | ||
.withContent('@inherits Umbraco.Web.Mvc.UmbracoViewPage\n') | ||
.build(); | ||
|
||
cy.saveTemplate(template); | ||
|
||
navigateToSettings(); | ||
|
||
// Open partial view | ||
cy.umbracoTreeItem("settings", ["Templates", name]).click(); | ||
// Edit | ||
cy.get('.ace_content').type(edit); | ||
// Navigate away | ||
cy.umbracoSection('content'); | ||
// Click discard | ||
cy.get('umb-button[label="Discard changes"] button:enabled').click(); | ||
// Navigate back | ||
cy.umbracoSection('settings'); | ||
cy.get('li .umb-tree-root:contains("Settings")').should("be.visible"); | ||
|
||
cy.umbracoTreeItem("settings", ["Templates", name]).rightclick(); | ||
cy.umbracoContextMenuAction("action-delete").click(); | ||
// Asserts | ||
cy.get('.ace_content').should('not.contain', edit); | ||
// cy.umbracoPartialViewExists(fileName).then(exists => { expect(exists).to.be.false; }); TODO: Switch to template | ||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
}); | ||
|
||
it('Insert macro', () => { | ||
const name = 'InsertMacroTest'; | ||
|
||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
cy.umbracoEnsureMacroNameNotExists(name); | ||
|
||
const template = new TemplateBuilder() | ||
.withName(name) | ||
.withContent('') | ||
.build(); | ||
|
||
cy.saveTemplate(template); | ||
|
||
cy.saveMacro(name); | ||
|
||
navigateToSettings(); | ||
cy.umbracoTreeItem("settings", ["Templates", name]).click(); | ||
// Insert macro | ||
cy.umbracoButtonByLabelKey('general_insert').click(); | ||
cy.get('.umb-insert-code-box__title').contains('Macro').click(); | ||
cy.get('.umb-card-grid-item').contains(name).click(); | ||
|
||
cy.umbracoButtonByLabelKey("general_ok").click(); | ||
// Assert | ||
cy.get('.ace_content').contains('@Umbraco.RenderMacro("' + name + '")').should('exist'); | ||
|
||
cy.contains(name).should('not.exist'); | ||
// Clean | ||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
cy.umbracoEnsureMacroNameNotExists(name); | ||
}); | ||
|
||
it('Insert value', () => { | ||
const name = 'Insert Value Test'; | ||
|
||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
|
||
const partialView = new TemplateBuilder() | ||
.withName(name) | ||
.withContent('') | ||
.build(); | ||
|
||
cy.saveTemplate(partialView); | ||
|
||
navigateToSettings(); | ||
cy.umbracoTreeItem("settings", ["Templates", name]).click(); | ||
|
||
// Insert value | ||
cy.umbracoButtonByLabelKey('general_insert').click(); | ||
cy.get('.umb-insert-code-box__title').contains('Value').click(); | ||
cy.get('select').select('umbracoBytes'); | ||
cy.umbracoButtonByLabelKey('general_submit').click(); | ||
|
||
// assert | ||
cy.get('.ace_content').contains('@Model.Value("umbracoBytes")').should('exist'); | ||
|
||
// Clean | ||
cy.umbracoEnsureTemplateNameNotExists(name); | ||
}); | ||
|
||
}); |