49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { expect, test } from "../support/browser/strict-browser-test.ts";
|
|
|
|
test("executes the storage durability adapter against the real browser StorageManager capability", async ({
|
|
page,
|
|
}) => {
|
|
await page.goto("/");
|
|
const observation = await page.evaluate(async () => {
|
|
const modulePath =
|
|
"/src/adapters/browser-file-storage/storage-manager-adapter.ts";
|
|
const { createStorageDurabilityAdapter } = await import(
|
|
/* @vite-ignore */ modulePath
|
|
);
|
|
const hasStorageManager = navigator.storage !== undefined;
|
|
const adapter = createStorageDurabilityAdapter(navigator.storage);
|
|
return {
|
|
hasStorageManager,
|
|
result: await adapter.inspect(),
|
|
};
|
|
});
|
|
|
|
if (!observation.hasStorageManager) {
|
|
expect(observation.result).toEqual({
|
|
ok: false,
|
|
error: {
|
|
code: "UNSUPPORTED",
|
|
operation: "STORAGE_ESTIMATE",
|
|
retryable: false,
|
|
recovery: "ONLINE_ONLY",
|
|
},
|
|
});
|
|
return;
|
|
}
|
|
|
|
expect(observation.result.ok).toBe(true);
|
|
if (observation.result.ok) {
|
|
expect(["UNKNOWN", "NORMAL", "PRESSURE", "CRITICAL"]).toContain(
|
|
observation.result.value.pressure,
|
|
);
|
|
expect(
|
|
observation.result.value.usageBytes === null ||
|
|
observation.result.value.usageBytes >= 0,
|
|
).toBe(true);
|
|
expect(
|
|
observation.result.value.quotaBytes === null ||
|
|
observation.result.value.quotaBytes >= 0,
|
|
).toBe(true);
|
|
}
|
|
});
|