diff --git a/packages/builder/src/stores/backend/tests/fixtures/views.js b/packages/builder/src/stores/backend/tests/fixtures/views.js new file mode 100644 index 0000000000..9a7b6173ad --- /dev/null +++ b/packages/builder/src/stores/backend/tests/fixtures/views.js @@ -0,0 +1,102 @@ +export const A_VIEW = { + "name": "Published", + "tableId": "ta_3c78cffe33664ca9bfb6b2b6cb3ee55a", + "filters": [], + "schema": { + "Auto ID": { + "name": "Auto ID", + "type": "number", + "subtype": "autoID", + "icon": "ri-magic-line", + "autocolumn": true, + "constraints": { + "type": "number", + "presence": false, + "numericality": { + "greaterThanOrEqualTo": "", + "lessThanOrEqualTo": "" + } + }, + "lastID": 2 + }, + "Created By": { + "name": "Created By", + "type": "link", + "subtype": "createdBy", + "icon": "ri-magic-line", + "autocolumn": true, + "constraints": { + "type": "array", + "presence": false + }, + "tableId": "ta_users", + "fieldName": "Guest-Created By", + "relationshipType": "many-to-many" + }, + "Created At": { + "name": "Created At", + "type": "datetime", + "subtype": "createdAt", + "icon": "ri-magic-line", + "autocolumn": true, + "constraints": { + "type": "string", + "length": {}, + "presence": false, + "datetime": { + "latest": "", + "earliest": "" + } + } + }, + "Updated By": { + "name": "Updated By", + "type": "link", + "subtype": "updatedBy", + "icon": "ri-magic-line", + "autocolumn": true, + "constraints": { + "type": "array", + "presence": false + }, + "tableId": "ta_users", + "fieldName": "Guest-Updated By", + "relationshipType": "many-to-many" + }, + "Updated At": { + "name": "Updated At", + "type": "datetime", + "subtype": "updatedAt", + "icon": "ri-magic-line", + "autocolumn": true, + "constraints": { + "type": "string", + "length": {}, + "presence": false, + "datetime": { + "latest": "", + "earliest": "" + } + } + }, + "Episode": { + "name": "Episode", + "type": "link", + "tableId": "ta_d4bf541ce0d84b16a1a8e0a060e5f7f7", + "fieldName": "Guest", + "relationshipType": "one-to-many" + }, + "Names": { + "type": "string", + "constraints": { + "type": "string", + "length": { + "maximum": "" + }, + "presence": false + }, + "fieldName": "Guest", + "name": "Names" + } + } +} \ No newline at end of file diff --git a/packages/builder/src/stores/backend/tests/views.spec.js b/packages/builder/src/stores/backend/tests/views.spec.js index e69de29bb2..4ba4d6ffed 100644 --- a/packages/builder/src/stores/backend/tests/views.spec.js +++ b/packages/builder/src/stores/backend/tests/views.spec.js @@ -0,0 +1,21 @@ +import { get } from 'svelte/store' +import api from 'builderStore/api' + +jest.mock('builderStore/api'); + +import { SOME_TABLES } from './fixtures/tables' + +import { createViewsStore } from "../views" + +describe("Tables Store", () => { + let store = createViewsStore() + + beforeEach(async () => { + api.get.mockReturnValue({ json: () => SOME_TABLES}) + await store.init() + }) + + it("Initialises correctly", async () => { + expect(get(store)).toEqual({ list: SOME_TABLES, selected: {}, draft: {}}) + }) +}) \ No newline at end of file diff --git a/packages/builder/src/stores/backend/views.js b/packages/builder/src/stores/backend/views.js index 5cd3c60267..0f2837bfbd 100644 --- a/packages/builder/src/stores/backend/views.js +++ b/packages/builder/src/stores/backend/views.js @@ -11,6 +11,7 @@ export function createViewsStore() { return { subscribe, select: view => { + console.log(view) update(state => ({ ...state, selected: view, @@ -28,6 +29,7 @@ export function createViewsStore() { name: view.name, ...json, } + console.log('JSON: ', json) update(state => { const viewTable = get(tables).list.find(