mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-21 06:00:39 +00:00
fix(ci): fix broken tests after external-sql and xlsx changes
This commit is contained in:
@@ -536,6 +536,18 @@ export const useQueryStore = defineStore("query", () => {
|
||||
{ flush: "post" },
|
||||
);
|
||||
|
||||
// Immediately flush any pending debounced persist so the on-disk content
|
||||
// reflects the latest in-memory tabs without waiting for the 300ms debounce.
|
||||
// Lets callers (e.g. tests that reload the store) read back persisted state
|
||||
// deterministically instead of racing the debounce timer.
|
||||
function flushPendingPersist() {
|
||||
if (_persistTimer) {
|
||||
clearTimeout(_persistTimer);
|
||||
_persistTimer = null;
|
||||
}
|
||||
saveTabs(tabs.value, activeTabId.value);
|
||||
}
|
||||
|
||||
function findTabByIdentity(connectionId: string, database: string, title: string, mode: QueryTab["mode"], schema?: string) {
|
||||
return tabs.value.find((tab) => tab.connectionId === connectionId && tab.database === database && tab.title === title && tab.mode === mode && (tab.schema || "") === (schema || ""));
|
||||
}
|
||||
@@ -2319,6 +2331,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
closeTab,
|
||||
forceClosePendingTab,
|
||||
cancelClosePendingTab,
|
||||
flushPendingPersist,
|
||||
saveAndClosePendingTab,
|
||||
isTabDirty,
|
||||
markTabClean,
|
||||
|
||||
@@ -647,6 +647,16 @@ mod tests {
|
||||
use crate::database_export::{clear_export_cancelled, set_export_cancelled};
|
||||
use crate::xlsx_export::{build_xlsx_workbook, XlsxWorksheetData};
|
||||
use serde_json::json;
|
||||
use std::io::Read;
|
||||
|
||||
/// Read and decompress a single entry from an in-memory XLSX (ZIP) buffer.
|
||||
fn read_zip_entry(bytes: &[u8], path: &str) -> String {
|
||||
let mut archive = zip::ZipArchive::new(std::io::Cursor::new(bytes.to_vec())).expect("open xlsx as zip archive");
|
||||
let mut entry = archive.by_name(path).unwrap_or_else(|_| panic!("missing zip entry: {path}"));
|
||||
let mut content = String::new();
|
||||
entry.read_to_string(&mut content).expect("read zip entry");
|
||||
content
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Helper: check that two CSV strings are equivalent by splitting lines
|
||||
@@ -766,15 +776,16 @@ mod tests {
|
||||
],
|
||||
};
|
||||
let workbook = build_xlsx_workbook(&data).expect("XLSX build should succeed");
|
||||
let text = String::from_utf8_lossy(&workbook);
|
||||
|
||||
assert_eq!(workbook[0], 0x50, "Should be a ZIP (PK) archive");
|
||||
assert_eq!(workbook[1], 0x4b);
|
||||
assert!(text.contains("[Content_Types].xml"));
|
||||
assert!(text.contains("xl/worksheets/sheet1.xml"));
|
||||
assert!(text.contains("name=\"employees\""));
|
||||
assert!(text.contains("<v>75000.5</v>"));
|
||||
assert!(text.contains("Alice"));
|
||||
|
||||
// Entries are Deflate-compressed; assert on their decompressed contents.
|
||||
let workbook_xml = read_zip_entry(&workbook, "xl/workbook.xml");
|
||||
let sheet = read_zip_entry(&workbook, "xl/worksheets/sheet1.xml");
|
||||
assert!(workbook_xml.contains("name=\"employees\""));
|
||||
assert!(sheet.contains("<v>75000.5</v>"));
|
||||
assert!(sheet.contains("Alice"));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@@ -32,6 +32,7 @@ test("serializes unsaved query tabs with editor context", () => {
|
||||
schema: "public",
|
||||
sql: "select * from users",
|
||||
savedSqlId: undefined,
|
||||
externalSqlPath: undefined,
|
||||
pinned: true,
|
||||
mode: "query",
|
||||
objectBrowser: undefined,
|
||||
|
||||
@@ -119,8 +119,7 @@ test("external SQL file paths persist with open query tabs", async () => {
|
||||
const tabId = store.createTab("conn-1", "db", "draft.sql");
|
||||
store.updateSql(tabId, "select 1;");
|
||||
store.linkExternalSqlPath(tabId, "/tmp/draft.sql", "draft.sql");
|
||||
|
||||
await waitFor(() => !!globalThis.localStorage.getItem("dbx-open-tabs"), 1000);
|
||||
store.flushPendingPersist();
|
||||
|
||||
setActivePinia(createPinia());
|
||||
store = useQueryStore();
|
||||
|
||||
Reference in New Issue
Block a user