Add a new graphql mutation in the pageLayout resolver to handle page layout update with tabs and widgets (#14612)
Add a new graphql mutation in the pageLayout resolver to handle page layout update with tabs and widgets. Later we will add validation inside the service to check if the page layout tab structure is correct (for instance check widgets don't overlap or aren't out of the grid, or to check that they have a correct configuration ...). This mutation will be plugged to the save action of the dashboards in the frontend.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { computeDiffBetweenObjects } from '../compute-diff-between-objects';
|
||||
|
||||
describe('computeDiffBetweenObjects', () => {
|
||||
it('should return the correct diff', () => {
|
||||
const existingObjects = [
|
||||
{ id: '1', name: 'Object 1' },
|
||||
{ id: '2', name: 'Object 2' },
|
||||
];
|
||||
const receivedObjects = [
|
||||
{ id: '1', name: 'Object 1' },
|
||||
{ id: '3', name: 'Object 3' },
|
||||
];
|
||||
|
||||
const diff = computeDiffBetweenObjects({
|
||||
existingObjects,
|
||||
receivedObjects,
|
||||
propertiesToCompare: ['name'],
|
||||
});
|
||||
|
||||
expect(diff).toEqual({
|
||||
toCreate: [{ id: '3', name: 'Object 3' }],
|
||||
toUpdate: [],
|
||||
idsToDelete: ['2'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the correct diff when the properties to compare are empty', () => {
|
||||
const existingObjects = [{ id: '1', name: 'Object 1' }];
|
||||
const receivedObjects = [{ id: '1', name: 'Object 1' }];
|
||||
|
||||
const diff = computeDiffBetweenObjects({
|
||||
existingObjects,
|
||||
receivedObjects,
|
||||
propertiesToCompare: [],
|
||||
});
|
||||
|
||||
expect(diff).toEqual({
|
||||
toCreate: [],
|
||||
toUpdate: [],
|
||||
idsToDelete: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the correct diff when the existing objects are empty', () => {
|
||||
const existingObjects: { id: string; name: string }[] = [];
|
||||
const receivedObjects = [{ id: '1', name: 'Object 1' }];
|
||||
|
||||
const diff = computeDiffBetweenObjects({
|
||||
existingObjects,
|
||||
receivedObjects,
|
||||
propertiesToCompare: ['name'],
|
||||
});
|
||||
|
||||
expect(diff).toEqual({
|
||||
toCreate: [{ id: '1', name: 'Object 1' }],
|
||||
toUpdate: [],
|
||||
idsToDelete: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the correct diff when the received objects are empty', () => {
|
||||
const existingObjects = [{ id: '1', name: 'Object 1' }];
|
||||
const receivedObjects: { id: string; name: string }[] = [];
|
||||
|
||||
const diff = computeDiffBetweenObjects({
|
||||
existingObjects,
|
||||
receivedObjects,
|
||||
propertiesToCompare: ['name'],
|
||||
});
|
||||
|
||||
expect(diff).toEqual({
|
||||
toCreate: [],
|
||||
toUpdate: [],
|
||||
idsToDelete: ['1'],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user