2024-08-31 17:05:01 +02:00
|
|
|
import activateMainMenuItem from '../util/activateMainMenuItem';
|
|
|
|
import { ElectronApplication, Locator, Page, expect } from '@playwright/test';
|
|
|
|
|
|
|
|
export default class NoteList {
|
|
|
|
public readonly container: Locator;
|
2024-09-04 13:14:12 +02:00
|
|
|
public readonly sortOrderButton: Locator;
|
2024-08-31 17:05:01 +02:00
|
|
|
|
|
|
|
public constructor(page: Page) {
|
|
|
|
this.container = page.locator('.rli-noteList');
|
2024-09-04 13:14:12 +02:00
|
|
|
this.sortOrderButton = this.container.getByRole('button', { name: 'Toggle sort order' });
|
2024-08-31 17:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public waitFor() {
|
|
|
|
return this.container.waitFor();
|
|
|
|
}
|
|
|
|
|
|
|
|
private async sortBy(electronApp: ElectronApplication, sortMethod: string) {
|
2024-09-04 13:14:12 +02:00
|
|
|
await activateMainMenuItem(electronApp, sortMethod, 'Sort notes by');
|
2024-08-31 17:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async sortByTitle(electronApp: ElectronApplication) {
|
2024-09-04 13:14:12 +02:00
|
|
|
await this.sortBy(electronApp, 'Title');
|
|
|
|
await expect(this.sortOrderButton).toHaveAttribute('title', /Toggle sort order field:[\n ]*title ->/);
|
2024-08-31 17:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async focusContent(electronApp: ElectronApplication) {
|
|
|
|
await activateMainMenuItem(electronApp, 'Note list', 'Focus');
|
|
|
|
}
|
|
|
|
|
|
|
|
// The resultant locator may fail to resolve if the item is not visible
|
|
|
|
public getNoteItemByTitle(title: string|RegExp) {
|
|
|
|
return this.container.getByRole('option', { name: title });
|
|
|
|
}
|
|
|
|
|
|
|
|
public async expectNoteToBeSelected(title: string|RegExp) {
|
|
|
|
await expect(this.getNoteItemByTitle(title)).toHaveAttribute('aria-selected', 'true');
|
|
|
|
}
|
|
|
|
}
|