test(sync): make first e2e test work

This commit is contained in:
Johannes Millan 2025-07-18 13:52:09 +02:00
parent 3958b39f13
commit 6858ce3c91
5 changed files with 43 additions and 89 deletions

View file

@ -1,59 +1,38 @@
// eslint-disable-next-line @typescript-eslint/no-namespace
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NightwatchCustomCommands {
interface Commands {
setupWebdavSync(
config: {
baseUrl: string;
username: string;
password: string;
syncFolderPath: string;
},
callback?: () => void,
): this;
}
}
}
import { NBrowser } from '../n-browser-interface';
module.exports = {
command: function setupWebdavSync(
this: any,
command(
this: NBrowser,
config: {
baseUrl: string;
username: string;
password: string;
syncFolderPath: string;
},
callback?: () => void,
) {
this.url('http://localhost:4200/config')
.waitForElementVisible('body', 5000)
.pause(500)
// Navigate to sync settings
.click('a[href="/config/sync"]')
.waitForElementVisible('[data-cy="sync-provider-webdav"]', 5000)
// Select WebDAV provider
.click('[data-cy="sync-provider-webdav"]')
.pause(500)
// Fill in WebDAV configuration
.waitForElementVisible('input[ng-reflect-name="baseUrl"]', 2000)
.clearValue('input[ng-reflect-name="baseUrl"]')
.setValue('input[ng-reflect-name="baseUrl"]', config.baseUrl)
.clearValue('input[ng-reflect-name="userName"]')
.setValue('input[ng-reflect-name="userName"]', config.username)
.clearValue('input[ng-reflect-name="password"]')
.setValue('input[ng-reflect-name="password"]', config.password)
.clearValue('input[ng-reflect-name="syncFolderPath"]')
.setValue('input[ng-reflect-name="syncFolderPath"]', config.syncFolderPath)
// Save configuration
.click('button[type="submit"]')
.pause(1000);
// CSSSelektoren zentral definieren
const sel = {
syncBtn: 'button.sync-btn',
providerSelect: 'formly-field-mat-select mat-select',
providerOptionWebDAV: '#mat-option-3', // Eintrag „WebDAV“
baseUrlInput: '.e2e-baseUrl input',
userNameInput: '.e2e-userName input',
passwordInput: '.e2e-password input',
saveBtn: 'mat-dialog-actions button[mat-stroked-button]',
};
if (callback) {
callback.call(this);
}
return this.click(sel.syncBtn)
.waitForElementVisible(sel.providerSelect)
.pause(100)
.click(sel.providerSelect)
.click(sel.providerOptionWebDAV)
.pause(100)
return this;
.setValue(sel.baseUrlInput, 'http://localhost:2345')
.setValue(sel.userNameInput, 'alice')
.setValue(sel.passwordInput, 'alice')
.pause(100)
.click(sel.saveBtn);
},
};

View file

@ -1,27 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-namespace
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NightwatchCustomCommands {
interface Commands {
triggerSync(callback?: () => void): this;
}
}
}
import { NBrowser } from '../n-browser-interface';
module.exports = {
command: function triggerSync(this: any, callback?: () => void) {
this.url('http://localhost:4200/work-view')
.waitForElementVisible('body', 5000)
.pause(500)
// Find and click sync button
.waitForElementVisible('.sync-btn', 3000)
.click('.sync-btn')
.pause(2000); // Allow time for sync to complete
if (callback) {
callback.call(this);
}
return this;
command: function triggerSync(this: NBrowser) {
return this.waitForElementVisible('.sync-btn', 3000).click('.sync-btn').pause(1000); // Allow time for sync to complete
},
};

View file

@ -20,4 +20,11 @@ export interface NBrowser extends NightwatchAPI {
navigateToPluginSettings: () => NBrowser;
checkPluginStatus: (pluginName: string, expectedEnabled?: boolean) => NBrowser;
enableTestPlugin: (pluginName?: string) => NBrowser;
setupWebdavSync: (config: {
baseUrl: string;
username: string;
password: string;
syncFolderPath: string;
}) => NBrowser;
triggerSync: () => NBrowser;
}

View file

@ -9,11 +9,12 @@ module.exports = {
browser: NBrowser,
) => {
await browser
.navigateTo('http://localhost:4200')
// Configure WebDAV sync
.setupWebdavSync({
baseUrl: 'http://localhost:8080/',
baseUrl: 'http://localhost:2345/',
username: 'alice',
password: 'alicepassword',
password: 'alice',
syncFolderPath: '/super-productivity-test',
})
// Create a test task
@ -23,24 +24,8 @@ module.exports = {
.triggerSync()
// Verify sync completed
.pause(3000)
.noError()
.assert.not.elementPresent('.sync-btn mat-icon.spin')
// Log sync state for debugging
.execute(
() => {
const syncBtn = document.querySelector('.sync-btn');
const icon = syncBtn?.querySelector('mat-icon');
return {
iconText: icon?.textContent?.trim(),
hasSyncBtn: !!syncBtn,
syncBtnText: syncBtn?.textContent?.trim(),
};
},
[],
(result) => {
console.log('WebDAV sync state:', result.value);
const state = result.value as any;
browser.assert.ok(state.hasSyncBtn, 'Sync button should exist');
},
);
.end();
},
};

View file

@ -98,6 +98,7 @@ export const SYNC_FORM: ConfigFormSection<SyncConfig> = {
{
key: 'baseUrl',
type: 'input',
className: 'e2e-baseUrl',
templateOptions: {
required: true,
label: T.F.SYNC.FORM.WEB_DAV.L_BASE_URL,
@ -108,6 +109,7 @@ export const SYNC_FORM: ConfigFormSection<SyncConfig> = {
{
key: 'userName',
type: 'input',
className: 'e2e-userName',
templateOptions: {
required: true,
label: T.F.SYNC.FORM.WEB_DAV.L_USER_NAME,
@ -116,6 +118,7 @@ export const SYNC_FORM: ConfigFormSection<SyncConfig> = {
{
key: 'password',
type: 'input',
className: 'e2e-password',
templateOptions: {
type: 'password',
required: true,