From fc4e9676969d50741d2213fce9ff8ca89293118c Mon Sep 17 00:00:00 2001 From: Kauwai Lucchesi Date: Mon, 30 Sep 2024 10:24:36 -0300 Subject: [PATCH] Create endpoint update-layout --- test/spread/project.clj | 2 +- .../src/house/jux__/test/spread__/index.html | 18 ++++++++++++++---- .../src/house/jux__/test/spread__/layout.clj | 5 ++--- .../src/house/jux__/test/spread__/server.clj | 18 ++++++++++++++---- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/test/spread/project.clj b/test/spread/project.clj index 087e9df..9baa6b1 100644 --- a/test/spread/project.clj +++ b/test/spread/project.clj @@ -1,4 +1,4 @@ -(defproject house.jux/test.spread "2024.09.28" +(defproject house.jux/test.spread "2024.09.30" :description "Support for highly expressive, two-dimensional tests represented as spreadsheets." :url "https://github.com/klauswuestefeld/simple-clj/tree/master/test/spread" diff --git a/test/spread/src/house/jux__/test/spread__/index.html b/test/spread/src/house/jux__/test/spread__/index.html index 843958b..1d68a6b 100644 --- a/test/spread/src/house/jux__/test/spread__/index.html +++ b/test/spread/src/house/jux__/test/spread__/index.html @@ -505,6 +505,16 @@ return { columns, rows }; } + async function updateTestLayout() { + const response = await fetch("/api/update-layout", { + method: "POST", + body: JSON.stringify({ + filename: currentFilePath, + "spreadsheet-dimensions": getSpreadsheetDimensions(), + }), + }); + } + async function saveSpreadsheetAndRunTests() { indicateTestsRunning(); clearErrorHighlights(); @@ -603,10 +613,10 @@ const eventHandlers = { onchange: saveSpreadsheetAndRunTests, - onresizecolumn: saveSpreadsheetAndRunTests, - onresizerow: saveSpreadsheetAndRunTests, - ondeleterow: saveSpreadsheetAndRunTests, - ondeletecolumn: saveSpreadsheetAndRunTests, + onresizecolumn: updateTestLayout, + onresizerow: updateTestLayout, + ondeleterow: updateTestLayout, + ondeletecolumn: updateTestLayout, }; jspreadsheetObj = loadJSpreadsheet(spreadsheet, spreadsheetDOMElement, eventHandlers); diff --git a/test/spread/src/house/jux__/test/spread__/layout.clj b/test/spread/src/house/jux__/test/spread__/layout.clj index 46345fb..1a50ffb 100644 --- a/test/spread/src/house/jux__/test/spread__/layout.clj +++ b/test/spread/src/house/jux__/test/spread__/layout.clj @@ -2,14 +2,13 @@ (:require [clojure.java.io :as java.io] [clojure.string :as string])) -(def file-suffix - ".layout.edn") +(def file-suffix ".layout.edn") (defn- layout-file? [filename] (-> filename java.io/file .exists)) (defn- path->filename [path] - (str (string/replace path #".csv" "") file-suffix)) + (string/replace path #".csv" file-suffix)) (defn layout-get [relative-path] (let [filename (path->filename relative-path)] diff --git a/test/spread/src/house/jux__/test/spread__/server.clj b/test/spread/src/house/jux__/test/spread__/server.clj index 7ba12ef..4d5835e 100644 --- a/test/spread/src/house/jux__/test/spread__/server.clj +++ b/test/spread/src/house/jux__/test/spread__/server.clj @@ -39,11 +39,20 @@ (catch RuntimeException e (throw (unpack-actual-exception-if-necessary e))))) +(defn- ->relative-path [filename] + (str spread/all-spreadsheets-folder filename)) + +(defn- update-layout + ([relative-path spreadsheet-dimensions] + (layout/layout-save relative-path spreadsheet-dimensions)) + ([_endpoint _user {:keys [filename spreadsheet-dimensions]}] + (update-layout (->relative-path filename) spreadsheet-dimensions))) + (defn- save-and-run [endpoint user {:keys [filename spreadsheet-data spreadsheet-dimensions] :as params}] - (let [relative-path (str spread/all-spreadsheets-folder filename)] + (let [relative-path (->relative-path filename)] (when filename - (csv/write! relative-path spreadsheet-data)) - (layout/layout-save relative-path spreadsheet-dimensions) + (csv/write! relative-path spreadsheet-data) + (update-layout relative-path spreadsheet-dimensions)) (run-tests endpoint user params))) (defn- accumulate-general-tests [acc file] @@ -64,7 +73,7 @@ .exists) (conj (csv/read! specific-test))))) (defn- csv-read [_endpoint _user {:keys [filename]}] - (let [relative-path (str spread/all-spreadsheets-folder filename) + (let [relative-path (->relative-path filename) data (csv/read! relative-path) dimensions (layout/layout-get relative-path) {:keys [commands initial-results queries]} (spread/cells-info data) @@ -125,6 +134,7 @@ (-> not-found (api/wrap-api "/api/run" run-tests {:anonymous? true}) (api/wrap-api "/api/save-and-run" save-and-run {:anonymous? true}) + (api/wrap-api "/api/update-layout" update-layout {:anonymous? true}) (api/wrap-api "/api/csv-read" csv-read {:anonymous? true}) (api/wrap-api "/api/get-test-tree" test-tree {:anonymous? true}) (wrap-single-request)