dao-governance-framework/forum-network/public/tests/forum.html

82 lines
2.4 KiB
HTML

<!DOCTYPE html>
<head>
<title>Forum test</title>
<link type="text/css" rel="stylesheet" href="/index.css" />
</head>
<body>
<div id="forum-test"></div>
</body>
<script type="module">
import { Box } from "/classes/box.js";
import { Scene } from "/classes/scene.js";
import { Member } from "/classes/member.js";
import { Bench } from "/classes/bench.js";
import { Business } from "/classes/business.js";
import { Availability } from "/classes/availability.js";
import { delay } from "/util.js";
import { Forum } from "/classes/forum.js";
import { Public } from "/classes/public.js";
import { PostContent } from "/classes/post.js";
const DELAY_INTERVAL = 500;
const rootElement = document.getElementById("forum-test");
const rootBox = new Box("rootBox", rootElement).flex();
const scene = (window.scene = new Scene("Forum test", rootBox).log(
"sequenceDiagram"
));
const members = (window.members = []);
const newMember = async () => {
const index = members.length;
const name = `Member${index + 1}`;
const member = await new Member(name, scene).initialize();
members.push(member);
return member;
};
const posts = (window.posts = []);
const newPost = async (author, content, citations) => {
const postContent = new PostContent({ hello: "there" });
const postId = await member1.submitPost(forum, postContent1);
return postId;
};
const member1 = await newMember();
const member2 = await newMember();
await newMember();
const bench = (window.bench = new Bench("Bench", scene));
const forum = (window.forum = new Forum(bench, "Forum", scene));
const updateDisplayValues = async () => {
for (const member of members) {
member.setValue(
"rep",
bench.reputations.getTokens(member.reputationPublicKey)
);
}
bench.setValue("total rep", bench.getTotalReputation());
await scene.renderSequenceDiagram();
};
const updateDisplayValuesAndDelay = async () => {
await updateDisplayValues();
await delay(DELAY_INTERVAL);
};
await updateDisplayValuesAndDelay();
const postId1 = await member1.submitPost(
forum,
new PostContent({ hello: "there" })
);
await updateDisplayValuesAndDelay();
const postId2 = await member1.submitPost(
forum,
new PostContent({ hello: "to you as well" }).addCitation(postId1, 0.5)
);
await updateDisplayValuesAndDelay();
</script>