added some more tests
This commit is contained in:
parent
20a0fc679b
commit
04b55e02fb
5 changed files with 168 additions and 47 deletions
49
src/features/source/source.spec.ts
Normal file
49
src/features/source/source.spec.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { describe, expect } from "vitest";
|
||||
import { createSource } from "./source";
|
||||
import { it } from "~/test-helpers";
|
||||
import { testEffect } from "@solidjs/testing-library";
|
||||
import { createEffect, createSignal } from "solid-js";
|
||||
|
||||
describe('Source', () => {
|
||||
describe('Source', () => {
|
||||
it('should return a `Source`', () => {
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
const actual = createSource('');
|
||||
|
||||
// Assert
|
||||
expect(actual.out).toBe('');
|
||||
});
|
||||
|
||||
it('should transform the input format to output format', () => {
|
||||
// Arrange
|
||||
const given = '**text**\n';
|
||||
const expected = '<p><strong>text</strong></p>';
|
||||
|
||||
// Act
|
||||
const actual = createSource(given);
|
||||
|
||||
// Assert
|
||||
expect(actual.out).toBe(expected);
|
||||
});
|
||||
|
||||
it('should contain query results', () => {
|
||||
// Arrange
|
||||
const expected: [number, number][] = [[8, 9], [12, 13], [15, 16]];
|
||||
const source = createSource('this is a seachable string');
|
||||
|
||||
// Act
|
||||
source.query = 'a';
|
||||
|
||||
// Assert
|
||||
return testEffect(done => {
|
||||
createEffect(() => {
|
||||
expect(source.queryResults).toEqual(expected);
|
||||
|
||||
done()
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -37,16 +37,12 @@ const inToOutProcessor = unified().use(remarkParse).use(remarkRehype).use(rehype
|
|||
const outToInProcessor = unified().use(rehypeParse).use(rehypeRemark).use(remarkStringify, { bullet: '-' });
|
||||
|
||||
export function createSource(initalValue: string): Source {
|
||||
const [store, setStore] = createStore<SourceStore>({ in: initalValue, out: '', plain: '', query: '', metadata: { spellingErrors: [], grammarErrors: [], queryResults: [] } });
|
||||
|
||||
onMount(() => {
|
||||
const ast = inToOutProcessor.runSync(inToOutProcessor.parse(initalValue));
|
||||
const ast = inToOutProcessor.runSync(inToOutProcessor.parse(initalValue));
|
||||
const out = String(inToOutProcessor.stringify(ast));
|
||||
const plain = String(unified().use(plainTextStringify).stringify(ast));
|
||||
|
||||
setStore({
|
||||
out: String(inToOutProcessor.stringify(ast)),
|
||||
plain: String(unified().use(plainTextStringify).stringify(ast)),
|
||||
});
|
||||
});
|
||||
const [store, setStore] = createStore<SourceStore>({ in: initalValue, out, plain, query: '', metadata: { spellingErrors: [], grammarErrors: [], queryResults: [] } });
|
||||
|
||||
createEffect(() => {
|
||||
const value = store.plain;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue