Files
Umbraco-CMS/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Settings/partialsViews.ts
Matt Darby 0a626c6c2a Replace .first() with localize (#11341)
Replaced usage of first() with localize to target specific action in context menu
2021-11-16 09:25:04 +10:00

146 lines
4.5 KiB
TypeScript

/// <reference types="Cypress" />
import {PartialViewBuilder} from "umbraco-cypress-testhelpers";
context('Partial Views', () => {
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 openPartialViewsCreatePanel() {
navigateToSettings();
cy.umbracoTreeItem("settings", ["Partial Views"]).rightclick();
}
it('Create new empty partial view', () => {
const name = "TestPartialView";
const fileName = name + ".cshtml";
cy.umbracoEnsurePartialViewNameNotExists(fileName);
openPartialViewsCreatePanel();
cy.umbracoContextMenuAction("action-create").click();
cy.get('.menu-label localize[key="create_newEmptyPartialView"]').click();
//Type name
cy.umbracoEditorHeaderName(name);
//Save
cy.get('.btn-success').click();
//Assert
cy.umbracoSuccessNotification().should('be.visible');
cy.umbracoPartialViewExists(fileName).then(exists => { expect(exists).to.be.true; });
//Clean up
cy.umbracoEnsurePartialViewNameNotExists(fileName);
});
it('Create partial view from snippet', () => {
const name = "TestPartialViewFromSnippet";
const fileName = name + ".cshtml";
cy.umbracoEnsurePartialViewNameNotExists(fileName);
openPartialViewsCreatePanel();
cy.umbracoContextMenuAction("action-create").click();
cy.get('.menu-label').eq(1).click();
// Select snippet
cy.get('.menu-label').eq(2).click();
// Type name
cy.umbracoEditorHeaderName(name);
// Save
cy.get('.btn-success').click();
// Assert
cy.umbracoSuccessNotification().should('be.visible');
cy.umbracoPartialViewExists(fileName).then(exists => { expect(exists).to.be.true; });
// Clean up
cy.umbracoEnsurePartialViewNameNotExists(fileName);
});
it('Partial view with no name', () => {
openPartialViewsCreatePanel();
cy.umbracoContextMenuAction("action-create").click();
cy.get('.menu-label localize[key="create_newEmptyPartialView"]').click();
// The test would fail intermittently, most likely because the editor didn't have time to load
// This should ensure that the editor is loaded and the test should no longer fail unexpectedly.
cy.get('.ace_content', {timeout: 5000}).should('exist');
// Click save
cy.get('.btn-success').click();
// Asserts
cy.umbracoErrorNotification().should('be.visible');
});
it('Delete partial view', () => {
const name = "TestDeletePartialView";
const fileName = name + ".cshtml";
cy.umbracoEnsurePartialViewNameNotExists(fileName);
// Build and save partial view
const partialView = new PartialViewBuilder()
.withName(name)
.withContent("@inherits UUmbraco.Cms.Web.Common.Views.UmbracoViewPage")
.build();
cy.savePartialView(partialView);
navigateToSettings();
// Delete partial view
cy.umbracoTreeItem("settings", ["Partial Views", fileName]).rightclick();
cy.umbracoContextMenuAction("action-delete").click();
cy.umbracoButtonByLabelKey("general_ok").click();
// Assert
cy.contains(fileName).should('not.exist');
cy.umbracoPartialViewExists(fileName).then(exists => { expect(exists).to.be.false; });
// Clean
cy.umbracoEnsurePartialViewNameNotExists(fileName);
});
it('Edit partial view', () => {
const name = 'EditPartialView';
const fileName = name + ".cshtml";
cy.umbracoEnsurePartialViewNameNotExists(fileName);
const partialView = new PartialViewBuilder()
.withName(name)
.withContent("@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage\n")
.build();
cy.savePartialView(partialView);
navigateToSettings();
// Open partial view
cy.umbracoTreeItem("settings", ["Partial Views", fileName]).click();
// Edit
cy.get('.ace_text-input').type("var num = 5;", {force:true} );
cy.get('.btn-success').click();
// Assert
cy.umbracoSuccessNotification().should('be.visible');
// Clean
cy.umbracoEnsurePartialViewNameNotExists(fileName);
});
});