From 87a66c064fd4ef42305bdfaedfcced08f73d3648 Mon Sep 17 00:00:00 2001 From: Andreas Zerbst <73799582+andr317c@users.noreply.github.com> Date: Fri, 23 Jun 2023 12:00:16 +0200 Subject: [PATCH] Added acceptance tests for testing the API for the Script section (#14441) * Added auth to gitignore * Added a setup for logging in which allows us to save the token for the user * Added simple acceptance test for testing our api for the DataTypes * Added simple acceptance tests for testing the API for the PartialView section * Added simple acceptance tests for testing the API for the Script section * Added acceptance tests for testing the API for the Stylesheet section. (#14442) --- .../tests/ApiTesting/Script/Script.spec.ts | 51 ++++++++++ .../ApiTesting/Script/ScriptFolder.spec.ts | 69 +++++++++++++ .../ApiTesting/Stylesheet/Stylesheet.spec.ts | 96 +++++++++++++++++++ .../Stylesheet/StylesheetFolder.spec.ts | 96 +++++++++++++++++++ 4 files changed, 312 insertions(+) create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Script/Script.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Script/ScriptFolder.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Stylesheet/Stylesheet.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Stylesheet/StylesheetFolder.spec.ts diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Script/Script.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Script/Script.spec.ts new file mode 100644 index 0000000000..4b687a0d45 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Script/Script.spec.ts @@ -0,0 +1,51 @@ +import {test} from '@umbraco/playwright-testhelpers'; +import {expect} from "@playwright/test"; + +test.describe('Script tests', () => { + const scriptName = 'scriptName.js'; + + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.script.ensureScriptNotNameNotExistsAtRoot(scriptName); + }); + + test.afterEach(async ({page, umbracoApi}) => { + await umbracoApi.script.ensureScriptNotNameNotExistsAtRoot(scriptName); + }); + + test('can create a script', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.script.createScript(scriptName, 'test'); + + // Assert + await expect(await umbracoApi.script.doesScriptWithNameExistAtRoot(scriptName)).toBeTruthy(); + }); + + test('can update a script', async ({page, umbracoApi, umbracoUi}) => { + const newContent = 'Howdy'; + + await umbracoApi.script.createScript(scriptName, 'test'); + + const script = await umbracoApi.script.getScriptByNameAtRoot(scriptName); + + script.content = newContent; + + await umbracoApi.script.updateScript(script); + + // Assert + // Checks if the content was updated for the script + const updatedScript = await umbracoApi.script.getScriptByPath(script.path); + await expect(updatedScript.content === newContent).toBeTruthy(); + }); + + test('can delete a script', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.script.createScript(scriptName, 'test'); + + await expect(await umbracoApi.script.doesScriptWithNameExistAtRoot(scriptName)).toBeTruthy(); + + const script = await umbracoApi.script.getScriptByNameAtRoot(scriptName); + + await umbracoApi.script.deleteScriptByPath(script.path); + + // Assert + await expect(await umbracoApi.script.doesScriptWithNameExistAtRoot(scriptName)).toBeFalsy(); + }); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Script/ScriptFolder.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Script/ScriptFolder.spec.ts new file mode 100644 index 0000000000..9fc9b2f78f --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Script/ScriptFolder.spec.ts @@ -0,0 +1,69 @@ +import {test} from '@umbraco/playwright-testhelpers'; +import {expect} from "@playwright/test"; + +test.describe('Script Folder tests', () => { + const scriptFolderName = 'scriptFolder'; + + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.script.ensureScriptNotNameNotExistsAtRoot(scriptFolderName); + }); + + test.afterEach(async ({page, umbracoApi}) => { + await umbracoApi.script.ensureScriptNotNameNotExistsAtRoot(scriptFolderName); + }); + + test('can create script folder', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.script.createScriptFolder(scriptFolderName); + + // Assert + await expect(umbracoApi.script.doesScriptWithNameExistAtRoot(scriptFolderName)).toBeTruthy(); + }); + + test('can delete script folder', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.script.createScriptFolder(scriptFolderName); + + await expect(await umbracoApi.script.doesScriptWithNameExistAtRoot(scriptFolderName)).toBeTruthy(); + const scriptFolder = await umbracoApi.script.getScriptByNameAtRoot(scriptFolderName); + + await umbracoApi.script.deleteScriptFolder(scriptFolder.path); + + // Assert + await expect(await umbracoApi.script.doesScriptWithNameExistAtRoot(scriptFolderName)).toBeFalsy(); + }); + + test('can add a script folder in another folder', async ({page, umbracoApi, umbracoUi}) => { + const childFolderName = 'childFolder'; + await umbracoApi.script.createScriptFolder(scriptFolderName); + + const parentFolder = await umbracoApi.script.getScriptByNameAtRoot(scriptFolderName); + + await umbracoApi.script.createScriptFolder(childFolderName, parentFolder.path); + + const children = await umbracoApi.script.getChildrenInScriptFolderByPath(parentFolder.path); + + // Assert + await expect(children.items[0].name === childFolderName).toBeTruthy(); + }); + + test('can add a script folder in a folder in another folder', async ({page, umbracoApi, umbracoUi}) => { + const childFolderName = 'childFolder'; + const childOfChildFolderName = 'childOfChildFolder'; + + // Creates parent folder + await umbracoApi.script.createScriptFolder(scriptFolderName); + const parentFolder = await umbracoApi.script.getScriptByNameAtRoot(scriptFolderName); + + // Creates child folder in parent folder + await umbracoApi.script.createScriptFolder(childFolderName, parentFolder.path); + const childOfParent = await umbracoApi.script.getChildrenInScriptFolderByPath(parentFolder.path); + + // Creates childOfChild folder in child folder + await umbracoApi.script.createScriptFolder(childOfChildFolderName, childOfParent.items[0].path); + const childOfChild = await umbracoApi.script.getChildrenInScriptFolderByPath(childOfParent.items[0].path); + + // Assert + // Checks if the script folder are in the correct folders + await expect(childOfParent.items[0].name === childFolderName).toBeTruthy(); + await expect(childOfChild.items[0].name === childOfChildFolderName).toBeTruthy(); + }); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Stylesheet/Stylesheet.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Stylesheet/Stylesheet.spec.ts new file mode 100644 index 0000000000..624940a370 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Stylesheet/Stylesheet.spec.ts @@ -0,0 +1,96 @@ +import {test} from '@umbraco/playwright-testhelpers'; +import {expect} from "@playwright/test"; + +test.describe('Stylesheet tests', () => { + const stylesheetName = 'Stylesheet.css'; + + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.stylesheet.ensureStylesheetNameNotExistsAtRoot(stylesheetName); + }); + + test.afterEach(async ({page, umbracoApi}) => { + await umbracoApi.stylesheet.ensureStylesheetNameNotExistsAtRoot(stylesheetName); + }); + + test('can create a stylesheet', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.stylesheet.createStylesheet(stylesheetName, 'content'); + + // Assert + await expect(await umbracoApi.stylesheet.doesStylesheetWithNameExistAtRoot(stylesheetName)).toBeTruthy(); + }); + + test('can update a stylesheet', async ({page, umbracoApi, umbracoUi}) => { + const newContent = 'BetterContent'; + + await umbracoApi.stylesheet.createStylesheet(stylesheetName, 'content'); + + const stylesheet = await umbracoApi.stylesheet.getStylesheetByNameAtRoot(stylesheetName); + + stylesheet.content = newContent; + + await umbracoApi.stylesheet.updateStylesheet(stylesheet); + + // Assert + // Checks if the content was updated for the stylesheet + const updatedStylesheet = await umbracoApi.stylesheet.getStylesheetByPath(stylesheet.path); + await expect(updatedStylesheet.content === newContent).toBeTruthy(); + }); + + test('can delete a stylesheet', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.stylesheet.createStylesheet(stylesheetName, 'content'); + + await expect(await umbracoApi.stylesheet.doesStylesheetWithNameExistAtRoot(stylesheetName)).toBeTruthy(); + + const stylesheet = await umbracoApi.stylesheet.getStylesheetByNameAtRoot(stylesheetName); + + await umbracoApi.stylesheet.deleteStylesheetByPath(stylesheet.path); + + // Assert + await expect(await umbracoApi.stylesheet.doesStylesheetWithNameExistAtRoot(stylesheetName)).toBeFalsy(); + }); + + test('can create a stylesheet in a folder', async ({page, umbracoApi, umbracoUi}) => { + const folderName = 'StyledFolder'; + + await umbracoApi.stylesheet.ensureStylesheetNameNotExistsAtRoot(folderName); + + await umbracoApi.stylesheet.createStylesheetFolder(folderName); + + const folder = await umbracoApi.stylesheet.getStylesheetByNameAtRoot(folderName); + + await umbracoApi.stylesheet.createStylesheet(stylesheetName, 'content', folder.path); + + // Assert + const child = await umbracoApi.stylesheet.getChildrenInStylesheetFolderByPath(folder.path); + await expect(child.items[0].name === stylesheetName).toBeTruthy(); + + // Clean + await umbracoApi.stylesheet.ensureStylesheetNameNotExistsAtRoot(folderName); + }); + + test('can delete a stylesheet from a folder', async ({page, umbracoApi, umbracoUi}) => { + const folderName = 'StyledFolder'; + + await umbracoApi.stylesheet.ensureStylesheetNameNotExistsAtRoot(folderName); + + await umbracoApi.stylesheet.createStylesheetFolder(folderName); + + const folder = await umbracoApi.stylesheet.getStylesheetByNameAtRoot(folderName); + + await umbracoApi.stylesheet.createStylesheet(stylesheetName, 'deleteMe', folder.path); + + // Checks if the stylesheet was created + const child = await umbracoApi.stylesheet.getChildrenInStylesheetFolderByPath(folder.path); + + await expect(child.items[0].name === stylesheetName).toBeTruthy(); + + await umbracoApi.stylesheet.deleteStylesheetByPath(child.items[0].path); + + // Assert + const noChild = await umbracoApi.stylesheet.getChildrenInStylesheetFolderByPath(folder.path); + await expect(noChild.items[0] === undefined).toBeTruthy(); + + // Clean + await umbracoApi.stylesheet.ensureStylesheetNameNotExistsAtRoot(folderName); + }); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Stylesheet/StylesheetFolder.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Stylesheet/StylesheetFolder.spec.ts new file mode 100644 index 0000000000..1bab495876 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Stylesheet/StylesheetFolder.spec.ts @@ -0,0 +1,96 @@ +import {test} from '@umbraco/playwright-testhelpers'; +import {expect} from "@playwright/test"; + +test.describe('Stylesheet Folder tests', () => { + const stylesheetFolderName = 'StylesheetFolder'; + + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.stylesheet.ensureStylesheetNameNotExistsAtRoot(stylesheetFolderName); + }); + + test.afterEach(async ({page, umbracoApi}) => { + await umbracoApi.stylesheet.ensureStylesheetNameNotExistsAtRoot(stylesheetFolderName); + }); + + test('can create stylesheet folder', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.stylesheet.createStylesheetFolder(stylesheetFolderName); + + // Assert + await expect(await umbracoApi.stylesheet.doesStylesheetWithNameExistAtRoot(stylesheetFolderName)).toBeTruthy(); + }); + + test('can delete stylesheet folder', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.stylesheet.createStylesheetFolder(stylesheetFolderName); + + await expect(await umbracoApi.stylesheet.doesStylesheetWithNameExistAtRoot(stylesheetFolderName)).toBeTruthy(); + + const stylesheet = await umbracoApi.stylesheet.getStylesheetByNameAtRoot(stylesheetFolderName); + + await umbracoApi.stylesheet.deleteStylesheetFolder(stylesheet.path); + + // Assert + await expect(await umbracoApi.stylesheet.doesStylesheetWithNameExistAtRoot(stylesheetFolderName)).toBeFalsy(); + }); + + test('can add a stylesheet folder in another folder', async ({page, umbracoApi, umbracoUi}) => { + const childFolderName = 'childFolder'; + await umbracoApi.stylesheet.createStylesheetFolder(stylesheetFolderName); + + const parentFolder = await umbracoApi.stylesheet.getStylesheetByNameAtRoot(stylesheetFolderName); + + await umbracoApi.stylesheet.createStylesheetFolder(childFolderName, parentFolder.path); + + const children = await umbracoApi.stylesheet.getChildrenInStylesheetFolderByPath(parentFolder.path); + + // Assert + await expect(children.items[0].name === childFolderName).toBeTruthy(); + }); + + test('can add a stylesheet folder in a folder that is in another folder', async ({page, umbracoApi, umbracoUi}) => { + const childFolderName = 'childFolder'; + const childOfChildFolderName = 'childOfChildFolder'; + + // Creates parent folder + await umbracoApi.stylesheet.createStylesheetFolder(stylesheetFolderName); + + const parentFolder = await umbracoApi.stylesheet.getStylesheetByNameAtRoot(stylesheetFolderName); + + // Creates child folder in parent folder + await umbracoApi.stylesheet.createStylesheetFolder(childFolderName, parentFolder.path); + + const childOfParent = await umbracoApi.stylesheet.getChildrenInStylesheetFolderByPath(parentFolder.path); + + // Creates childOfChild folder in child folder + await umbracoApi.stylesheet.createStylesheetFolder(childOfChildFolderName, childOfParent.items[0].path); + + const childOfChild = await umbracoApi.stylesheet.getChildrenInStylesheetFolderByPath(childOfParent.items[0].path); + + // Assert + // Checks if the stylesheet folder are in the correct folders + await expect(childOfParent.items[0].name === childFolderName).toBeTruthy(); + await expect(childOfChild.items[0].name === childOfChildFolderName).toBeTruthy(); + }); + + test('can delete a stylesheet folder from another folder', async ({page, umbracoApi, umbracoUi}) => { + const childFolderName = 'childFolder'; + + await umbracoApi.stylesheet.createStylesheetFolder(stylesheetFolderName); + + const parentFolder = await umbracoApi.stylesheet.getStylesheetByNameAtRoot(stylesheetFolderName); + + await umbracoApi.stylesheet.createStylesheetFolder(childFolderName, parentFolder.path); + + const child = await umbracoApi.stylesheet.getChildrenInStylesheetFolderByPath(parentFolder.path); + + await expect(child.items[0].name === childFolderName).toBeTruthy(); + + await umbracoApi.stylesheet.doesStylesheetWithPathExist(child.items[0].path); + + await umbracoApi.stylesheet.deleteStylesheetFolder(child.items[0].path); + + const noChild = await umbracoApi.stylesheet.getChildrenInStylesheetFolderByPath(parentFolder.path); + + // Assert + await expect(noChild.items[0] === undefined).toBeTruthy(); + }); +});