2023-12-11 15:58:45 +02:00
|
|
|
import { Page, Locator, ElectronApplication } from '@playwright/test';
|
2023-10-13 16:32:10 +02:00
|
|
|
import NoteEditorScreen from './NoteEditorScreen';
|
2023-12-11 15:58:45 +02:00
|
|
|
import activateMainMenuItem from '../util/activateMainMenuItem';
|
2024-04-25 16:31:18 +02:00
|
|
|
import Sidebar from './Sidebar';
|
2024-07-31 15:10:58 +02:00
|
|
|
import GoToAnything from './GoToAnything';
|
2024-08-02 15:47:43 +02:00
|
|
|
import setFilePickerResponse from '../util/setFilePickerResponse';
|
2024-08-31 17:05:01 +02:00
|
|
|
import NoteList from './NoteList';
|
2024-11-08 17:32:05 +02:00
|
|
|
import { expect } from '../util/test';
|
2023-10-13 16:32:10 +02:00
|
|
|
|
|
|
|
export default class MainScreen {
|
|
|
|
public readonly newNoteButton: Locator;
|
2024-08-31 17:05:01 +02:00
|
|
|
public readonly noteList: NoteList;
|
2024-04-25 16:31:18 +02:00
|
|
|
public readonly sidebar: Sidebar;
|
|
|
|
public readonly dialog: Locator;
|
2023-10-13 16:32:10 +02:00
|
|
|
public readonly noteEditor: NoteEditorScreen;
|
2024-07-31 15:10:58 +02:00
|
|
|
public readonly goToAnything: GoToAnything;
|
2023-10-13 16:32:10 +02:00
|
|
|
|
2023-12-06 21:17:16 +02:00
|
|
|
public constructor(private page: Page) {
|
2023-10-13 16:32:10 +02:00
|
|
|
this.newNoteButton = page.locator('.new-note-button');
|
2024-08-31 17:05:01 +02:00
|
|
|
this.noteList = new NoteList(page);
|
2024-04-25 16:31:18 +02:00
|
|
|
this.sidebar = new Sidebar(page, this);
|
2024-08-02 15:49:15 +02:00
|
|
|
this.dialog = page.locator('.dialog-modal-layer');
|
2023-10-13 16:32:10 +02:00
|
|
|
this.noteEditor = new NoteEditorScreen(page);
|
2024-07-31 15:10:58 +02:00
|
|
|
this.goToAnything = new GoToAnything(page, this);
|
2023-10-13 16:32:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async waitFor() {
|
|
|
|
await this.newNoteButton.waitFor();
|
2024-08-31 17:05:01 +02:00
|
|
|
await this.noteList.waitFor();
|
2023-10-13 16:32:10 +02:00
|
|
|
}
|
2023-12-06 21:17:16 +02:00
|
|
|
|
|
|
|
// Follows the steps a user would use to create a new note.
|
|
|
|
public async createNewNote(title: string) {
|
|
|
|
await this.waitFor();
|
|
|
|
|
2024-11-13 12:07:02 +02:00
|
|
|
// Create the new note. Retry this -- creating new notes can sometimes fail if done just after
|
|
|
|
// application startup.
|
|
|
|
await expect.poll(async () => {
|
|
|
|
await this.newNoteButton.click();
|
|
|
|
await expect(this.noteEditor.noteTitleInput).toHaveValue('', { timeout: 4_000 });
|
|
|
|
await expect(this.noteEditor.noteTitleInput).toHaveJSProperty('placeholder', 'Creating new note...', { timeout: 4_000 });
|
|
|
|
return true;
|
|
|
|
}, { timeout: 10_000 }).toBe(true);
|
2023-12-06 21:17:16 +02:00
|
|
|
|
|
|
|
// Fill the title
|
|
|
|
await this.noteEditor.noteTitleInput.click();
|
|
|
|
await this.noteEditor.noteTitleInput.fill(title);
|
|
|
|
|
|
|
|
return this.noteEditor;
|
|
|
|
}
|
2023-12-11 15:58:45 +02:00
|
|
|
|
|
|
|
public async openSettings(electronApp: ElectronApplication) {
|
|
|
|
// Check both labels so this works on MacOS
|
2024-09-04 13:14:12 +02:00
|
|
|
await activateMainMenuItem(electronApp, /^(Preferences\.\.\.|Options)$/);
|
2023-12-11 15:58:45 +02:00
|
|
|
}
|
2024-06-12 16:11:53 +02:00
|
|
|
|
|
|
|
public async search(text: string) {
|
|
|
|
const searchBar = this.page.getByPlaceholder('Search...');
|
|
|
|
await searchBar.fill(text);
|
|
|
|
}
|
2024-08-02 15:47:43 +02:00
|
|
|
|
|
|
|
public async importHtmlDirectory(electronApp: ElectronApplication, path: string) {
|
|
|
|
await setFilePickerResponse(electronApp, [path]);
|
2024-09-04 13:14:12 +02:00
|
|
|
await activateMainMenuItem(electronApp, 'HTML - HTML document (Directory)', 'Import');
|
2024-08-02 15:47:43 +02:00
|
|
|
}
|
2023-10-13 16:32:10 +02:00
|
|
|
}
|