44 lines
2.1 KiB
TypeScript
44 lines
2.1 KiB
TypeScript
import type { ProjectDocument } from '../../types/project';
|
|
import { findComponentReferences } from './componentDeletionUtils';
|
|
|
|
const doc: ProjectDocument = {
|
|
schemaVersion: '0.1.0',
|
|
project: {
|
|
id: 'project', name: 'Project', variables: {}, settings: {},
|
|
pages: [{ id: 'page', name: 'Page', components: [] }],
|
|
bindings: [
|
|
{ id: 'binding_target', source: 'actions.load.response.body', target: 'components.postsTable.rows', trigger: 'onSuccess' },
|
|
{ id: 'binding_source', source: 'components.itemInput.value', target: 'variables.query', trigger: 'onChange' },
|
|
{ id: 'binding_other', source: 'actions.load.response.body', target: 'components.other.value', trigger: 'onSuccess' },
|
|
],
|
|
actions: [{
|
|
id: 'load', name: 'Load posts', method: 'GET', authenticationType: 'anonymous',
|
|
url: 'https://example.com/{{components.itemInput.value}}',
|
|
headers: { 'X-Input': '{{components.itemInput.value}}' },
|
|
queryParameters: { item: '{{components.itemInput.value}}' },
|
|
pathParameters: { legacy: '{{components.itemInput.value}}' },
|
|
bodyTemplate: '{"item":"{{components.itemInput.value}}"}',
|
|
}],
|
|
},
|
|
};
|
|
|
|
describe('component deletion reference discovery', () => {
|
|
test('finds binding targets for a Table without matching similar names', () => {
|
|
expect(findComponentReferences(doc, 'postsTable')).toEqual([
|
|
{ kind: 'binding', label: 'Binding "binding_target" target' },
|
|
]);
|
|
expect(findComponentReferences(doc, 'posts')).toEqual([]);
|
|
});
|
|
|
|
test('finds binding sources and every request-template location', () => {
|
|
expect(findComponentReferences(doc, 'itemInput')).toEqual([
|
|
{ kind: 'binding', label: 'Binding "binding_source" source' },
|
|
{ kind: 'actionTemplate', label: 'Action "Load posts" URL' },
|
|
{ kind: 'actionTemplate', label: 'Action "Load posts" body' },
|
|
{ kind: 'actionTemplate', label: 'Action "Load posts" header "X-Input"' },
|
|
{ kind: 'actionTemplate', label: 'Action "Load posts" query parameter "item"' },
|
|
{ kind: 'actionTemplate', label: 'Action "Load posts" path parameter "legacy"' },
|
|
]);
|
|
});
|
|
});
|