Skip to content

Commit 1cb3c6d

Browse files
Pollepsjoepio
authored andcommitted
#648 Add ontology test and fix other tests
1 parent 39b102e commit 1cb3c6d

File tree

4 files changed

+70
-43
lines changed

4 files changed

+70
-43
lines changed

browser/data-browser/src/components/forms/SearchBox/SearchBoxWindow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function SearchBoxWindow({
161161
onKeyDown={handleKeyDown}
162162
onPaste={handlePaste}
163163
/>
164-
<ResultBox>
164+
<ResultBox data-testid='searchbox-results'>
165165
{!searchValue && <CenteredMessage>Start Searching</CenteredMessage>}
166166
<StyledScrollArea>
167167
<ul>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { JSONValue, properties } from '@tomic/react';
1+
import { core, JSONValue } from '@tomic/react';
22
import { randomString } from './randomString';
33

44
const normalizeName = (name: string) =>
5-
encodeURIComponent(name.replaceAll('/t', '-'));
5+
encodeURIComponent(name.replace(/\s/g, '-'));
66

77
export const getNamePartFromProps = (
88
props: Record<string, JSONValue>,
99
): string =>
1010
normalizeName(
11-
(props?.[properties.shortname] as string) ??
12-
(props?.[properties.name] as string) ??
11+
(props?.[core.properties.shortname] as string) ??
12+
(props?.[core.properties.name] as string) ??
1313
randomString(8),
1414
);

browser/data-browser/tests/e2e.spec.ts

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import {
3131
signIn,
3232
timestamp,
3333
waitForCommit,
34+
openAgentPage,
35+
fillSearchBox,
3436
} from './test-utils';
3537

3638
test.describe('data-browser', async () => {
@@ -62,7 +64,7 @@ test.describe('data-browser', async () => {
6264
});
6365

6466
// Sign out
65-
await page.click('text=user settings');
67+
await openAgentPage(page);
6668
await page.click('[data-test="sign-out"]');
6769
await expect(page.locator('text=Enter your Agent secret')).toBeVisible();
6870
await page.reload();
@@ -249,9 +251,6 @@ test.describe('data-browser', async () => {
249251
await page2.keyboard.press('Enter');
250252
// Both pages should see then new chat message
251253
await expect(page.locator(`text=${teststring2}`)).toBeVisible();
252-
// TODO: get rid of this reload! It should not be necessary
253-
// For some reason the page does not see the new message
254-
await page2.reload();
255254
await expect(page2.locator(`text=${teststring2}`)).toBeVisible();
256255
});
257256

@@ -342,7 +341,7 @@ test.describe('data-browser', async () => {
342341
// await expect(page.locator(currentDriveTitle)).toHaveText('Atomic Data');
343342

344343
// Cleanup drives for signed in user
345-
await page.click('text=user settings');
344+
await openAgentPage(page);
346345
await page.click('text=Edit profile');
347346
await page.click('[data-test="input-drives-clear"]');
348347
await page.click('[data-test="save"]');
@@ -376,35 +375,24 @@ test.describe('data-browser', async () => {
376375
const shortnameInput = '[data-test="input-shortname"]';
377376
// Try entering a wrong slug
378377
await page.click(shortnameInput);
379-
await page.keyboard.type('not valid');
380-
await expect(page.locator('text=Not a valid slug')).toBeVisible();
378+
await page.keyboard.type('not valid-');
379+
await page.locator(shortnameInput).blur();
380+
await expect(page.getByText('Invalid Slug')).toBeVisible();
381381
await page.locator(shortnameInput).fill('');
382382
await page.keyboard.type('is-valid');
383383
await expect(page.locator('text=Not a valid slug')).not.toBeVisible();
384384

385-
// Add a new property
386-
const input = page.locator(
387-
'[placeholder="Select a property or enter a property URL..."]',
385+
await fillSearchBox(
386+
page,
387+
'Search for a property or enter a URL',
388+
'https://atomicdata.dev/properties/invite/usagesLeft',
388389
);
389-
await input.click();
390-
391-
await expect(page.locator('text=Create property:')).toBeVisible();
392-
await input.fill('https://atomicdata.dev/properties/invite/usagesLeft');
393390
await page.keyboard.press('Enter');
394-
await page.click('[title="Add this property"]');
395391
await expect(page.locator('text=Usages-left').first()).toBeVisible();
396392
// Integer validation
397393
await page.click('[data-test="input-usages-left"]');
398-
await page.keyboard.type('asdf' + '1');
394+
await page.keyboard.type('asdf1');
399395
await expect(page.locator('text=asdf')).not.toBeVisible();
400-
// Dropdown select
401-
await page.click('[data-test="input-recommends-add-resource"]');
402-
await page.locator('text=append').click();
403-
await expect(
404-
page.locator(
405-
'[data-test="input-recommends"] >> text=https://atomicdata.dev',
406-
),
407-
).not.toBeVisible();
408396

409397
// Try to save without a description
410398
page.locator('button:has-text("Save")').click();
@@ -505,20 +493,27 @@ test.describe('data-browser', async () => {
505493
.locator('[title="Add an item to the recommends list"]')
506494
.first()
507495
.click();
508-
await page.locator('[data-test="input-recommends"]').click();
509-
await page.locator('[data-test="input-recommends"]').fill('test-prop');
510496

511497
// Create new Property using dialog
512-
await page.locator('text=Create property: test-prop').click();
498+
499+
const clickOption = await fillSearchBox(
500+
page,
501+
'Search for a property or enter a URL',
502+
'test-prop',
503+
{ nth: 0 },
504+
);
505+
506+
await clickOption('Create test-prop');
507+
513508
await expect(page.locator('h1:has-text("new property")')).toBeVisible();
514-
await page.locator('[data-test="input-datatype"]').click();
515-
// click twice, first click is buggy, it closes the dropdown from earlier
516-
await page.locator('[data-test="input-datatype"]').click();
517-
await page
518-
.locator(
519-
'li:has-text("boolean - Either `true` or `false`. In JSON-AD, th...")',
520-
)
521-
.click();
509+
// Set datatype of new property to boolean
510+
511+
const selectDatatypeOption = await fillSearchBox(
512+
page,
513+
'Search for a datatype or enter a URL',
514+
'boolean',
515+
);
516+
await selectDatatypeOption('boolean - Either `true` or `false`');
522517
await page.locator('dialog textarea[name="yamdeContent"]').click();
523518
await page
524519
.locator('dialog textarea[name="yamdeContent"]')

browser/data-browser/tests/test-utils.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page, expect, Browser } from '@playwright/test';
1+
import { Page, expect, Browser, Locator } from '@playwright/test';
22

33
export const DEMO_FILENAME = 'testimage.svg';
44
export const SERVER_URL = 'http://localhost:9883';
@@ -122,6 +122,10 @@ export async function getCurrentSubject(page: Page) {
122122
return page.locator(addressBar).getAttribute('value');
123123
}
124124

125+
export async function openAgentPage(page: Page) {
126+
page.goto(`${FRONTEND_URL}/app/agent`);
127+
}
128+
125129
/** Set atomicdata.dev as current server */
126130
export async function openAtomic(page: Page) {
127131
await changeDrive('https://atomicdata.dev', page);
@@ -131,7 +135,7 @@ export async function openAtomic(page: Page) {
131135

132136
/** Opens the users' profile, sets a username */
133137
export async function editProfileAndCommit(page: Page) {
134-
await page.click('text=user settings');
138+
await openAgentPage(page);
135139
await page.click('text=Edit profile');
136140
await expect(page.locator('text=add another property')).toBeVisible();
137141
const username = `Test user edited at ${new Date().toLocaleDateString()}`;
@@ -143,14 +147,42 @@ export async function editProfileAndCommit(page: Page) {
143147
await expect(page.locator(`text=${username}`).first()).toBeVisible();
144148
}
145149

150+
export async function fillSearchBox(
151+
page: Page,
152+
placeholder: string,
153+
fillText: string,
154+
options: {
155+
nth?: number;
156+
container?: Locator;
157+
} = {},
158+
) {
159+
const { nth, container } = options;
160+
const selector = container ?? page;
161+
162+
if (nth !== undefined) {
163+
await selector.getByRole('button', { name: placeholder }).nth(nth).click();
164+
} else {
165+
await selector.getByRole('button', { name: placeholder }).click();
166+
}
167+
168+
await selector.getByPlaceholder(placeholder).type(fillText);
169+
170+
return async (name: string) => {
171+
// wait for the search to load (TODO: make this better)
172+
await page.waitForTimeout(100);
173+
selector.getByTestId('searchbox-results').getByText(name).hover();
174+
selector.getByTestId('searchbox-results').getByText(name).click();
175+
};
176+
}
177+
146178
/** Create a new Resource in the current Drive.
147179
* Class can be an Class URL or a shortname available in the new page. */
148180
export async function newResource(klass: string, page: Page) {
149181
await page.locator(sideBarNewResource).click();
150182
await expect(page).toHaveURL(`${FRONTEND_URL}/app/new`);
151183

152184
if (klass.startsWith('https://')) {
153-
await page.getByPlaceholder('Select a class').fill(klass);
185+
await fillSearchBox(page, 'Search for a class or enter a URL', klass);
154186
await page.keyboard.press('Enter');
155187
await page.click(`button:has-text("new ")`);
156188
} else {

0 commit comments

Comments
 (0)