<commit_before>import * as chai from 'chai';
import * as sinonChai from 'sinon-chai'
import { spy, stub } from 'sinon'

chai.use(sinonChai);
const expect = chai.expect

import { Game } from '../src/game'
import * as Parser from 'storyboard-lang'
import * as Actions from '../src/gameActions'

describe.skip("initialization", function() {
  describe("creating a nodeGraph", function() {
    var node, game: Game;
    beforeEach(function() {
      const story = `
        start: node
        # node
      `
      game = new Game(story)
    });

    it("should create a valid nodeGraph with the passed options", function() {
      expect(game.story.graph).to.exist;

      expect(game.story!.graph!.start).to.equal("1");
      expect(Object.keys(game.story!.graph!.nodes)).to.have.length(1);
    });

    it("shouldn't start the game", function() {
      expect(game.state.graph.currentNodeId).to.be.undefined;
    });
  });

  describe("creating a nodeBag", function() {
    it("should create a valid nodeBag with the passed nodes", function() {
      const story = `## node`
      const game = new Game(story)

      expect(game.story.bag).to.exist;
      expect(Object.keys(game.story.bag.nodes)).to.have.length(1)
    });
  });
});

describe("playing the node graph", function() {
  context("when starting the game", function() {
    it("should play the appropriate content via an output", function() {
      const game = new Game({
        "graph": {
          "start": "1",
          "nodes": {
            "1": {
              "nodeId": "1",
              "passages": [
                {
                  "passageId": "5",
                  "type": "text",
                  "content": "Hello World!"
                }
              ]
            }
          }
        }
      });

      const callback = spy();
      game.addOutput("text", callback);

      game.start();

      expect(callback).to.have.been.calledWith("Hello World!", "5");
    });
  });

  context("when a node has no passages", function() {
    let game: Game, callback: any;
    beforeEach(function() {
      game = new Game({
        "graph": {
          "start": "1",
          "nodes": {
            "1": {
              "nodeId": "1",
              "choices": [
                {
                  "nodeId": "2",
                  "predicate": {
                    "continue": { "eq": true }
                  }
                }
              ]
            },
            "2": {
              "nodeId": "2",
              "passages": [
                {
                  "passageId": "6",
                  "type": "text",
                  "content": "Goodbye World!"
                }
              ]
            }
          }
        }
      });

      callback = spy();
      game.addOutput("text", callback);
      game.start();

    });

    context("when a predicate has not yet been met", function() {
      it("should wait for the predicate to be met", function() {
        expect(callback).not.to.have.been.called
      })
    })

    context("when a predicate has been met", function() {
      it.only("should go immediately on", function() {
        game.receiveInput("continue", true)
        expect(callback).to.have.been.calledWith("Goodbye World!", "6");
      });
    })
  })

  context("when there are multiple passages", function() {
    describe("waiting for completion", function() {
     let first, second, game: Game, callback: any;
      beforeEach(function() {
        first = {
          "passageId": "2",
          "type": "text",
          "content": "First"
        }

        second = {
          "passageId": "3",
          "type": "text",
          "content": "Second"
        }

        game = new Game({
          "graph": {
            "start": "1",
            "nodes": {<commit_msg>Remove .only<commit_after>import * as chai from 'chai';
import * as sinonChai from 'sinon-chai'
import { spy, stub } from 'sinon'

chai.use(sinonChai);
const expect = chai.expect

import { Game } from '../src/game'
import * as Parser from 'storyboard-lang'
import * as Actions from '../src/gameActions'

describe.skip("initialization", function() {
  describe("creating a nodeGraph", function() {
    var node, game: Game;
    beforeEach(function() {
      const story = `
        start: node
        # node
      `
      game = new Game(story)
    });

    it("should create a valid nodeGraph with the passed options", function() {
      expect(game.story.graph).to.exist;

      expect(game.story!.graph!.start).to.equal("1");
      expect(Object.keys(game.story!.graph!.nodes)).to.have.length(1);
    });

    it("shouldn't start the game", function() {
      expect(game.state.graph.currentNodeId).to.be.undefined;
    });
  });

  describe("creating a nodeBag", function() {
    it("should create a valid nodeBag with the passed nodes", function() {
      const story = `## node`
      const game = new Game(story)

      expect(game.story.bag).to.exist;
      expect(Object.keys(game.story.bag.nodes)).to.have.length(1)
    });
  });
});

describe("playing the node graph", function() {
  context("when starting the game", function() {
    it("should play the appropriate content via an output", function() {
      const game = new Game({
        "graph": {
          "start": "1",
          "nodes": {
            "1": {
              "nodeId": "1",
              "passages": [
                {
                  "passageId": "5",
                  "type": "text",
                  "content": "Hello World!"
                }
              ]
            }
          }
        }
      });

      const callback = spy();
      game.addOutput("text", callback);

      game.start();

      expect(callback).to.have.been.calledWith("Hello World!", "5");
    });
  });

  context("when a node has no passages", function() {
    let game: Game, callback: any;
    beforeEach(function() {
      game = new Game({
        "graph": {
          "start": "1",
          "nodes": {
            "1": {
              "nodeId": "1",
              "choices": [
                {
                  "nodeId": "2",
                  "predicate": {
                    "continue": { "eq": true }
                  }
                }
              ]
            },
            "2": {
              "nodeId": "2",
              "passages": [
                {
                  "passageId": "6",
                  "type": "text",
                  "content": "Goodbye World!"
                }
              ]
            }
          }
        }
      });

      callback = spy();
      game.addOutput("text", callback);
      game.start();

    });

    context("when a predicate has not yet been met", function() {
      it("should wait for the predicate to be met", function() {
        expect(callback).not.to.have.been.called
      })
    })

    context("when a predicate has been met", function() {
      it("should go immediately on", function() {
        game.receiveInput("continue", true)
        expect(callback).to.have.been.calledWith("Goodbye World!", "6");
      });
    })
  })

  context("when there are multiple passages", function() {
    describe("waiting for completion", function() {
     let first, second, game: Game, callback: any;
      beforeEach(function() {
        first = {
          "passageId": "2",
          "type": "text",
          "content": "First"
        }

        second = {
          "passageId": "3",
          "type": "text",
          "content": "Second"
        }

        game = new Game({
          "graph": {
            "start": "1",
            "nodes": {
{'fraction_non_alphanumeric': 0.15473684210526314, 'fraction_numerical': 0.005, 'mean_word_length': 1.6282849239280774, 'pattern_counts': {'":': 68, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1503871', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2132, 'n_words': 525}