Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional e2e tests for up down arrow navigation #205

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Page } from 'playwright/test';
import { getSelector, waitForAnimationEnd } from '../../helpers';
import testIds from '../../../../src/helper/test-ids';
import { closeTab } from '../close-tab';
import { openNewTab } from '../open-new-tab';

export const navigateBackToCurrentPromptWithCodeAttachment = async (page: Page, skipScreenshots?: boolean): Promise<void> => {
await closeTab(page, false, true);
await openNewTab(page, false, true);

await page.locator(`${getSelector(testIds.prompt.input)}`).fill('This is the first user prompt');
Jurredr marked this conversation as resolved.
Show resolved Hide resolved
await page.locator(`${getSelector(testIds.prompt.send)}`).click();
await waitForAnimationEnd(page);

await page.evaluate(() => {
const selectedTabId = window.mynahUI.getSelectedTabId();
if (selectedTabId != null) {
window.mynahUI.addToUserPrompt(
selectedTabId,
'This is an unsent code attachment',
'code',
);
}
});
await waitForAnimationEnd(page);

const promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
await promptInput.press('ArrowUp');
await waitForAnimationEnd(page);

await promptInput.press('ArrowDown');
await waitForAnimationEnd(page);
// we add .trim() because webpack test was failing otherwise, as it adds a \n at the end, like 'This is an unsent code attachment\n'
const codeAttachmentContent = (await page.locator(`${getSelector(testIds.prompt.attachment)}`).innerText()).trim();
francescoopiccoli marked this conversation as resolved.
Show resolved Hide resolved
expect(codeAttachmentContent).toBe('This is an unsent code attachment');

if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Page } from 'playwright/test';
import { getSelector, waitForAnimationEnd } from '../../helpers';
import testIds from '../../../../src/helper/test-ids';
import { closeTab } from '../close-tab';
import { openNewTab } from '../open-new-tab';

export const navigateBackToCurrentPrompt = async (page: Page, skipScreenshots?: boolean): Promise<void> => {
await closeTab(page, false, true);
await openNewTab(page, false, true);

await page.locator(`${getSelector(testIds.prompt.input)}`).fill('This is the first user prompt');

await page.locator(`${getSelector(testIds.prompt.send)}`).click();
await waitForAnimationEnd(page);

// Write prompt without sending it
await page.locator(`${getSelector(testIds.prompt.input)}`).fill('This is the second unsent user prompt');
await waitForAnimationEnd(page);

const promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
await promptInput.press('ArrowUp');
await waitForAnimationEnd(page);

await promptInput.press('ArrowDown');
await waitForAnimationEnd(page);

expect(await promptInput.inputValue()).toBe('This is the second unsent user prompt');

if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ export const navigatePromptsDown = async (page: Page, skipScreenshots?: boolean)
await page.locator(`${getSelector(testIds.prompt.send)}`).click();
await waitForAnimationEnd(page);

let promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
const promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
await promptInput.press('ArrowUp');
await waitForAnimationEnd(page);

await promptInput.press('ArrowUp');
await waitForAnimationEnd(page);

promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
await promptInput.press('ArrowDown');
await waitForAnimationEnd(page);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export const navigatePromptsToEmpty = async (page: Page, skipScreenshots?: boole
await page.locator(`${getSelector(testIds.prompt.send)}`).click();
await waitForAnimationEnd(page);

let promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
const promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
await promptInput.press('ArrowUp');
await waitForAnimationEnd(page);

promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
await promptInput.press('ArrowDown');
await waitForAnimationEnd(page);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Page } from 'playwright/test';
import { getSelector, waitForAnimationEnd } from '../../helpers';
import testIds from '../../../../src/helper/test-ids';
import { closeTab } from '../close-tab';
import { openNewTab } from '../open-new-tab';

export const stayOnCurrentPrompt = async (page: Page, skipScreenshots?: boolean): Promise<void> => {
await closeTab(page, false, true);
await openNewTab(page, false, true);

// Write prompt without sending it
await page.locator(`${getSelector(testIds.prompt.input)}`).fill('This is the first unsent user prompt');
await waitForAnimationEnd(page);

const promptInput = await page.locator(`${getSelector(testIds.prompt.input)}`);
await promptInput.press('ArrowUp');
await waitForAnimationEnd(page);

await promptInput.press('ArrowDown');
await waitForAnimationEnd(page);

expect(await promptInput.inputValue()).toBe('This is the first unsent user prompt');

if (skipScreenshots !== true) {
expect(await page.screenshot()).toMatchImageSnapshot();
}
};
25 changes: 22 additions & 3 deletions ui-tests/__test__/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { renderInformationCard } from './flows/render-information-card';
import { renderTabbedCard } from './flows/render-tabbed-card';
import { welcomeMode } from './flows/welcome-mode';
import { renderButtons } from './flows/render-buttons';
import { navigatePromptsDown } from './flows/navigate-prompts/navigatePromptsDown';
import { navigatePromptsUp } from './flows/navigate-prompts/navigatePromptsUp';
import { navigatePromptsToEmpty } from './flows/navigate-prompts/navigatePromptsToEmpty';
import { navigatePromptsDown } from './flows/navigate-prompts/navigate-prompts-down';
import { navigatePromptsUp } from './flows/navigate-prompts/navigate-prompts-up';
import { navigatePromptsToEmpty } from './flows/navigate-prompts/navigate-prompts-to-empty';
import { hoverOverLink } from './flows/link-hover-preview';
import { showFileTree } from './flows/file-tree/show-file-tree';
import { collapseExpandFileTree } from './flows/file-tree/collapse-file-tree';
Expand All @@ -32,8 +32,15 @@ import { renderFileDetails } from './flows/file-tree/render-file-details';
import { renderFormElements } from './flows/form/render-form-elements';
import { disableForm } from './flows/form/disable-form';
import { removeForm } from './flows/form/remove-form';
import { stayOnCurrentPrompt } from './flows/navigate-prompts/stay-on-current-prompt';
import { navigateBackToCurrentPrompt } from './flows/navigate-prompts/navigate-back-to-current-prompt';
import { navigateBackToCurrentPromptWithCodeAttachment } from './flows/navigate-prompts/navigate-back-to-current-prompt-with-code-attachment';

describe('Open MynahUI', () => {
beforeEach(async () => {
await page.setViewportSize(DEFAULT_VIEWPORT);
});

beforeAll(async () => {
const browserName = browser.browserType().name();
const toMatchImageSnapshot = configureToMatchImageSnapshot({
Expand Down Expand Up @@ -220,5 +227,17 @@ describe('Open MynahUI', () => {
it('should navigate down to current empty prompt', async () => {
await navigatePromptsToEmpty(page);
});

it('should stay on current prompt', async () => {
await stayOnCurrentPrompt(page);
});

it('should navigate back to current prompt', async () => {
await navigateBackToCurrentPrompt(page);
});

it('should navigate back to current prompt with code attachment', async () => {
await navigateBackToCurrentPromptWithCodeAttachment(page);
});
});
});
Loading