test: json field e2e and int

This commit is contained in:
Dan Ribbens
2022-12-23 17:45:22 -05:00
parent 73b8ba3d4a
commit abaa22950c
3 changed files with 57 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import { pointFieldsSlug } from './collections/Point';
import { tabsSlug } from './collections/Tabs';
import { collapsibleFieldsSlug } from './collections/Collapsible';
import wait from '../../src/utilities/wait';
import { jsonDoc } from './collections/JSON';
const { beforeAll, describe } = test;
@@ -64,6 +65,31 @@ describe('fields', () => {
});
});
describe('json', () => {
let url: AdminUrlUtil;
beforeAll(() => {
url = new AdminUrlUtil(serverURL, 'json-fields');
});
test('should display field in list view', async () => {
await page.goto(url.list);
const jsonCell = page.locator('.row-1 .cell-json');
await expect(jsonCell)
.toHaveText(JSON.stringify(jsonDoc.json));
});
test('should create', async () => {
const input = '{"foo": "bar"}';
await page.goto(url.create);
const json = page.locator('.json-field .inputarea');
await json.fill(input);
await saveDocAndAssert(page);
await expect(page.locator('.json-field')).toContainText('"foo": "bar"');
});
});
describe('radio', () => {
let url: AdminUrlUtil;
beforeAll(() => {

View File

@@ -505,6 +505,29 @@ describe('Fields', () => {
});
});
describe('json', () => {
it('should save json data', async () => {
const json = { foo: 'bar' };
const doc = await payload.create({
collection: 'json-fields',
data: {
json,
},
});
expect(doc.json).toStrictEqual({ foo: 'bar' });
});
it('should validate json', async () => {
await expect(async () => payload.create({
collection: 'json-fields',
data: {
json: '{ bad input: true }',
},
})).rejects.toThrow('The following field is invalid: json');
});
});
describe('richText', () => {
it('should allow querying on rich text content', async () => {
const emptyRichTextQuery = await payload.find({