Skip to content

Commit

Permalink
Merge pull request umbraco#8595 from umbraco/v8/feature/partial-view-…
Browse files Browse the repository at this point in the history
…macro-acceptance

V8/feature/Add acceptance tests
  • Loading branch information
bergmania authored Aug 20, 2020
2 parents 0140d90 + 67c25ad commit 2ac0ff9
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ context('Document Types', () => {
const name = "Test document type";

cy.umbracoEnsureDocumentTypeNameNotExists(name);
cy.umbracoEnsureTemplateNameNotExists(name);

cy.umbracoSection('settings');
cy.get('li .umb-tree-root:contains("Settings")').should("be.visible");
Expand Down Expand Up @@ -44,6 +45,7 @@ context('Document Types', () => {

//Assert
cy.umbracoSuccessNotification().should('be.visible');
cy.umbracoEnsureTemplateNameNotExists(name);

//Clean up
cy.umbracoEnsureDocumentTypeNameNotExists(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
/// <reference types="Cypress" />
import { PartialViewMacroBuilder } from "umbraco-cypress-testhelpers";

context('Partial View Macro Files', () => {

beforeEach(() => {
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'));
});

it('Create new partial view macro', () => {
const name = "TestPartialViewMacro";
const fileName = name + ".cshtml";

cy.umbracoEnsurePartialViewMacroFileNameNotExists(fileName);
cy.umbracoEnsureMacroNameNotExists(name);

function openPartialViewMacroCreatePanel() {
cy.umbracoSection('settings');
cy.get('li .umb-tree-root:contains("Settings")').should("be.visible");

cy.umbracoTreeItem("settings", ["Partial View Macro Files"]).rightclick();

cy.umbracoContextMenuAction("action-create").click();
}

function cleanup(name, extension = ".cshtml") {
const fileName = name + extension;

cy.umbracoEnsureMacroNameNotExists(name);
cy.umbracoEnsurePartialViewMacroFileNameNotExists(fileName);
}

it('Create new partial view macro', () => {
const name = "TestPartialViewMacro";

cleanup(name);

openPartialViewMacroCreatePanel();

cy.get('.menu-label').first().click(); // TODO: Fucked we cant use something like cy.umbracoContextMenuAction("action-label").click();

//Type name
Expand All @@ -28,10 +39,117 @@ context('Partial View Macro Files', () => {

//Assert
cy.umbracoSuccessNotification().should('be.visible');
cy.umbracoMacroExists(name).then(exists => { expect(exists).to.be.true; });

//Clean up
cy.umbracoEnsurePartialViewMacroFileNameNotExists(fileName);
cy.umbracoEnsureMacroNameNotExists(name);
});
cleanup(name);
});

it('Create new partial view macro without macro', () => {
const name = "TestPartialMacrolessMacro";

cleanup(name);

openPartialViewMacroCreatePanel();

cy.get('.menu-label').eq(1).click();

// Type name
cy.umbracoEditorHeaderName(name);

// Save
cy.get('.btn-success').click();

// Assert
cy.umbracoSuccessNotification().should('be.visible');
cy.umbracoMacroExists(name).then(exists => { expect(exists).to.be.false; });

// Clean
cleanup(name);
});

it('Create new partial view macro from snippet', () => {
const name = "TestPartialFromSnippet";

cleanup(name);

openPartialViewMacroCreatePanel();

cy.get('.menu-label').eq(2).click();

// Select snippet
cy.get('.menu-label').eq(1).click();

// Type name
cy.umbracoEditorHeaderName(name);

// Save
cy.get('.btn-success').click();

// Assert
cy.umbracoSuccessNotification().should('be.visible');
cy.umbracoMacroExists(name).then(exists => { expect(exists).to.be.true; });

// Clean
cleanup(name);
});

it('Delete partial view macro', () => {
const name = "TestDeletePartialViewMacro";
const fullName = name + ".cshtml"

cleanup(name);

const partialViewMacro = new PartialViewMacroBuilder()
.withName(name)
.withContent("@inherits Umbraco.Web.Macros.PartialViewMacroPage")
.build();

cy.savePartialViewMacro(partialViewMacro);

// Navigate to settings
cy.umbracoSection('settings');
cy.get('li .umb-tree-root:contains("Settings")').should("be.visible");

// Delete partialViewMacro
cy.umbracoTreeItem("settings", ["Partial View Macro Files", fullName]).rightclick();
cy.umbracoContextMenuAction("action-delete").click();
cy.umbracoButtonByLabelKey("general_ok").click();

// Assert
cy.contains(fullName).should('not.exist');

// Clean
cleanup(name);
});

it('Edit partial view macro', () => {
const name = "TestPartialViewMacroEditable";
const fullName = name + ".cshtml";

cleanup(name);

const partialViewMacro = new PartialViewMacroBuilder()
.withName(name)
.withContent("@inherits Umbraco.Web.Macros.PartialViewMacroPage")
.build();

cy.savePartialViewMacro(partialViewMacro);

// Navigate to settings
cy.umbracoSection('settings');
cy.get('li .umb-tree-root:contains("Settings")').should("be.visible");
cy.umbracoTreeItem("settings", ["Partial View Macro Files", fullName]).click();

// Type an edit
cy.get('.ace_text-input').type(" // test", {force:true} );
// Save
cy.get('.btn-success').click();

// Assert
cy.umbracoSuccessNotification().should('be.visible');

cleanup(name);
});

});
Original file line number Diff line number Diff line change
@@ -1,35 +1,145 @@
/// <reference types="Cypress" />
import { PartialViewBuilder } from "umbraco-cypress-testhelpers";

context('Partial Views', () => {

beforeEach(() => {
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'));
});
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').first().click(); // TODO: Fucked we cant use something like cy.umbracoContextMenuAction("action-mediaType").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').first().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 Umbraco.Web.Mvc.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();

it('Create new empty partial view', () => {
const name = "TestPartialView";
const fileName = name + ".cshtml";
// Assert
cy.contains(fileName).should('not.exist');
cy.umbracoPartialViewExists(fileName).then(exists => { expect(exists).to.be.false; });

cy.umbracoEnsurePartialViewNameNotExists(fileName);
// Clean
cy.umbracoEnsurePartialViewNameNotExists(fileName);
});

cy.umbracoSection('settings');
cy.get('li .umb-tree-root:contains("Settings")').should("be.visible");
it('Edit partial view', () => {
const name = 'EditPartialView';
const fileName = name + ".cshtml";

cy.umbracoTreeItem("settings", ["Partial Views"]).rightclick();
cy.umbracoEnsurePartialViewNameNotExists(fileName);

cy.umbracoContextMenuAction("action-create").click();
cy.get('.menu-label').first().click(); // TODO: Fucked we cant use something like cy.umbracoContextMenuAction("action-mediaType").click();
const partialView = new PartialViewBuilder()
.withName(name)
.withContent("@inherits Umbraco.Web.Mvc.UmbracoViewPage\n")
.build();

//Type name
cy.umbracoEditorHeaderName(name);
cy.savePartialView(partialView);

//Save
cy.get('.btn-success').click();
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');
// Assert
cy.umbracoSuccessNotification().should('be.visible');
// Clean
cy.umbracoEnsurePartialViewNameNotExists(fileName);
});

//Clean up
cy.umbracoEnsurePartialViewNameNotExists(fileName);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ context('Scripts', () => {
cy.umbracoSection('settings');
cy.get('li .umb-tree-root:contains("Settings")').should("be.visible");

cy.umbracoTreeItem("settings", ["Stylesheets"]).rightclick();
cy.umbracoTreeItem("settings", ["Scripts"]).rightclick();

cy.umbracoContextMenuAction("action-create").click();
cy.get('.menu-label').first().click(); // TODO: Fucked we cant use something like cy.umbracoContextMenuAction("action-mediaType").click();
Expand Down
Loading

0 comments on commit 2ac0ff9

Please sign in to comment.