* fix: css selectors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types';
|
||||
import { buildConfig } from '../buildConfig';
|
||||
import { devUser } from '../../credentials';
|
||||
import { mapAsync } from '../../../src/utilities/mapAsync';
|
||||
|
||||
export const slug = 'fields-relationship';
|
||||
|
||||
@@ -13,6 +14,7 @@ export interface FieldsRelationship {
|
||||
id: string;
|
||||
relationship: RelationOne;
|
||||
relationshipHasMany: RelationOne[];
|
||||
relationshipHasManyMultiple: Array<RelationOne | RelationTwo | { relationTo: string, value: string}>;
|
||||
relationshipMultiple: Array<RelationOne | RelationTwo>;
|
||||
relationshipRestricted: RelationRestricted;
|
||||
relationshipWithTitle: RelationWithTitle;
|
||||
@@ -40,7 +42,7 @@ export default buildConfig({
|
||||
{
|
||||
slug,
|
||||
admin: {
|
||||
defaultColumns: ['relationship', 'relationshipRestricted', 'with-existing-relations'],
|
||||
defaultColumns: ['id', 'relationship', 'relationshipRestricted', 'relationshipHasManyMultiple', 'relationshipWithTitle'],
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
@@ -59,6 +61,12 @@ export default buildConfig({
|
||||
name: 'relationshipMultiple',
|
||||
relationTo: [relationOneSlug, relationTwoSlug],
|
||||
},
|
||||
{
|
||||
type: 'relationship',
|
||||
name: 'relationshipHasManyMultiple',
|
||||
hasMany: true,
|
||||
relationTo: [relationOneSlug, relationTwoSlug],
|
||||
},
|
||||
{
|
||||
type: 'relationship',
|
||||
name: 'relationshipRestricted',
|
||||
@@ -113,18 +121,26 @@ export default buildConfig({
|
||||
},
|
||||
});
|
||||
|
||||
await payload.create<RelationOne>({
|
||||
collection: relationOneSlug,
|
||||
data: {
|
||||
name: relationOneSlug,
|
||||
},
|
||||
const relationOneIDs = [];
|
||||
await mapAsync([...Array(5)], async () => {
|
||||
const doc = await payload.create<RelationOne>({
|
||||
collection: relationOneSlug,
|
||||
data: {
|
||||
name: relationOneSlug,
|
||||
},
|
||||
});
|
||||
relationOneIDs.push(doc.id);
|
||||
});
|
||||
|
||||
await payload.create<RelationTwo>({
|
||||
collection: relationTwoSlug,
|
||||
data: {
|
||||
name: relationTwoSlug,
|
||||
},
|
||||
const relationTwoIDs = [];
|
||||
await mapAsync([...Array(11)], async () => {
|
||||
const doc = await payload.create<RelationTwo>({
|
||||
collection: relationTwoSlug,
|
||||
data: {
|
||||
name: relationTwoSlug,
|
||||
},
|
||||
});
|
||||
relationTwoIDs.push(doc.id);
|
||||
});
|
||||
|
||||
// Existing relationships
|
||||
@@ -148,5 +164,28 @@ export default buildConfig({
|
||||
relationshipWithTitle: relationWithTitleDocId,
|
||||
},
|
||||
});
|
||||
await mapAsync([...Array(11)], async () => {
|
||||
await payload.create<FieldsRelationship>({
|
||||
collection: slug,
|
||||
data: {
|
||||
relationship: relationOneDocId,
|
||||
relationshipRestricted: restrictedDocId,
|
||||
relationshipHasManyMultiple: relationOneIDs.map((id) => ({ relationTo: relationOneSlug, value: id })),
|
||||
},
|
||||
});
|
||||
});
|
||||
await mapAsync([...Array(15)], async () => {
|
||||
const relationOneID = relationOneIDs[Math.floor(Math.random() * 10)];
|
||||
const relationTwoID = relationTwoIDs[Math.floor(Math.random() * 10)];
|
||||
await payload.create<FieldsRelationship>({
|
||||
collection: slug,
|
||||
data: {
|
||||
relationship: relationOneDocId,
|
||||
relationshipRestricted: restrictedDocId,
|
||||
relationshipHasMany: [relationOneID],
|
||||
relationshipHasManyMultiple: [{ relationTo: relationTwoSlug, value: relationTwoID }],
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -104,10 +104,9 @@ describe('fields - relationship', () => {
|
||||
test('should create relationship', async () => {
|
||||
await page.goto(url.create);
|
||||
|
||||
const fields = page.locator('.render-fields >> .react-select');
|
||||
const relationshipField = fields.nth(0);
|
||||
const field = page.locator('#field-relationship');
|
||||
|
||||
await relationshipField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
|
||||
const options = page.locator('.rs__option');
|
||||
|
||||
@@ -115,7 +114,7 @@ describe('fields - relationship', () => {
|
||||
|
||||
// Select a relationship
|
||||
await options.nth(1).click();
|
||||
await expect(relationshipField).toContainText(relationOneDoc.id);
|
||||
await expect(field).toContainText(relationOneDoc.id);
|
||||
|
||||
await saveDocAndAssert(page);
|
||||
});
|
||||
@@ -123,10 +122,9 @@ describe('fields - relationship', () => {
|
||||
test('should create hasMany relationship', async () => {
|
||||
await page.goto(url.create);
|
||||
|
||||
const fields = page.locator('.render-fields >> .react-select');
|
||||
const relationshipHasManyField = fields.nth(1);
|
||||
const field = page.locator('.field-relationshipHasMany');
|
||||
|
||||
await relationshipHasManyField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
|
||||
const options = page.locator('.rs__option');
|
||||
|
||||
@@ -134,16 +132,16 @@ describe('fields - relationship', () => {
|
||||
|
||||
// Add one relationship
|
||||
await options.locator(`text=${relationOneDoc.id}`).click();
|
||||
await expect(relationshipHasManyField).toContainText(relationOneDoc.id);
|
||||
await expect(relationshipHasManyField).not.toContainText(anotherRelationOneDoc.id);
|
||||
await expect(field).toContainText(relationOneDoc.id);
|
||||
await expect(field).not.toContainText(anotherRelationOneDoc.id);
|
||||
|
||||
// Add second relationship
|
||||
await relationshipHasManyField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
await options.locator(`text=${anotherRelationOneDoc.id}`).click();
|
||||
await expect(relationshipHasManyField).toContainText(anotherRelationOneDoc.id);
|
||||
await expect(field).toContainText(anotherRelationOneDoc.id);
|
||||
|
||||
// No options left
|
||||
await relationshipHasManyField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
await expect(page.locator('.rs__menu')).toHaveText('No options');
|
||||
|
||||
await saveDocAndAssert(page);
|
||||
@@ -152,10 +150,9 @@ describe('fields - relationship', () => {
|
||||
test('should create relations to multiple collections', async () => {
|
||||
await page.goto(url.create);
|
||||
|
||||
const fields = page.locator('.render-fields >> .react-select');
|
||||
const relationshipMultipleField = fields.nth(2);
|
||||
const field = page.locator('.field-relationshipMultiple');
|
||||
|
||||
await relationshipMultipleField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
|
||||
const options = page.locator('.rs__option');
|
||||
|
||||
@@ -163,12 +160,12 @@ describe('fields - relationship', () => {
|
||||
|
||||
// Add one relationship
|
||||
await options.locator(`text=${relationOneDoc.id}`).click();
|
||||
await expect(relationshipMultipleField).toContainText(relationOneDoc.id);
|
||||
await expect(field).toContainText(relationOneDoc.id);
|
||||
|
||||
// Add relationship of different collection
|
||||
await relationshipMultipleField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
await options.locator(`text=${relationTwoDoc.id}`).click();
|
||||
await expect(relationshipMultipleField).toContainText(relationTwoDoc.id);
|
||||
await expect(field).toContainText(relationTwoDoc.id);
|
||||
|
||||
await saveDocAndAssert(page);
|
||||
});
|
||||
@@ -177,11 +174,10 @@ describe('fields - relationship', () => {
|
||||
test('should highlight existing relationship', async () => {
|
||||
await page.goto(url.edit(docWithExistingRelations.id));
|
||||
|
||||
const fields = page.locator('.render-fields >> .react-select');
|
||||
const relationOneField = fields.nth(0);
|
||||
const field = page.locator('#field-relationship');
|
||||
|
||||
// Check dropdown options
|
||||
await relationOneField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
|
||||
await expect(page.locator('.rs__option--is-selected')).toHaveCount(1);
|
||||
await expect(page.locator('.rs__option--is-selected')).toHaveText(relationOneDoc.id);
|
||||
@@ -190,29 +186,31 @@ describe('fields - relationship', () => {
|
||||
test('should show untitled ID on restricted relation', async () => {
|
||||
await page.goto(url.edit(docWithExistingRelations.id));
|
||||
|
||||
const fields = page.locator('.render-fields >> .react-select');
|
||||
const restrictedRelationField = fields.nth(3);
|
||||
const field = page.locator('#field-relationshipRestricted');
|
||||
|
||||
// Check existing relationship has untitled ID
|
||||
await expect(restrictedRelationField).toContainText(`Untitled - ID: ${restrictedRelation.id}`);
|
||||
await expect(field).toContainText(`Untitled - ID: ${restrictedRelation.id}`);
|
||||
|
||||
// Check dropdown options
|
||||
await restrictedRelationField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
const options = page.locator('.rs__option');
|
||||
|
||||
await expect(options).toHaveCount(2); // None + 1 Unitled ID
|
||||
});
|
||||
|
||||
// test.todo('should paginate within the dropdown');
|
||||
// test.todo('should search within the relationship field');
|
||||
|
||||
test('should show useAsTitle on relation', async () => {
|
||||
await page.goto(url.edit(docWithExistingRelations.id));
|
||||
|
||||
const fields = page.locator('.render-fields >> .react-select');
|
||||
const relationWithTitleField = fields.nth(4);
|
||||
const field = page.locator('#field-relationshipWithTitle .react-select');
|
||||
|
||||
// Check existing relationship for correct title
|
||||
await expect(relationWithTitleField).toHaveText(relationWithTitle.name);
|
||||
await expect(field).toHaveText(relationWithTitle.name);
|
||||
await page.screenshot({ path: './bad.png' });
|
||||
|
||||
await relationWithTitleField.click({ delay: 100 });
|
||||
await field.click({ delay: 100 });
|
||||
const options = page.locator('.rs__option');
|
||||
|
||||
await expect(options).toHaveCount(2); // None + 1 Doc
|
||||
@@ -220,26 +218,26 @@ describe('fields - relationship', () => {
|
||||
|
||||
test('should show id on relation in list view', async () => {
|
||||
await page.goto(url.list);
|
||||
await wait(1000);
|
||||
const cells = page.locator('.relationship');
|
||||
await wait(110);
|
||||
const cells = page.locator('.cell-relationship');
|
||||
const relationship = cells.nth(0);
|
||||
await expect(relationship).toHaveText(relationOneDoc.id);
|
||||
});
|
||||
|
||||
test('should show Untitled ID on restricted relation in list view', async () => {
|
||||
await page.goto(url.list);
|
||||
await wait(110);
|
||||
const cells = page.locator('.cell-relationshipRestricted');
|
||||
const relationship = cells.nth(0);
|
||||
await expect(relationship).toContainText('Untitled - ID: ');
|
||||
});
|
||||
|
||||
test('should show useAsTitle on relation in list view', async () => {
|
||||
await page.goto(url.list);
|
||||
wait(110);
|
||||
const cells = page.locator('.relationshipWithTitle');
|
||||
await wait(110);
|
||||
const cells = page.locator('.cell-relationshipWithTitle');
|
||||
const relationship = cells.nth(0);
|
||||
await expect(relationship).toHaveText(relationWithTitle.id);
|
||||
});
|
||||
|
||||
test('should show untitled ID on restricted relation in list view', async () => {
|
||||
await page.goto(url.list);
|
||||
wait(110);
|
||||
const cells = page.locator('.relationship');
|
||||
const relationship = cells.nth(0);
|
||||
await expect(relationship).toHaveText(relationOneDoc.id);
|
||||
await expect(relationship).toHaveText(relationWithTitle.name);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,9 +17,9 @@ export async function firstRegister(args: FirstRegisterArgs): Promise<void> {
|
||||
const { page, serverURL } = args;
|
||||
|
||||
await page.goto(`${serverURL}/admin`);
|
||||
await page.fill('#email', devUser.email);
|
||||
await page.fill('#password', devUser.password);
|
||||
await page.fill('#confirm-password', devUser.password);
|
||||
await page.fill('#field-email', devUser.email);
|
||||
await page.fill('#field-password', devUser.password);
|
||||
await page.fill('#field-confirm-password', devUser.password);
|
||||
await wait(500);
|
||||
await page.click('[type=submit]');
|
||||
await page.waitForURL(`${serverURL}/admin`);
|
||||
@@ -29,8 +29,8 @@ export async function login(args: LoginArgs): Promise<void> {
|
||||
const { page, serverURL } = args;
|
||||
|
||||
await page.goto(`${serverURL}/admin`);
|
||||
await page.fill('#email', devUser.email);
|
||||
await page.fill('#password', devUser.password);
|
||||
await page.fill('#field-email', devUser.email);
|
||||
await page.fill('#field-password', devUser.password);
|
||||
await wait(500);
|
||||
await page.click('[type=submit]');
|
||||
await page.waitForURL(`${serverURL}/admin`);
|
||||
|
||||
BIN
test/e2e/uploads/image.png
Normal file
BIN
test/e2e/uploads/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
Reference in New Issue
Block a user