From 17dea3124da1d01be32f25c405960bca54f5f54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Tue, 30 Mar 2021 18:10:58 +0200 Subject: [PATCH] wip: views store tests --- .../stores/backend/tests/fixtures/views.js | 102 ++++++++++++++++++ .../src/stores/backend/tests/views.spec.js | 21 ++++ packages/builder/src/stores/backend/views.js | 2 + 3 files changed, 125 insertions(+) create mode 100644 packages/builder/src/stores/backend/tests/fixtures/views.js 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(