From fbc8d453e340e11ec2afc0d0fdf2b419081e1938 Mon Sep 17 00:00:00 2001 From: Andreas Zerbst <73799582+andr317c@users.noreply.github.com> Date: Mon, 26 Jun 2023 12:21:09 +0200 Subject: [PATCH] Added acceptance tests for testing the API for the Dictionary section. (#14446) * 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. * Added acceptance tests for testing the API for the User section * Bumped the version of our testhelpers! * Added acceptance tests for testing the API for the Dictionary section. --- .../ApiTesting/Dictionary/Dictionary.spec.ts | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Dictionary/Dictionary.spec.ts diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Dictionary/Dictionary.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Dictionary/Dictionary.spec.ts new file mode 100644 index 0000000000..99815b7183 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Dictionary/Dictionary.spec.ts @@ -0,0 +1,83 @@ +import {test} from '@umbraco/playwright-testhelpers'; +import {expect} from "@playwright/test"; + +test.describe('Dictionary tests', () => { + const dictionaryName = 'Word' + + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.dictionary.ensureDictionaryNameNotExists(dictionaryName); + }); + + test.afterEach(async ({page, umbracoApi}) => { + await umbracoApi.dictionary.ensureDictionaryNameNotExists(dictionaryName); + }) + + test('can create a dictionary', async ({page, umbracoApi, umbracoUi}) => { + const translationData = [ + { + 'isoCode': 'en-US', + 'translation': 'Word' + }, + { + 'isoCode': 'da-DK', + 'translation': 'Ord' + } + ]; + + await umbracoApi.dictionary.createDictionary(dictionaryName, translationData); + + // Assert + await expect(umbracoApi.dictionary.doesDictionaryWithNameExists(dictionaryName)).toBeTruthy(); + }); + + test('can update a dictionary', async ({page, umbracoApi, umbracoUi}) => { + const oldDictionaryName = 'OldWord'; + + await umbracoApi.dictionary.createDictionary(oldDictionaryName); + + const dictionary = await umbracoApi.dictionary.getDictionaryByName(oldDictionaryName); + + // Updates the dictionary name + dictionary.name = dictionaryName; + await umbracoApi.dictionary.updateDictionaryById(dictionary.id, dictionary); + + // Assert + // Checks if the dictionary was updated + const newDictionary = await umbracoApi.dictionary.getDictionaryById(dictionary.id); + await expect(newDictionary.name == dictionaryName).toBeTruthy(); + + await expect(umbracoApi.dictionary.doesDictionaryWithNameExists(dictionaryName)).toBeTruthy(); + }); + + test('can delete a dictionary', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.dictionary.createDictionary(dictionaryName); + + await expect(umbracoApi.dictionary.doesDictionaryWithNameExists(dictionaryName)).toBeTruthy(); + + await umbracoApi.dictionary.deleteDictionaryByName(dictionaryName); + + // Assert + await expect(await umbracoApi.dictionary.doesDictionaryWithNameExists(dictionaryName)).toBeFalsy(); + }); + + test('can create a dictionary item in a dictionary', async ({page, umbracoApi, umbracoUi}) => { + const parentDictionaryName = 'Book'; + + await umbracoApi.dictionary.ensureDictionaryNameNotExists(parentDictionaryName); + + await umbracoApi.dictionary.createDictionary(parentDictionaryName); + + const parentDictionary = await umbracoApi.dictionary.getDictionaryByName(parentDictionaryName); + + await umbracoApi.dictionary.createDictionary(dictionaryName, [], parentDictionary.id); + + const dictionaryChildren = await umbracoApi.dictionary.getDictionaryChildrenById(parentDictionary.id); + + // Assert + // Checks if the parent dictionary contains the child dictionary + await expect(dictionaryChildren.items[0].name == dictionaryName).toBeTruthy(); + + // Clean + await umbracoApi.dictionary.ensureDictionaryNameNotExists(parentDictionaryName); + }); +});