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';
|
2023-10-13 16:32:10 +02:00
|
|
|
|
|
|
|
export default class MainScreen {
|
|
|
|
public readonly newNoteButton: Locator;
|
|
|
|
public readonly noteListContainer: Locator;
|
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;
|
|
|
|
|
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');
|
|
|
|
this.noteListContainer = page.locator('.rli-noteList');
|
2024-04-25 16:31:18 +02:00
|
|
|
this.sidebar = new Sidebar(page, this);
|
|
|
|
this.dialog = page.locator('.dialog-root');
|
2023-10-13 16:32:10 +02:00
|
|
|
this.noteEditor = new NoteEditorScreen(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async waitFor() {
|
|
|
|
await this.newNoteButton.waitFor();
|
|
|
|
await this.noteListContainer.waitFor();
|
|
|
|
}
|
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();
|
|
|
|
await this.newNoteButton.click();
|
|
|
|
await this.noteEditor.waitFor();
|
|
|
|
|
|
|
|
// Wait for the title input to have the correct placeholder
|
|
|
|
await this.page.locator('input[placeholder^="Creating new note"]').waitFor();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
const openedWithPreferences = await activateMainMenuItem(electronApp, 'Preferences...');
|
|
|
|
const openedWithOptions = await activateMainMenuItem(electronApp, 'Options');
|
|
|
|
|
|
|
|
if (!openedWithOptions && !openedWithPreferences) {
|
|
|
|
throw new Error('Unable to find settings menu item in application menus.');
|
|
|
|
}
|
|
|
|
}
|
2024-06-12 16:11:53 +02:00
|
|
|
|
|
|
|
public async search(text: string) {
|
|
|
|
const searchBar = this.page.getByPlaceholder('Search...');
|
|
|
|
await searchBar.fill(text);
|
|
|
|
}
|
2023-10-13 16:32:10 +02:00
|
|
|
}
|