chore: tests

This commit is contained in:
James
2022-10-10 14:56:10 -04:00
parent c6edb7f53a
commit 1bc42ae098
3 changed files with 77 additions and 5 deletions

View File

@@ -77,12 +77,14 @@ export const AddNewRelation: React.FC<Props> = ({ path, hasMany, relationTo, val
}, [modalState, modalSlug]);
return hasPermission ? (
<div className={baseClass}>
<div
className={baseClass}
id={`${path}-add-new`}
>
{relatedCollections.length === 1 && (
<Button
className={`${baseClass}__add-button`}
onClick={() => openModal(relatedCollections[0])}
id={`${path}-add-new`}
buttonStyle="none"
tooltip={`Add new ${relatedCollections[0].labels.singular}`}
>
@@ -97,7 +99,6 @@ export const AddNewRelation: React.FC<Props> = ({ path, hasMany, relationTo, val
button={(
<Button
className={`${baseClass}__add-button`}
id={`${path}-add-new`}
buttonStyle="none"
tooltip={popupOpen ? undefined : 'Add new'}
>
@@ -111,7 +112,7 @@ export const AddNewRelation: React.FC<Props> = ({ path, hasMany, relationTo, val
return (
<li key={relatedCollection.slug}>
<button
className={`${baseClass}__relation-button`}
className={`${baseClass}__relation-button ${baseClass}__relation-button--${relatedCollection.slug}`}
type="button"
onClick={() => { closePopup(); openModal(relatedCollection); }}
>

View File

@@ -8,7 +8,7 @@ const RelationshipFields: CollectionConfig = {
{
name: 'relationship',
type: 'relationship',
relationTo: ['uploads', 'array-fields'],
relationTo: ['text-fields', 'array-fields'],
required: true,
},
{

View File

@@ -8,6 +8,7 @@ import { arrayFieldsSlug } from './collections/Array';
import { pointFieldsSlug } from './collections/Point';
import { tabsSlug } from './collections/Tabs';
import wait from '../../src/utilities/wait';
import { relationshipFieldsSlug } from './collections/Relationship';
const { beforeAll, describe } = test;
@@ -222,5 +223,75 @@ describe('fields', () => {
await expect(editLinkModal).not.toBeVisible();
});
});
describe('relationship', () => {
let url: AdminUrlUtil;
beforeAll(() => {
url = new AdminUrlUtil(serverURL, relationshipFieldsSlug);
});
test('should create inline relationship within field with many relations', async () => {
await page.goto(url.create);
const button = page.locator('#relationship-add-new .relationship-add-new__add-button');
await button.click();
await page.locator('.relationship-add-new__relation-button--text-fields').click();
const textField = page.locator('#field-text');
const textValue = 'hello';
await textField.fill(textValue);
await page.locator('#relationship-add-modal-depth-1 #action-save').click();
await expect(page.locator('.Toastify')).toContainText('successfully');
await expect(page.locator('#field-relationship .rs__single-value')).toContainText(textValue);
await page.locator('#action-save').click();
await expect(page.locator('.Toastify')).toContainText('successfully');
});
test('should create nested inline relationships', async () => {
await page.goto(url.create);
// Open first modal
await page.locator('#relationToSelf-add-new .relationship-add-new__add-button').click();
// Fill first modal's required relationship field
await page.locator('#relationToSelf-add-modal-depth-1 #field-relationship').click();
await page.locator('#relationToSelf-add-modal-depth-1 .rs__option:has-text("Seeded text document")').click();
// Open second modal
await page.locator('#relationToSelf-add-modal-depth-1 #relationToSelf-add-new button').click();
// Fill second modal's required relationship field
await page.locator('#relationToSelf-add-modal-depth-2 #field-relationship').click();
await page.locator('#relationToSelf-add-modal-depth-2 .rs__option:has-text("Seeded text document")').click();
// Save second modal
await page.locator('#relationToSelf-add-modal-depth-2 #action-save').click();
// Assert that the first modal is still open
// and that the Relation to Self field now has a value in its input
await expect(page.locator('#relationToSelf-add-modal-depth-1 #field-relationToSelf .rs__single-value')).toBeVisible();
// Save first modal
await page.locator('#relationToSelf-add-modal-depth-1 #action-save').click();
await wait(200);
// Expect the original field to have a value filled
await expect(page.locator('#field-relationToSelf .rs__single-value')).toBeVisible();
// Fill the required field
await page.locator('#field-relationship').click();
await page.locator('.rs__option:has-text("Seeded text document")').click();
await page.locator('#action-save').click();
await expect(page.locator('.Toastify')).toContainText('successfully');
});
});
});
});