Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/kristianbinau/SimpleHistory. A simple history library for Deno, Node.js and the browser. Build with Deno & Typescript. www.npmjs.com/package/@kristianbinau/simple-history
Something went wrong. Try again.
3.0 kB · 130 lines
TypeScript
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";import { History } from "./mod.ts";
const testValues = [ { typeName: "number", originalValue: 42, newValue: 43, newOriginalValue: 44, }, { typeName: "string", originalValue: "42", newValue: "43", newOriginalValue: "44", }, { typeName: "boolean", originalValue: true, newValue: false, newOriginalValue: true, }, { typeName: "array", originalValue: [42], newValue: [42, 43], newOriginalValue: [42, 43, 44], }, { typeName: "object", originalValue: { a: 42 }, newValue: { a: 42, b: 43 }, newOriginalValue: { a: 42, b: 43, c: 44 }, },];
for (const testValue of testValues) { const typeName = testValue.typeName; const originalValue = testValue.originalValue; const newValue = testValue.newValue; const newOriginalValue = testValue.newOriginalValue;
Deno.test(`Getter should work with ${typeName}`, () => { const history = new History(originalValue);
assertEquals(history.value, originalValue); });
Deno.test(`Setter should work with ${typeName}`, () => { const history = new History(originalValue);
history.value = newValue;
assertEquals(history.value, newValue); });
Deno.test(`Undo should work with ${typeName}`, () => { const history = new History(originalValue);
history.value = newValue;
assertEquals(history.value, newValue);
assertEquals(history.undo(), true);
assertEquals(history.value, originalValue);
assertEquals(history.undo(), false);
assertEquals(history.value, originalValue); });
Deno.test(`Redo should work with ${typeName}`, () => { const history = new History(originalValue);
history.value = newValue;
assertEquals(history.value, newValue);
assertEquals(history.undo(), true);
assertEquals(history.value, originalValue);
assertEquals(history.redo(), true);
assertEquals(history.value, newValue);
assertEquals(history.redo(), false);
assertEquals(history.value, newValue); });
Deno.test(`Has changed should work with ${typeName}`, () => { const history = new History(originalValue);
assertEquals(history.hasChanged(), false);
history.value = newValue;
assertEquals(history.hasChanged(), true);
history.undo();
assertEquals(history.hasChanged(), false); });
Deno.test(`Reset should work with ${typeName}`, () => { const history = new History(originalValue);
history.value = newValue;
assertEquals(history.value, newValue);
history.reset();
assertEquals(history.value, originalValue); });
Deno.test(`SetOriginal should work with ${typeName}`, () => { const history = new History(originalValue);
history.value = newValue;
assertEquals(history.value, newValue);
history.setOriginal(newOriginalValue);
assertEquals(history.value, newOriginalValue); });}