Add mocha tests and fix forum logic
This commit is contained in:
		
							parent
							
								
									f475742cbf
								
							
						
					
					
						commit
						e26afa1eb4
					
				| 
						 | 
					@ -145,8 +145,8 @@ export class Forum extends ReputationHolder {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (params.referenceChainLimit === null || depth <= params.referenceChainLimit) {
 | 
					    if (params.referenceChainLimit === null || depth <= params.referenceChainLimit) {
 | 
				
			||||||
      for (const citationEdge of this.posts.getEdges(CITATION, post)) {
 | 
					      for (const citationEdge of postVertex.getEdges(CITATION, true)) {
 | 
				
			||||||
        const { to: citedPostVertex, data: { weight } } = citationEdge;
 | 
					        const { to: citedPostVertex, weight } = citationEdge;
 | 
				
			||||||
        const citedPost = citedPostVertex.data;
 | 
					        const citedPost = citedPostVertex.data;
 | 
				
			||||||
        let outboundAmount = weight * increment;
 | 
					        let outboundAmount = weight * increment;
 | 
				
			||||||
        const balance = this.posts.getEdge(BALANCE, postVertex, citedPostVertex)?.data || 0;
 | 
					        const balance = this.posts.getEdge(BALANCE, postVertex, citedPostVertex)?.data || 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -127,7 +127,8 @@ export class Scene {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  withFlowchart({ direction = 'BT' } = {}) {
 | 
					  withFlowchart({ direction = 'BT' } = {}) {
 | 
				
			||||||
    const box = this.topSection.addBox('Flowchart').addClass('padded');
 | 
					    const box = this.topSection.addBox('Flowchart').addClass('padded');
 | 
				
			||||||
    const logBox = this.topSection.addBox('Flowchart text').addClass('dim');
 | 
					    this.box.addBox('Spacer').setInnerHTML(' ');
 | 
				
			||||||
 | 
					    const logBox = this.box.addBox('Flowchart text').addClass('dim');
 | 
				
			||||||
    this.flowchart = new MermaidDiagram(box, logBox);
 | 
					    this.flowchart = new MermaidDiagram(box, logBox);
 | 
				
			||||||
    this.flowchart.log(`graph ${direction}`, false);
 | 
					    this.flowchart.log(`graph ${direction}`, false);
 | 
				
			||||||
    return this;
 | 
					    return this;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,5 +21,6 @@
 | 
				
			||||||
    <li><a href="./tests/wdag.test.html">WDAG</a></li>
 | 
					    <li><a href="./tests/wdag.test.html">WDAG</a></li>
 | 
				
			||||||
    <li><a href="./tests/debounce.test.html">Debounce</a></li>
 | 
					    <li><a href="./tests/debounce.test.html">Debounce</a></li>
 | 
				
			||||||
    <li><a href="./tests/flowchart.test.html">Flowchart</a></li>
 | 
					    <li><a href="./tests/flowchart.test.html">Flowchart</a></li>
 | 
				
			||||||
 | 
					    <li><a href="./tests/mocha.test.html">Mocha</a></li>
 | 
				
			||||||
  </ul>
 | 
					  </ul>
 | 
				
			||||||
</body>
 | 
					</body>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,8 @@
 | 
				
			||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js" integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
 | 
					<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js" integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
 | 
				
			||||||
<script src="https://unpkg.com/chai/chai.js"></script>
 | 
					<script src="https://unpkg.com/chai/chai.js"></script>
 | 
				
			||||||
<script src="https://unpkg.com/mocha/mocha.js"></script>
 | 
					<script src="https://unpkg.com/mocha/mocha.js"></script>
 | 
				
			||||||
<script class="mocha-init">
 | 
					<script type="module" src="./scripts/forum.test.js"></script>
 | 
				
			||||||
 | 
					<script defer class="mocha-init">
 | 
				
			||||||
  mocha.setup({
 | 
					  mocha.setup({
 | 
				
			||||||
    ui: 'bdd',
 | 
					    ui: 'bdd',
 | 
				
			||||||
    globals: ['scene', 'bench', 'forum', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
 | 
					    globals: ['scene', 'bench', 'forum', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
 | 
				
			||||||
| 
						 | 
					@ -20,7 +21,7 @@
 | 
				
			||||||
  mocha.checkLeaks();
 | 
					  mocha.checkLeaks();
 | 
				
			||||||
  chai.should();
 | 
					  chai.should();
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
<script type="module" src="./scripts/forum.test.js"></script>
 | 
					<script defer class="mocha-exec">
 | 
				
			||||||
<script class="mocha-exec">
 | 
					  // TODO: Weird race condition -- resolve this in a better way
 | 
				
			||||||
  mocha.run();
 | 
					  setTimeout(() => mocha.run(), 1000);
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,8 +10,6 @@ import params from '../../params.js';
 | 
				
			||||||
const DEFAULT_DELAY_MS = 1;
 | 
					const DEFAULT_DELAY_MS = 1;
 | 
				
			||||||
const POOL_DURATION_MS = 50;
 | 
					const POOL_DURATION_MS = 50;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let rootElement;
 | 
					 | 
				
			||||||
let rootBox;
 | 
					 | 
				
			||||||
let scene;
 | 
					let scene;
 | 
				
			||||||
let forum;
 | 
					let forum;
 | 
				
			||||||
let bench;
 | 
					let bench;
 | 
				
			||||||
| 
						 | 
					@ -55,11 +53,13 @@ async function addPost(author, fee, citations = []) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function setup() {
 | 
					async function setup() {
 | 
				
			||||||
  rootElement = document.getElementById('scene');
 | 
					  const rootElement = document.getElementById('scene');
 | 
				
			||||||
  rootBox = new Box('rootBox', rootElement).flex();
 | 
					  const rootBox = new Box('rootBox', rootElement).flex();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  scene = (window.scene = new Scene('Forum test', rootBox));
 | 
					  scene = (window.scene = new Scene('Forum test', rootBox));
 | 
				
			||||||
  scene.withSequenceDiagram();
 | 
					  scene.withSequenceDiagram();
 | 
				
			||||||
 | 
					  scene.withFlowchart();
 | 
				
			||||||
 | 
					  scene.withTable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  scene.addDisplayValue('c3. stakeForAuthor').set(params.stakeForAuthor);
 | 
					  scene.addDisplayValue('c3. stakeForAuthor').set(params.stakeForAuthor);
 | 
				
			||||||
  scene.addDisplayValue('q2. revaluationLimit').set(params.revaluationLimit);
 | 
					  scene.addDisplayValue('q2. revaluationLimit').set(params.revaluationLimit);
 | 
				
			||||||
| 
						 | 
					@ -74,10 +74,6 @@ async function setup() {
 | 
				
			||||||
  experts = (window.experts = []);
 | 
					  experts = (window.experts = []);
 | 
				
			||||||
  posts = (window.posts = []);
 | 
					  posts = (window.posts = []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  forum.posts.withFlowchart();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  scene.withTable();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  await newExpert();
 | 
					  await newExpert();
 | 
				
			||||||
  // await newExpert();
 | 
					  // await newExpert();
 | 
				
			||||||
  // await newExpert();
 | 
					  // await newExpert();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,19 +5,36 @@ import { WDAG } from '../../classes/wdag.js';
 | 
				
			||||||
const rootElement = document.getElementById('scene');
 | 
					const rootElement = document.getElementById('scene');
 | 
				
			||||||
const rootBox = new Box('rootBox', rootElement).flex();
 | 
					const rootBox = new Box('rootBox', rootElement).flex();
 | 
				
			||||||
window.scene = new Scene('WDAG test', rootBox);
 | 
					window.scene = new Scene('WDAG test', rootBox);
 | 
				
			||||||
const graph = (window.graph = new WDAG(window.scene).withFlowchart());
 | 
					describe('Query the graph', () => {
 | 
				
			||||||
const v = (window.v = []);
 | 
					  let graph;
 | 
				
			||||||
function addVertex() {
 | 
					  before(() => {
 | 
				
			||||||
  const vertex = graph.addVertex({ seq: window.v.length });
 | 
					    graph = (window.graph = new WDAG(window.scene)).withFlowchart();
 | 
				
			||||||
  v.push(vertex);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
addVertex();
 | 
					 | 
				
			||||||
addVertex();
 | 
					 | 
				
			||||||
addVertex();
 | 
					 | 
				
			||||||
addVertex();
 | 
					 | 
				
			||||||
addVertex();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
graph.addEdge('e1', 0, 1, 1);
 | 
					    graph.addVertex({});
 | 
				
			||||||
graph.addEdge('e1', 2, 1, 0.5);
 | 
					    graph.addVertex({});
 | 
				
			||||||
graph.addEdge('e1', 3, 1, 0.25);
 | 
					    graph.addVertex({});
 | 
				
			||||||
graph.addEdge('e1', 1, 4, 0.125);
 | 
					    graph.addVertex({});
 | 
				
			||||||
 | 
					    graph.addVertex({});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    graph.addEdge('e1', 0, 1, 1);
 | 
				
			||||||
 | 
					    graph.addEdge('e1', 2, 1, 0.5);
 | 
				
			||||||
 | 
					    graph.addEdge('e1', 3, 1, 0.25);
 | 
				
			||||||
 | 
					    graph.addEdge('e1', 1, 4, 0.125);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  it('can query for all e1 edges', () => {
 | 
				
			||||||
 | 
					    const edges = graph.getEdges('e1');
 | 
				
			||||||
 | 
					    edges.should.have.length(4);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  it('can query for all e1 edges from a particular vertex', () => {
 | 
				
			||||||
 | 
					    const edges = graph.getEdges('e1', 2);
 | 
				
			||||||
 | 
					    edges.map(({ from, to, weight }) => [from.id, to.id, weight]).should.have.deep.members([[2, 1, 0.5]]);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  it('can query for all e1 edges to a particular vertex', () => {
 | 
				
			||||||
 | 
					    const edges = graph.getEdges('e1', null, 1);
 | 
				
			||||||
 | 
					    edges.map(({ from, to, weight }) => [from.id, to.id, weight]).should.have.deep.members([
 | 
				
			||||||
 | 
					      [0, 1, 1],
 | 
				
			||||||
 | 
					      [2, 1, 0.5],
 | 
				
			||||||
 | 
					      [3, 1, 0.25],
 | 
				
			||||||
 | 
					    ]);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,29 @@
 | 
				
			||||||
<!DOCTYPE html>
 | 
					<!DOCTYPE html>
 | 
				
			||||||
<head>
 | 
					<head>
 | 
				
			||||||
  <title>Forum WDAG</title>
 | 
					  <title>WDAG test</title>
 | 
				
			||||||
 | 
					  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
 | 
					  <link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
 | 
				
			||||||
  <link type="text/css" rel="stylesheet" href="../index.css" />
 | 
					  <link type="text/css" rel="stylesheet" href="../index.css" />
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
 | 
					  <div id="mocha"></div>
 | 
				
			||||||
  <div id="scene"></div>
 | 
					  <div id="scene"></div>
 | 
				
			||||||
</body>
 | 
					</body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js" integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
 | 
				
			||||||
 | 
					<script src="https://unpkg.com/chai/chai.js"></script>
 | 
				
			||||||
 | 
					<script src="https://unpkg.com/mocha/mocha.js"></script>
 | 
				
			||||||
 | 
					<script defer class="mocha-init">
 | 
				
			||||||
 | 
					  mocha.setup({
 | 
				
			||||||
 | 
					    ui: 'bdd',
 | 
				
			||||||
 | 
					    globals: ['scene', 'bench', 'forum', 'experts', 'posts', 'graph', '__REACT_DEVTOOLS_*'],
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					  mocha.checkLeaks();
 | 
				
			||||||
 | 
					  chai.should();
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
<script type="module" src="./scripts/wdag.test.js"></script>
 | 
					<script type="module" src="./scripts/wdag.test.js"></script>
 | 
				
			||||||
 | 
					<script defer class="mocha-exec">
 | 
				
			||||||
 | 
					  // TODO: Weird race condition -- resolve this in a better way
 | 
				
			||||||
 | 
					  setTimeout(() => mocha.run(), 1000);
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue