Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grgbkr committed Dec 28, 2024
1 parent 776a685 commit c90b4f0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions packages/zero-solid/src/solid-view.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {expect, test} from 'vitest';
import {resolver} from '@rocicorp/resolver';
import {MemorySource} from '../../zql/src/ivm/memory-source.js';
import {SolidView, solidViewFactory} from './solid-view.js';
import type {Query, Smash} from '../../zql/src/query/query.js';
Expand All @@ -24,6 +25,8 @@ test('basics', () => {
{a: 2, b: 'b'},
]);

expect(view.resultType).toEqual('complete');

ms.push({row: {a: 3, b: 'c'}, type: 'add'});

expect(view.data).toEqual([
Expand Down Expand Up @@ -71,6 +74,39 @@ test('single-format', () => {
expect(view.data).toEqual(undefined);
});

test('queryComplete promise', async () => {
const ms = new MemorySource(
'table',
{a: {type: 'number'}, b: {type: 'string'}},
['a'],
);
ms.push({row: {a: 1, b: 'a'}, type: 'add'});
ms.push({row: {a: 2, b: 'b'}, type: 'add'});

const queryCompleteResolver = resolver<true>();

const view = new SolidView(
ms.connect([
['b', 'asc'],
['a', 'asc'],
]),
undefined,
undefined,
queryCompleteResolver.promise,
);

expect(view.data).toEqual([
{a: 1, b: 'a'},
{a: 2, b: 'b'},
]);

expect(view.resultType).toEqual('unknown');

queryCompleteResolver.resolve(true);
await 1;
expect(view.resultType).toEqual('complete');
});

type TestSchema = {
tableName: 'test';
columns: {
Expand Down Expand Up @@ -114,6 +150,8 @@ test('factory', () => {
]),
{singular: false, relationships: {}},
onDestroy,
() => undefined,
true,
);
expect(view).toBeDefined();
expect(onDestroyCalled).false;
Expand Down
4 changes: 2 additions & 2 deletions packages/zero-solid/src/solid-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class SolidView<V extends View> implements Output {
input: Input,
format: Format = {singular: false, relationships: {}},
onDestroy: () => void = () => {},
queryComplete: true | Promise<true>,
queryComplete: true | Promise<true> = true,
) {
this.#input = input;
this.#format = format;
Expand All @@ -41,7 +41,7 @@ export class SolidView<V extends View> implements Output {
'': format.singular ? undefined : [],
});
[this.#resultTypeStore, this.#setResultType] = createStore({
resultType: queryComplete ? 'complete' : 'unknown',
resultType: queryComplete === true ? 'complete' : 'unknown',
});
input.setOutput(this);

Expand Down

0 comments on commit c90b4f0

Please sign in to comment.