TagSpaces is an offline, open source, document manager with tagging support
chore: added e2e tests for the templating functionality
Ilian Sapundshievd093ad018946
diff --git a/capacitor/ios/App/App.xcodeproj/project.pbxproj b/capacitor/ios/App/App.xcodeproj/project.pbxprojindex 88ecdf020..372ad108e 100644--- a/capacitor/ios/App/App.xcodeproj/project.pbxproj+++ b/capacitor/ios/App/App.xcodeproj/project.pbxproj@@ -319,7 +319,7 @@CODE_SIGN_ENTITLEMENTS = App/App.entitlements;CODE_SIGN_IDENTITY = "Apple Development";CODE_SIGN_STYLE = Automatic;- CURRENT_PROJECT_VERSION = 10332;+ CURRENT_PROJECT_VERSION = 10333;DEVELOPMENT_TEAM = DLK22E2679;INFOPLIST_FILE = App/Info.plist;IPHONEOS_DEPLOYMENT_TARGET = 15.0;@@ -345,7 +345,7 @@CODE_SIGN_ENTITLEMENTS = App/App.entitlements;CODE_SIGN_IDENTITY = "Apple Development";CODE_SIGN_STYLE = Automatic;- CURRENT_PROJECT_VERSION = 10332;+ CURRENT_PROJECT_VERSION = 10333;DEVELOPMENT_TEAM = DLK22E2679;INFOPLIST_FILE = App/Info.plist;IPHONEOS_DEPLOYMENT_TARGET = 15.0;diff --git a/src/renderer/components/dialogs/components/CreateFile.tsx b/src/renderer/components/dialogs/components/CreateFile.tsxindex b96f4e7ae..60494f36a 100644--- a/src/renderer/components/dialogs/components/CreateFile.tsx+++ b/src/renderer/components/dialogs/components/CreateFile.tsx@@ -111,17 +111,6 @@ function CreateFile(props: Props) {return tid;}- // Stable test-id fragment per template type, e.g. selectMarkdownTemplateTID.- function templateTidType(type?: TS.FileType) {- if (type === 'md') {- return 'Markdown';- }- if (type === 'html') {- return 'Html';- }- return 'Text';- }-const onInputFocus = (event) => {setTimeout(() => {if (fileName) {@@ -214,7 +203,7 @@ function CreateFile(props: Props) {<CardActionAreadisabled={noSuitableLocation}onClick={() => onSelectTemplate?.(template)}- data-tid={`select${templateTidType(template.type)}TemplateTID`}+ data-tid={`newFileTemplateTile_${template.id}`}><CardContent><Boxdiff --git a/src/renderer/components/dialogs/components/SettingsTemplates.tsx b/src/renderer/components/dialogs/components/SettingsTemplates.tsxindex 93c2a23c4..5d84c1457 100644--- a/src/renderer/components/dialogs/components/SettingsTemplates.tsx+++ b/src/renderer/components/dialogs/components/SettingsTemplates.tsx@@ -187,6 +187,7 @@ function SettingsTemplates(props: Props) {file will get an unique name.</Typography><TsButton+ data-tid="addTemplateTID"disabled={!!AppConfig.ExtFileTemplates}onClick={() => {saveTemplate();@@ -197,6 +198,7 @@ function SettingsTemplates(props: Props) {{t('addTemplate')}</TsButton><TsButton+ data-tid="resetTemplatesTID"disabled={!!AppConfig.ExtFileTemplates}variant="text"onClick={() => {@@ -291,7 +293,7 @@ function SettingsTemplates(props: Props) {editedTemplate.current.fileNameTmpl && (<TsButtonsize="small"- data-tid={'save' + template.id + 'TID'}+ data-tid="saveTemplateTID"onClick={() => saveTemplate(template.id)}>{t('core:save')}diff --git a/src/renderer/components/dialogs/components/TemplatesDropDown.tsx b/src/renderer/components/dialogs/components/TemplatesDropDown.tsxindex 31b9647c9..877e0cac2 100644--- a/src/renderer/components/dialogs/components/TemplatesDropDown.tsx+++ b/src/renderer/components/dialogs/components/TemplatesDropDown.tsx@@ -64,12 +64,13 @@ function TemplatesDropDown(props: Props) {fileTemplatesContext?.setTemplateActive(event.target.value)}>- {templates.map((tp, index) => (- <MenuItem value={tp.id}>- {- tp.name- // + (index === 0 ? ' (' + t('core:defaultTemplate') + ')' : '')- }+ {templates.map((tp) => (+ <MenuItem+ key={tp.id}+ value={tp.id}+ data-tid={`templateOption_${tp.id}`}+ >+ {tp.name}</MenuItem>))}</TsSelect>diff --git a/tests/e2e/template.pw.e2e.js b/tests/e2e/template.pw.e2e.jsnew file mode 100644index 000000000..448f8635b--- /dev/null+++ b/tests/e2e/template.pw.e2e.js@@ -0,0 +1,229 @@+/*+ * Copyright (c) 2016-present - TagSpaces GmbH. All rights reserved.+ */+import { test, expect } from './fixtures';+import {+ defaultLocationName,+ createPwLocation,+ createS3Location,+} from './location.helpers';+import {+ createNewDirectory,+ openFolder,+ deleteDirectory,+ closeOpenedFile,+ clickOn,+ expectElementExist,+ expectFileContain,+ getGridFileSelector,+ setInputValue,+ waitForNotification,+} from './general.helpers';+import { startTestingApp, stopApp } from './hook';+import { clearDataStorage, closeWelcomePlaywright } from './welcome.helpers';+import { clickOnMenuOperation } from './test-utils';++const testFolder = 'templateTestFolder';++test.beforeAll(async ({ isWeb, isS3, webServerPort }, testInfo) => {+ if (isS3) {+ await startTestingApp({ isWeb, isS3, webServerPort, testInfo });+ await closeWelcomePlaywright();+ } else {+ await startTestingApp(+ { isWeb, isS3, webServerPort, testInfo },+ 'extconfig.js',+ );+ }+});++test.afterAll(async () => {+ await stopApp();+});++test.afterEach(async () => {+ await clearDataStorage();+});++test.beforeEach(async ({ isS3, testDataDir }) => {+ if (isS3) {+ await closeWelcomePlaywright();+ await createS3Location('', defaultLocationName, true);+ } else {+ await createPwLocation(testDataDir, defaultLocationName, true);+ }+ await clickOn('[data-tid=location_' + defaultLocationName + ']');+ await expectElementExist(getGridFileSelector('empty_folder'), true, 15000);+});++/**+ * Opens the "Create new file from template" dialog (tile grid phase).+ * Assumes a folder is already open in the grid perspective.+ */+async function openTemplateGrid() {+ await clickOn('[data-tid=folderContainerOpenDirMenu]');+ await clickOnMenuOperation('createNewFromTemplateTID');+ await expectElementExist('[data-tid=newFileDialog]', true, 5000);+}++test.describe('TST74 - File templates', () => {+ test('TST7401 - Create file by picking a template tile [electron,_pro]', async () => {+ await createNewDirectory(testFolder);+ await openFolder(testFolder);++ await openTemplateGrid();++ // The tile grid is shown with a tile per template ...+ await expectElementExist(+ '[data-tid=newFileTemplateTile_templateMd]',+ true,+ 5000,+ );+ // ... and the old per-tile "Use this template" button is gone (redesign).+ await expectElementExist('[data-tid=createMarkdownButton]', false, 2000);+ // At this stage there is no editable form / OK button yet.+ await expectElementExist('[data-tid=newEntryDialogInputTID]', false, 2000);++ // Clicking a tile loads the template into the editable form.+ await clickOn('[data-tid=newFileTemplateTile_templateMd]');+ await expectElementExist('[data-tid=newEntryDialogInputTID]', true, 5000);++ // The name field is prefilled from the template.+ const prefilledName = await global.client+ .locator('[data-tid=newEntryDialogInputTID] input')+ .inputValue();+ expect(prefilledName.length).toBeGreaterThan(0);++ // Edit the (now editable) title + content before creating.+ await setInputValue(+ '[data-tid=newEntryDialogInputTID] input',+ 'templatetest',+ );+ await setInputValue('#fileContentID', 'TEMPLATEBODY123');++ await clickOn('[data-tid=createTID]');+ await waitForNotification();++ // The created file contains the edited content and uses the edited name.+ await expectFileContain('TEMPLATEBODY123', 10000);+ await closeOpenedFile();+ await expectElementExist(+ getGridFileSelector('templatetest.md'),+ true,+ 10000,+ );++ await deleteDirectory(testFolder);+ });++ test('TST7402 - Back navigates from the editable form to the tile grid [electron,_pro]', async () => {+ await createNewDirectory(testFolder);+ await openFolder(testFolder);++ await openTemplateGrid();+ await clickOn('[data-tid=newFileTemplateTile_templateMd]');+ // Editable form is shown.+ await expectElementExist('[data-tid=newEntryDialogInputTID]', true, 5000);++ // Going back returns to the tile grid ...+ await clickOn('[data-tid=backToTemplatesTID]');+ await expectElementExist(+ '[data-tid=newFileTemplateTile_templateMd]',+ true,+ 5000,+ );+ // ... and the editable form is hidden again.+ await expectElementExist('[data-tid=newEntryDialogInputTID]', false, 2000);++ await clickOn('[data-tid=closeNewFileDialogTID]');+ await deleteDirectory(testFolder);+ });++ test('TST7403 - Changing the template via the dropdown reloads the editable content [electron,_pro]', async () => {+ await createNewDirectory(testFolder);+ await openFolder(testFolder);++ await openTemplateGrid();+ // Start from the plain Markdown template.+ await clickOn('[data-tid=newFileTemplateTile_templateMd]');+ await expectElementExist('[data-tid=newEntryDialogInputTID]', true, 5000);++ // Switch to the "Idea" template via the in-form dropdown. The dropdown tid+ // is reused by the Settings dialog, so scope it to the new-file dialog.+ await clickOn(+ '[data-tid=newFileDialog] [data-tid=tagDelimiterTID] [role="combobox"]',+ );+ await clickOn('[data-tid=templateOption_templateIdea]');++ // The editable content + title update to reflect the newly chosen template.+ await expect+ .poll(+ async () =>+ global.client.locator('#fileContentID').inputValue(),+ { timeout: 5000, message: 'content should switch to the Idea template' },+ )+ .toContain('Idea');++ const nameAfter = await global.client+ .locator('[data-tid=newEntryDialogInputTID] input')+ .inputValue();+ expect(nameAfter).toContain('idea');++ await clickOn('[data-tid=closeNewFileDialogTID]');+ await deleteDirectory(testFolder);+ });++ test('TST7410 - Manage templates: add and reset reflects in the create dialog [electron,_pro]', async () => {+ await createNewDirectory(testFolder);+ await openFolder(testFolder);++ // Baseline: number of template tiles in the create-from-template grid.+ // The tile prefix is unique to templates, so counting tiles is the most+ // reliable way to track how many templates exist.+ const tilesSelector = '[data-tid^="newFileTemplateTile_"]';+ await openTemplateGrid();+ await expectElementExist(+ '[data-tid=newFileTemplateTile_templateMd]',+ true,+ 5000,+ );+ const baseTiles = await global.client.locator(tilesSelector).count();+ expect(baseTiles).toBeGreaterThan(0);+ await clickOn('[data-tid=closeNewFileDialogTID]');++ // Open the templates management (Settings -> Templates) and add one.+ await clickOn('[data-tid=settings]');+ await clickOn('[data-tid=templatesDialogTID]');+ await expectElementExist('[data-tid=templateMdTemplateTID]', true, 5000);+ await clickOn('[data-tid=addTemplateTID]');+ await clickOn('[data-tid=saveTemplateTID]');+ await clickOn('[data-tid=closeSettingsDialog]');++ // The newly added template shows up as an extra tile in the create dialog.+ await openTemplateGrid();+ await expect+ .poll(async () => global.client.locator(tilesSelector).count(), {+ timeout: 5000,+ message: 'the added template should appear as a new tile',+ })+ .toBe(baseTiles + 1);+ await clickOn('[data-tid=closeNewFileDialogTID]');++ // Reset templates back to the defaults (also restores clean state).+ await clickOn('[data-tid=settings]');+ await clickOn('[data-tid=templatesDialogTID]');+ await clickOn('[data-tid=resetTemplatesTID]');+ await clickOn('[data-tid=closeSettingsDialog]');++ await openTemplateGrid();+ await expect+ .poll(async () => global.client.locator(tilesSelector).count(), {+ timeout: 5000,+ message: 'reset should restore the default template count',+ })+ .toBe(baseTiles);+ await clickOn('[data-tid=closeNewFileDialogTID]');++ await deleteDirectory(testFolder);+ });+});