test(web-chat): remove tests

Not really used and some issues with jest.
This commit is contained in:
fryorcraken.eth 2022-09-02 14:29:28 +10:00
parent e4c001d901
commit 5b82c8e963
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 1 additions and 100 deletions

View File

@ -31,7 +31,7 @@
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test:unit": "react-scripts test", "test:unit": "exit 0",
"fix": "run-s fix:*", "fix": "run-s fix:*",
"test": "run-s build test:*", "test": "run-s build test:*",
"test:lint": "eslint src --ext .ts --ext .tsx", "test:lint": "eslint src --ext .ts --ext .tsx",

View File

@ -1,30 +0,0 @@
import WakuMock, { Message } from "./WakuMock";
test("Messages are emitted", async () => {
const wakuMock = await WakuMock.create();
let message: Message;
wakuMock.on("message", (msg) => {
message = msg;
});
await new Promise((resolve) => setTimeout(resolve, 2000));
// @ts-ignore
expect(message.message).toBeDefined();
});
test("Messages are sent", async () => {
const wakuMock = await WakuMock.create();
const text = "This is a message.";
let message: Message;
wakuMock.on("message", (msg) => {
message = msg;
});
await wakuMock.send(text);
// @ts-ignore
expect(message.message).toEqual(text);
});

View File

@ -1,69 +0,0 @@
class EventEmitter<T> {
public callbacks: { [key: string]: Array<(data: T) => void> };
constructor() {
this.callbacks = {};
}
on(event: string, cb: (data: T) => void) {
if (!this.callbacks[event]) this.callbacks[event] = [];
this.callbacks[event].push(cb);
}
emit(event: string, data: T) {
let cbs = this.callbacks[event];
if (cbs) {
cbs.forEach((cb) => cb(data));
}
}
}
export interface Message {
timestamp: Date;
handle: string;
message: string;
}
export default class WakuMock extends EventEmitter<Message> {
index: number;
intervalId?: number | NodeJS.Timeout;
private constructor() {
super();
this.index = 0;
}
public static async create(): Promise<WakuMock> {
await new Promise((resolve) => setTimeout(resolve, 500));
const wakuMock = new WakuMock();
wakuMock.startInterval();
return wakuMock;
}
public async send(message: string): Promise<void> {
const timestamp = new Date();
const handle = "me";
this.emit("message", {
timestamp,
handle,
message,
});
}
private startInterval() {
if (this.intervalId === undefined) {
this.intervalId = setInterval(this.emitMessage.bind(this), 1000);
}
}
private emitMessage() {
const handle = "you";
const timestamp = new Date();
this.emit("message", {
timestamp,
handle,
message: `This is message #${this.index++}.`,
});
}
}