<commit_before>import fs from 'fs';

import expect from '../../expect';

import DmnModdle from '../../../lib';

describe('dmn-moddle - read', function() {

  let moddle;

  beforeEach(function() {
    moddle = new DmnModdle();
  });

  async function read(fileName, root = 'dmn:Definitions') {
    return new Promise((resolve, reject) => {
      const file = fs.readFileSync(fileName, 'utf8');

      moddle.fromXML(file, root, (err, definitions) => {
        if (err) {
          reject(err);
        }

        resolve(definitions);
      });
    });
  }

  describe('DMN', function() {

    it('Decision', async function() {

      // given
      const expected = {
        $type: 'dmn:Decision',
        id: 'Decision_1',
        name: 'Decision'
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmn/decision.dmn');

      // then
      expect(definitions.get('drgElement')[ 0 ]).to.jsonEqual(expected);
    });

    it('dmn:Decision#decisionLogic', async function() {

      // given
      const expected = {
        $type: 'dmn:Decision',
        id: 'Decision_1',
        name: 'Decision',
        decisionLogic: {
          $type: 'dmn:LiteralExpression',
          id: 'LiteralExpression_1'
        }
      };

      // when
      const decision = await read('test/fixtures/dmn/dmn/decision-decisionLogic.part.dmn', 'dmn:Decision');

      // then
      expect(decision).to.jsonEqual(expected);
    });

    it('dmn:InputData', async function() {

      // given
      const expected = {
        $type: 'dmn:InputData',
        id: 'InputData_1',
        name: 'InputData'
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmn/input-data.dmn');

      // then
      expect(definitions.get('drgElement')[ 0 ]).to.jsonEqual(expected);
    });

    it('InformationRequirement', async function() {

      // given
      const expected = {
        $type: 'dmn:InformationRequirement',
        id: 'InformationRequirement_1',
        requiredInput: {
          $type: 'dmn:DMNElementReference',
          href: '#InputData_1'
        }
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmn/information-requirement.dmn');

      // then
      expect(definitions.get('drgElement')[ 0 ].get('informationRequirement')[ 0 ]).to.jsonEqual(expected);
    });

    it('BusinessKnowledgeModel', async function() {

      // when
      const bkm = await read(
        'test/fixtures/dmn/dmn/business-knowledge-model.part.dmn',
        'dmn:BusinessKnowledgeModel'
      );

      // then
      expect(bkm).to.jsonEqual({
        $type: 'dmn:BusinessKnowledgeModel',
        name: 'InstallmentCalculation',
        id: 'b_InstallmentCalculation',
        variable: {
          $type: 'dmn:InformationItem',
          name: 'InstallmentCalculation'
        },
        encapsulatedLogic: {
          $type: 'dmn:FunctionDefinition',
          formalParameter: [
            {
              $type: 'dmn:InformationItem',
              typeRef: 'string',
              name: 'ProductType'
            },
            {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'Rate'
            },
            {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'Term'
            },
            {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'Amount'
            }
          ],
          context: {
            $type: 'dmn:Context'
          }
        }
      });
    });

    it('Context', async function() {

      // when
      const context = await read(
        'test/fixtures/dmn/dmn/context.part.dmn',
        'dmn:Context'
      );

      // then
      expect(context).to.jsonEqual({
        $type: 'dmn:Context',
        contextEntry: [
          {
            $type: 'dmn:ContextEntry',
            variable: {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'MonthlyFee'
            },
            value: {
              $type: 'dmn:LiteralExpression',
              text: 'if ProductType ="STANDARD LOAN" then 20.00 else if ProductType ="SPECIAL LOAN" then 25.00 else null'
            }
          },
          {
            $type: 'dmn:ContextEntry',
            variable: {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'MonthlyRepayment'
            },
            value: {
              $type: 'dmn:LiteralExpression',
              text: '(Amount *Rate/12) / (1 - (1 + Rate/12)**-Term)'
            }
          },
          {
            $type: 'dmn:ContextEntry',
            value: {
              $type: 'dmn:LiteralExpression',
              typeRef: 'number',
              text: 'MonthlyRepayment+MonthlyFee'
            }
          }
        ]
      });

    });

  });

  describe('DI', function() {

    it('Decision & DI', async function() {

      // given
      const expected = {
        $type: 'dmndi:DMNDI',
        diagrams: [
          {
            $type: 'dmndi:DMNDiagram',
            diagramElements: [
              {
                $type: 'dmndi:DMNShape',
                bounds: {
                  $type: 'dc:Bounds',
                  height: 80,
                  width: 180,
                  x: 100,
                  y: 100
                }
              }
            ]
          }
        ]
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/decision.dmn');

      // then
      expect(definitions.get('dmnDI')).to.jsonEqual(expected);
    });

    it('InputData & DI', async function() {

      // given
      const expected = {
        $type: 'dmndi:DMNDI',
        diagrams: [
          {
            $type: 'dmndi:DMNDiagram',
            diagramElements: [
              {
                $type: 'dmndi:DMNShape',
                bounds: {
                  $type: 'dc:Bounds',
                  height: 45,
                  width: 125,
                  x: 100,
                  y: 100
                }
              }
            ]
          }
        ]
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/input-data.dmn');

      // then
      expect(definitions.get('dmnDI')).to.jsonEqual(expected);
    });

    it('TextAnnotation & DI', async function() {

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/text-annotation.dmn');

      // then
      const artifact = definitions.get('artifact');

      expect(artifact).to.have.lengthOf(2);

      const textAnnotation = artifact[ 0 ];

      expect(textAnnotation).to.jsonEqual({
        $type: 'dmn:TextAnnotation',
        id: 'TextAnnotation_1',
        text: 'TextAnnotation_1'
      });

      const association = artifact[ 1 ];

      expect(association).to.jsonEqual({
        $type: 'dmn:Association',
        id: 'Association_1',
        sourceRef: {
          $type: 'dmn:DMNElementReference',
          href: '#Decision_1'
        },
        targetRef: {
          $type: 'dmn:DMNElementReference',
          href: '#TextAnnotation_1'
        }
      });
    });

    it('with label', async function() {

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/label.dmn');

      // then
      expect(definitions.get('dmnDI')).to.jsonEqual({
        $type: 'dmndi:DMNDI',
        diagrams: [
          {
            $type: 'dmndi:DMNDiagram',
            diagramElements: [
              {
                $type: 'dmndi:DMNShape',
                id: 'DMNShape_1',
                bounds: {
                  $type: 'dc:Bounds',
                  height: 80,
                  width: 180,
                  x: 100,
                  y: 100
                },
                label: {
                  $type: 'dmndi:DMNLabel',
                  text: {
                    $type: 'dmndi:Text',
                    text: 'Decision_1'
                  }
                }
              },
              {
                $type: 'dmndi:DMNShape',
                id: 'DMNShape_2',
                bounds: {
                  $type: 'dc:Bounds',
                  height: 45,
                  width: 125,
                  x: 127.5,
                  y: 300
                },
                label: {
                  $type: 'dmndi:DMNLabel',
                  text: {
                    $type: 'dmndi:Text',
                    text: 'InputData_1'
                  }
                }
              },
              {
                $type: 'dmndi:DMNEdge',
                id: 'DMNEdge_1',
                waypoint: [
                  {
                    $type: 'dc:Point',
                    x: 180,
                    y: 190
                  },
                  {
                    $type: 'dc:Point',
                    x: 180,
                    y: 300
                  }
                ],
                label: {
                  $type: 'dmndi:DMNLabel',
                  text: {
                    $type: 'dmndi:Text',
                    text: 'InformationRequirement_1'
                  }
                }
              }
            ]
          }
        ],
        styles: [
          {
            '$type': 'dmndi:DMNStyle',
            'id': 'SharedStyle_1',
            'fontFamily': 'arial,helvetica,sans-serif',
            'fontSize': 14,
            'fontBold': false,
            'fontItalic': false,
            'fontUnderline': false,
            'fontStrikeThrough': false
          }
        ]
      });
    });

    it('with size', async function() {

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/size.dmn');

      // then
      const diagram = definitions.get('dmnDI').diagrams[0];

      expect(diagram.size).to.jsonEqual({
        $type: 'dmndi:Size',
        height: 650.0,
        width: 650.0
      });
    });
  });

});
<commit_msg>test(read): prefix specs with type<commit_after>import fs from 'fs';

import expect from '../../expect';

import DmnModdle from '../../../lib';

describe('dmn-moddle - read', function() {

  let moddle;

  beforeEach(function() {
    moddle = new DmnModdle();
  });

  async function read(fileName, root = 'dmn:Definitions') {
    return new Promise((resolve, reject) => {
      const file = fs.readFileSync(fileName, 'utf8');

      moddle.fromXML(file, root, (err, definitions) => {
        if (err) {
          reject(err);
        }

        resolve(definitions);
      });
    });
  }

  describe('DMN', function() {

    it('dmn:Decision', async function() {

      // given
      const expected = {
        $type: 'dmn:Decision',
        id: 'Decision_1',
        name: 'Decision'
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmn/decision.dmn');

      // then
      expect(definitions.get('drgElement')[ 0 ]).to.jsonEqual(expected);
    });

    it('dmn:Decision#decisionLogic', async function() {

      // given
      const expected = {
        $type: 'dmn:Decision',
        id: 'Decision_1',
        name: 'Decision',
        decisionLogic: {
          $type: 'dmn:LiteralExpression',
          id: 'LiteralExpression_1'
        }
      };

      // when
      const decision = await read('test/fixtures/dmn/dmn/decision-decisionLogic.part.dmn', 'dmn:Decision');

      // then
      expect(decision).to.jsonEqual(expected);
    });

    it('dmn:InputData', async function() {

      // given
      const expected = {
        $type: 'dmn:InputData',
        id: 'InputData_1',
        name: 'InputData'
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmn/input-data.dmn');

      // then
      expect(definitions.get('drgElement')[ 0 ]).to.jsonEqual(expected);
    });

    it('dmn:InformationRequirement', async function() {

      // given
      const expected = {
        $type: 'dmn:InformationRequirement',
        id: 'InformationRequirement_1',
        requiredInput: {
          $type: 'dmn:DMNElementReference',
          href: '#InputData_1'
        }
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmn/information-requirement.dmn');

      // then
      expect(definitions.get('drgElement')[ 0 ].get('informationRequirement')[ 0 ]).to.jsonEqual(expected);
    });

    it('dmn:BusinessKnowledgeModel', async function() {

      // when
      const bkm = await read(
        'test/fixtures/dmn/dmn/business-knowledge-model.part.dmn',
        'dmn:BusinessKnowledgeModel'
      );

      // then
      expect(bkm).to.jsonEqual({
        $type: 'dmn:BusinessKnowledgeModel',
        name: 'InstallmentCalculation',
        id: 'b_InstallmentCalculation',
        variable: {
          $type: 'dmn:InformationItem',
          name: 'InstallmentCalculation'
        },
        encapsulatedLogic: {
          $type: 'dmn:FunctionDefinition',
          formalParameter: [
            {
              $type: 'dmn:InformationItem',
              typeRef: 'string',
              name: 'ProductType'
            },
            {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'Rate'
            },
            {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'Term'
            },
            {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'Amount'
            }
          ],
          context: {
            $type: 'dmn:Context'
          }
        }
      });
    });

    it('dmn:Context', async function() {

      // when
      const context = await read(
        'test/fixtures/dmn/dmn/context.part.dmn',
        'dmn:Context'
      );

      // then
      expect(context).to.jsonEqual({
        $type: 'dmn:Context',
        contextEntry: [
          {
            $type: 'dmn:ContextEntry',
            variable: {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'MonthlyFee'
            },
            value: {
              $type: 'dmn:LiteralExpression',
              text: 'if ProductType ="STANDARD LOAN" then 20.00 else if ProductType ="SPECIAL LOAN" then 25.00 else null'
            }
          },
          {
            $type: 'dmn:ContextEntry',
            variable: {
              $type: 'dmn:InformationItem',
              typeRef: 'number',
              name: 'MonthlyRepayment'
            },
            value: {
              $type: 'dmn:LiteralExpression',
              text: '(Amount *Rate/12) / (1 - (1 + Rate/12)**-Term)'
            }
          },
          {
            $type: 'dmn:ContextEntry',
            value: {
              $type: 'dmn:LiteralExpression',
              typeRef: 'number',
              text: 'MonthlyRepayment+MonthlyFee'
            }
          }
        ]
      });

    });

  });

  describe('DI', function() {

    it('dmn:Decision + DI', async function() {

      // given
      const expected = {
        $type: 'dmndi:DMNDI',
        diagrams: [
          {
            $type: 'dmndi:DMNDiagram',
            diagramElements: [
              {
                $type: 'dmndi:DMNShape',
                bounds: {
                  $type: 'dc:Bounds',
                  height: 80,
                  width: 180,
                  x: 100,
                  y: 100
                }
              }
            ]
          }
        ]
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/decision.dmn');

      // then
      expect(definitions.get('dmnDI')).to.jsonEqual(expected);
    });

    it('dmn:InputData + DI', async function() {

      // given
      const expected = {
        $type: 'dmndi:DMNDI',
        diagrams: [
          {
            $type: 'dmndi:DMNDiagram',
            diagramElements: [
              {
                $type: 'dmndi:DMNShape',
                bounds: {
                  $type: 'dc:Bounds',
                  height: 45,
                  width: 125,
                  x: 100,
                  y: 100
                }
              }
            ]
          }
        ]
      };

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/input-data.dmn');

      // then
      expect(definitions.get('dmnDI')).to.jsonEqual(expected);
    });

    it('dmn:TextAnnotation + DI', async function() {

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/text-annotation.dmn');

      // then
      const artifact = definitions.get('artifact');

      expect(artifact).to.have.lengthOf(2);

      const textAnnotation = artifact[ 0 ];

      expect(textAnnotation).to.jsonEqual({
        $type: 'dmn:TextAnnotation',
        id: 'TextAnnotation_1',
        text: 'TextAnnotation_1'
      });

      const association = artifact[ 1 ];

      expect(association).to.jsonEqual({
        $type: 'dmn:Association',
        id: 'Association_1',
        sourceRef: {
          $type: 'dmn:DMNElementReference',
          href: '#Decision_1'
        },
        targetRef: {
          $type: 'dmn:DMNElementReference',
          href: '#TextAnnotation_1'
        }
      });
    });

    it('dmndi:DMNLabel', async function() {

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/label.dmn');

      // then
      expect(definitions.get('dmnDI')).to.jsonEqual({
        $type: 'dmndi:DMNDI',
        diagrams: [
          {
            $type: 'dmndi:DMNDiagram',
            diagramElements: [
              {
                $type: 'dmndi:DMNShape',
                id: 'DMNShape_1',
                bounds: {
                  $type: 'dc:Bounds',
                  height: 80,
                  width: 180,
                  x: 100,
                  y: 100
                },
                label: {
                  $type: 'dmndi:DMNLabel',
                  text: {
                    $type: 'dmndi:Text',
                    text: 'Decision_1'
                  }
                }
              },
              {
                $type: 'dmndi:DMNShape',
                id: 'DMNShape_2',
                bounds: {
                  $type: 'dc:Bounds',
                  height: 45,
                  width: 125,
                  x: 127.5,
                  y: 300
                },
                label: {
                  $type: 'dmndi:DMNLabel',
                  text: {
                    $type: 'dmndi:Text',
                    text: 'InputData_1'
                  }
                }
              },
              {
                $type: 'dmndi:DMNEdge',
                id: 'DMNEdge_1',
                waypoint: [
                  {
                    $type: 'dc:Point',
                    x: 180,
                    y: 190
                  },
                  {
                    $type: 'dc:Point',
                    x: 180,
                    y: 300
                  }
                ],
                label: {
                  $type: 'dmndi:DMNLabel',
                  text: {
                    $type: 'dmndi:Text',
                    text: 'InformationRequirement_1'
                  }
                }
              }
            ]
          }
        ],
        styles: [
          {
            '$type': 'dmndi:DMNStyle',
            'id': 'SharedStyle_1',
            'fontFamily': 'arial,helvetica,sans-serif',
            'fontSize': 14,
            'fontBold': false,
            'fontItalic': false,
            'fontUnderline': false,
            'fontStrikeThrough': false
          }
        ]
      });
    });

    it('dmndi:Diagram with dmndi:Size', async function() {

      // when
      const definitions = await read('test/fixtures/dmn/dmndi/size.dmn');

      // then
      const diagram = definitions.get('dmnDI').diagrams[0];

      expect(diagram.size).to.jsonEqual({
        $type: 'dmndi:Size',
        height: 650.0,
        width: 650.0
      });
    });

  });

});
<|endoftext|>


<commit_before>process.env.NODE_ENV = 'test';
process.argv[2] = 'test';

var Queue = require('../../lib/queue');
var Step = require('step');
var exec = require('child_process').exec;
var path = require('path');
var fs = require('fs');

process.env.HOME = path.resolve(__dirname + '/../fixtures/files');

// Remove stale config file if present.
try { fs.unlinkSync(process.env.HOME + '/.tilemill.json'); }
catch (err) { if (err.code !== 'ENOENT') throw err }

// Load application.
require('../..');
var tilemill = require('bones').plugin;
tilemill.config.files = path.resolve(__dirname + '/../fixtures/files');
tilemill.config.examples = false;

var queue = new Queue(function(next, done) {
    var command = tilemill.start(function() {
        var remaining = 2;
        command.servers['Core'].close = (function(parent) { return function() {
            if (remaining-- === 1) done();
            return parent.apply(this, arguments);
        }})(command.servers['Core'].close);
        command.servers['Tile'].close = (function(parent) { return function() {
            if (remaining-- === 1) done();
            return parent.apply(this, arguments);
        }})(command.servers['Tile'].close);
        next(command);
    });
}, 1);
// @TODO:
// Not sure why this is necessary. tile.test.js doesn't seem to exit out
// despite both servers closing.
queue.on('empty', process.exit);

tilemill.commands.test.augment({
    bootstrap: function(parent, plugin, callback) {
        // Create a clean environment.
        var basedir = path.resolve(__dirname + '/..');
        var clean = '\
            rm -f ' + basedir + '/fixtures/files/app.db && \
            rm -rf ' + basedir + '/fixtures/files/project && \
            rm -rf ' + basedir + '/fixtures/files/data && \
            rm -rf ' + basedir + '/fixtures/files/export && \
            cp -R ' + basedir + '/fixtures/pristine/project ' + basedir + '/fixtures/files && \
            psql -d postgres -c "DROP DATABASE IF EXISTS tilemill_test;" && \
            createdb -E UTF8 -T template_postgis tilemill_test && \
            psql -d tilemill_test -f ' + basedir + '/fixtures/tilemill_test.sql';
        exec(clean, function(err) {
            if (err) throw err;
            console.warn('Initialized test fixture');
            parent.call(this, plugin, callback);
        }.bind(this));
    }
});

module.exports = queue.add;

<commit_msg>Insert postgis fixtures only once and prior to all tests.<commit_after>process.env.NODE_ENV = 'test';
process.argv[2] = 'test';

var Queue = require('../../lib/queue');
var Step = require('step');
var exec = require('child_process').exec;
var path = require('path');
var fs = require('fs');
var basedir = path.resolve(__dirname + '/..');

process.env.HOME = path.resolve(__dirname + '/../fixtures/files');

// Remove stale config file if present.
try { fs.unlinkSync(process.env.HOME + '/.tilemill.json'); }
catch (err) { if (err.code !== 'ENOENT') throw err }

// Load application.
require('../..');
var tilemill = require('bones').plugin;
tilemill.config.files = path.resolve(__dirname + '/../fixtures/files');
tilemill.config.examples = false;

var queue = new Queue(function(next, done) {
    // Allow bootstrap functions to be added to the queue.
    if (next.bootstrap) return next(done);

    var command = tilemill.start(function() {
        var remaining = 2;
        command.servers['Core'].close = (function(parent) { return function() {
            if (remaining-- === 1) done();
            return parent.apply(this, arguments);
        }})(command.servers['Core'].close);
        command.servers['Tile'].close = (function(parent) { return function() {
            if (remaining-- === 1) done();
            return parent.apply(this, arguments);
        }})(command.servers['Tile'].close);
        next(command);
    });
}, 1);
// @TODO:
// Not sure why this is necessary. tile.test.js doesn't seem to exit out
// despite both servers closing.
queue.on('empty', process.exit);

// Insert postgis fixture only once for all tests as they will not be
// modified. Queued first after which the remaining tests run.
var postgis = function(callback) {
    var insert = '\
        psql -d postgres -c "DROP DATABASE IF EXISTS tilemill_test;" && \
        createdb -E UTF8 -T template_postgis tilemill_test && \
        psql -d tilemill_test -f ' + basedir + '/fixtures/tilemill_test.sql';
    exec(insert, function(err) {
        if (err) throw err;
        console.warn('Inserted postgres fixture.');
        callback();
    });
};
postgis.bootstrap = true;
queue.add(postgis);

tilemill.commands.test.augment({
    bootstrap: function(parent, plugin, callback) {
        // Create a clean environment.
        var clean = '\
            rm -f ' + basedir + '/fixtures/files/app.db && \
            rm -rf ' + basedir + '/fixtures/files/project && \
            rm -rf ' + basedir + '/fixtures/files/data && \
            rm -rf ' + basedir + '/fixtures/files/export && \
            cp -R ' + basedir + '/fixtures/pristine/project ' + basedir + '/fixtures/files';
        exec(clean, function(err) {
            if (err) throw err;
            console.warn('Initialized test fixture');
            parent.call(this, plugin, callback);
        }.bind(this));
    }
});

module.exports = queue.add;

<|endoftext|>


<commit_before>/*global describe, beforeEach, it, xit */
'use strict';
var path = require('path');
var fs = require('fs-extra');
var exec = require('child_process').exec;

var helpers = require('yeoman-generator').test;
var assert = require('yeoman-generator').assert;
var chai = require('chai');
var expect = chai.expect;

describe('emberfs generator', function () {

    var defaultOptions = {
    };

    beforeEach(function(done) {
        this.app = helpers
            .run(path.join(__dirname, '../generators/app'))
            .inDir(path.join(__dirname, '.tmp'), function(dir) {
                //node_modulesx
                // fs.copySync(path.join(__dirname, 'fixtures/node_modules'),
                //             path.join(dir, 'node_modules'));
                //bower_components

                // node_modules
                fs.symlinkSync(path.join(__dirname, 'fixtures/node_modules'),
                               path.join(dir, 'node_modules'), 'dir');

                fs.mkdirpSync(path.join(dir, 'app/client'));

                // bower_components
                fs.symlinkSync(path.join(__dirname, 'fixtures/bower_components'),
                               path.join(dir, 'app/client/bower_components'), 'dir');

                exec('npm install & bower install', { cwd: path.join(__dirname, 'fixtures') }, function(error) {
                    console.log('running npm install & bower install on fixtures');
                    if (error) { console.log('Error: ' + error); }

                    done();
                });
            });
    });

    describe('running app', function() {

        describe('with default options', function() {

            it('should pass jshint', function(done) {
                this.timeout(40000);
                this.app.withPrompt(defaultOptions)
                    .on('end', function() {
                        console.log('running jshint');
                        exec('gulp jshint', function(error, stdout, stderr) {
                            if (error) { console.log('Error: ' + error); }
                            expect(stdout).to.contain('Finished \'jshint\'');
                            expect(stdout).to.not.contain('problems');

                            done();
                        });
                    });
            });
            // pending for now, because gulp test doesn't exit properly
            xit('should pass all client tests', function(done) {
                this.timeout(600000);
                this.app.withPrompt(defaultOptions)
                    .on('end', function() {
                        console.log('running client side tests');
                        exec('gulp test', function(error, stdout, stderr) {
                            expect(stdout).to.match(/# tests\s*3/);
                            expect(stdout).to.match(/# pass\s*3/);
                            expect(stdout).to.match(/# fail\s*0/);
                            done();
                        });
                    });
            });
        });
    });

});
<commit_msg>test-creation fixed<commit_after>/*global describe, beforeEach, it, xit */
'use strict';
var path = require('path');
var fs = require('fs-extra');
var exec = require('child_process').exec;

var helpers = require('yeoman-generator').test;
var assert = require('yeoman-generator').assert;
var chai = require('chai');
var expect = chai.expect;

describe('emberfs generator', function () {

    var defaultOptions = {
    };

    beforeEach(function(done) {
        this.timeout(1200000);
        this.app = helpers
            .run(path.join(__dirname, '../generators/app'))
            .inDir(path.join(__dirname, '.tmp'), function(dir) {
                //node_modulesx
                // fs.copySync(path.join(__dirname, 'fixtures/node_modules'),
                //             path.join(dir, 'node_modules'));
                //bower_components

                // node_modules
                fs.symlinkSync(path.join(__dirname, 'fixtures/node_modules'),
                               path.join(dir, 'node_modules'), 'dir');

                fs.mkdirpSync(path.join(dir, 'app/client'));

                // bower_components
                fs.symlinkSync(path.join(__dirname, 'fixtures/bower_components'),
                               path.join(dir, 'app/client/bower_components'), 'dir');

                exec('npm install & bower install', { cwd: path.join(__dirname, 'fixtures') }, function(error) {
                    console.log('running npm install & bower install on fixtures');
                    if (error) { console.log('Error: ' + error); }

                    done();
                });
            });
    });

    describe('running app', function() {

        describe('with default options', function() {

            it('should pass jshint', function(done) {
                this.timeout(40000);
                this.app.withPrompt(defaultOptions)
                    .on('end', function() {
                        console.log('running jshint');
                        exec('gulp jshint', function(error, stdout, stderr) {
                            if (error) { console.log('Error: ' + error); }
                            expect(stdout).to.contain('Finished \'jshint\'');
                            expect(stdout).to.not.contain('problems');

                            done();
                        });
                    });
            });
            // pending for now, because gulp test doesn't exit properly
            xit('should pass all client tests', function(done) {
                this.timeout(600000);
                this.app.withPrompt(defaultOptions)
                    .on('end', function() {
                        console.log('running client side tests');
                        exec('gulp test', function(error, stdout, stderr) {
                            expect(stdout).to.match(/# tests\s*3/);
                            expect(stdout).to.match(/# pass\s*3/);
                            expect(stdout).to.match(/# fail\s*0/);
                            done();
                        });
                    });
            });
        });
    });

});
<|endoftext|>


<commit_before>var expect, deepcopy;

if (typeof module !== 'undefined') {
  expect = require('expect.js');
  deepcopy = require('../');
} else {
  expect = this.expect;
  deepcopy = this.deepcopy;
}

describe('deepcopy', function() {

  it('should return deep copy if parameter is primitive type', function() {
    expect(deepcopy(12345)).to.be(12345);
    expect(deepcopy('abc')).to.be('abc');
    expect(deepcopy(true)).to.be(true);
    expect(deepcopy(null)).to.be(null);
    expect(deepcopy(void 0)).to.be(void 0);
  });

  it('should return reference if parameter is Function', function() {
    function f() {}

    expect(deepcopy(f)).to.be(f);
  });

  it('should return deep copy if parameter is Date', function() {
    var date = new Date;

    expect(deepcopy(date)).to.eql(date);
  });

  it('should return deep copy if parameter is RegExp', function() {
    var regexp = /\x00/gi;

    expect(deepcopy(regexp)).to.eql(regexp);
  });

  it('should return deep copy if parameter is Array', function() {
    var array = [
      12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi, [
        12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi
      ], {
        array: [
          12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi,
        ]
      }
    ];

    expect(deepcopy(array)).to.eql(array);
  });

  it('should return deep copy if parameter is Object', function() {
    var object = {
      num: 12345,
      str: 'abc',
      bool: true,
      null: null,
      undefined: void 0,
      fn: function() {},
      date: new Date,
      regexp: /\x00/gi,
      array: [
        1, 'a', false, null, void 0, function() {}, new Date, /\x00/gi
      ],
      object: {
        num: 1,
        str: 'a',
        bool: false,
        null: null,
        undefined: void 0,
        fn: function() {},
        date: new Date,
        regexp: /\x00/gi
      }
    };

    expect(deepcopy(object)).to.eql(object);
  });

  it('should return object if object has circular reference', function() {
    var circular, copy;

    expect(function() {
      circular = {};
      circular.to = circular;
      copy = deepcopy(circular);
    }).to.not.throwException();

    expect(copy.to).to.be(copy);
  });

});
<commit_msg>linted<commit_after>var expect, deepcopy;

if (typeof module !== 'undefined') {
  expect = require('expect.js');
  deepcopy = require('../');
} else {
  expect = this.expect;
  deepcopy = this.deepcopy;
}

describe('deepcopy', function() {

  it('should return deep copy if parameter is primitive type', function() {
    expect(deepcopy(12345)).to.be(12345);
    expect(deepcopy('abc')).to.be('abc');
    expect(deepcopy(true)).to.be(true);
    expect(deepcopy(null)).to.be(null);
    expect(deepcopy(void 0)).to.be(void 0);
  });

  it('should return reference if parameter is Function', function() {
    function f() {}

    expect(deepcopy(f)).to.be(f);
  });

  it('should return deep copy if parameter is Date', function() {
    var date = new Date;

    expect(deepcopy(date)).to.eql(date);
  });

  it('should return deep copy if parameter is RegExp', function() {
    var regexp = /\x00/gi;

    expect(deepcopy(regexp)).to.eql(regexp);
  });

  it('should return deep copy if parameter is Array', function() {
    var array = [
      12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi, [
        12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi
      ], {
        array: [
          12345, 'abc', true, null, void 0, function() {}, new Date, /\x00/gi
        ]
      }
    ];

    expect(deepcopy(array)).to.eql(array);
  });

  it('should return deep copy if parameter is Object', function() {
    var object = {
      num: 12345,
      str: 'abc',
      bool: true,
      null: null,
      undefined: void 0,
      fn: function() {},
      date: new Date,
      regexp: /\x00/gi,
      array: [
        1, 'a', false, null, void 0, function() {}, new Date, /\x00/gi
      ],
      object: {
        num: 1,
        str: 'a',
        bool: false,
        null: null,
        undefined: void 0,
        fn: function() {},
        date: new Date,
        regexp: /\x00/gi
      }
    };

    expect(deepcopy(object)).to.eql(object);
  });

  it('should return object if object has circular reference', function() {
    var circular, copy;

    expect(function() {
      circular = {};
      circular.to = circular;
      copy = deepcopy(circular);
    }).to.not.throwException();

    expect(copy.to).to.be(copy);
  });

});
<|endoftext|>


<commit_before>var assert = require('assert');
var mori = require('mori');
var setLogic = require('./../setLogic.js');

describe('makeCard', function() {
    it('should return a mori hashMap', function(){
        assert(mori.isMap(setLogic.makeCard(1,1,1,1)));
    });

    it('should return a hashMap with the four attribute names as keys', function(){
        assert.equal(mori.intoArray(mori.keys(setLogic.makeCard(1,1,1,1))),
            ["number", "shape", "fill", "color"]
        );
    });

})

describe('isSet', function(){

    it('should reject more or less than three cards', function(){
      assert.equal(setLogic.isSet([1, 2]), false);
      assert.equal(setLogic.isSet([1,2,3,4]), false);
    });

    it('should accept three cards that are identical');

    it('should accept three cards that are different in all ways');

    it('should accept three cards that share two attributes but differ on a third');

    it('should accept three cards that share one attribute and differ on two');

    it('should reject three cards where only two share an attribute');

})
<commit_msg>Add some more test stubs<commit_after>var assert = require('assert');
var mori = require('mori');
var setLogic = require('./../setLogic.js');

describe('makeCard', function() {
    it('should return a mori hashMap', function(){
        assert(mori.isMap(setLogic.makeCard(1,1,1,1)));
    });

    it('should return a hashMap with the four attribute names as keys', function(){
        var card1 = setLogic.makeCard(1,1,1,1);
        assert.equal(mori.count(mori.keys(card1)), 4);
        assert(mori.hasKey(card1, "number"));
        assert(mori.hasKey(card1, "shape"));
        assert(mori.hasKey(card1, "fill"));
        assert(mori.hasKey(card1, "color"));
    });

    it('should return a hashMap with the correct values', function() {
        var card0 = setLogic.makeCard(0,0,0,0);
        assert.equal(mori.get(card0, "number"), 1);
        assert.equal(mori.get(card0, "shape"), "diamond");
        assert.equal(mori.get(card0, "fill"), "solid");
        assert.equal(mori.get(card0, "color"), "red");

        var card2 = setLogic.makeCard(1,2,1,2);
        assert.equal(mori.get(card2, "number"), 2);
        assert.equal(mori.get(card2, "shape"), "rectangle");
        assert.equal(mori.get(card2, "fill"), "shaded");
        assert.equal(mori.get(card2, "color"), "purple");

    });

})

describe('isSet', function(){

    it('should reject more or less than three cards', function(){
      assert.equal(setLogic.isSet([1, 2]), false);
      assert.equal(setLogic.isSet([1,2,3,4]), false);
    });

    it('should accept three cards that are identical');

    it('should accept three cards that are different in all ways');

    it('should accept three cards that share two attributes but differ on a third');

    it('should accept three cards that share one attribute and differ on two');

    it('should reject three cards where only two share an attribute');

})

describe('isAttrOK', function(){

    it('should accept three identical values');

    it('should accept three distinct values');

    it('should reject two similar and one different values');
})
<|endoftext|>


<commit_before>/* @flow */
import lodash from 'lodash'
const _: any = lodash

const state: any = {
  contents: {
    common: {
      header: {
        title: 'header',
        text: 'center header\n\nendheader'
      },
      footer: {
        title: 'footer',
        text: 'center footer\n\nendfooter'
      },
      scale: {
        title: 'scale',
        text: 'scale'
      },
      define: {
        title: 'define',
        text: '!define'
      },
      title: {
        title: 'title',
        text: 'title'
      },
      legend: {
        title: 'legend',
        text: 'legend center\n\nendlegend'
      },
      caption: {
        title: 'caption',
        text: 'caption'
      },
      direction: {
        title: 'direction',
        text: 'left to right direction'
      },
      label: {
        title: 'label',
        text: ':'
      },
      comment: {
        title: 'comment',
        text: '\''
      },
      blockcomment: {
        title: 'block comment',
        text: '/\'\ncomment\n\'/'
      },
      solidline: {
        title: 'solid line',
        text: '-->'
      },
      dashedline: {
        title: 'dashed line',
        text: '..>'
      },
      noteleft: {
        title: 'note left',
        text: 'note left :'
      },
      noteright: {
        title: 'note right',
        text: 'note right :'
      },
      noteblock: {
        title: 'note block',
        text: 'note left of A\n\nend note'
      },
      actor: {
        title: 'actor',
        text: 'actor',
        img: 'UDfpA2v9B2efpStXuh9oJ2x9Br98pCbCBBRYud98pKi1YWC0mMaBGG00'
      },
      actoralias: {
        title: 'actor',
        text: ':Actor alias:'
      },
      agent: {
        title: 'agent',
        text: 'agent',
        img: 'UDfpA2v9B2efpStXuafCJyqhKG2JN5mEgNafG540i5aAw000'
      },
      usecase: {
        title: 'usecase',
        text: 'usecase',
        img: 'UDfpA2v9B2efpStXuYejJarEB4vLWD9SN0wfUIb06G3bpmoS'
      },
      node: {
        title: 'node',
        text: 'node',
        img: 'UDfpA2v9B2efpStXuihBJqbL01FHO3PNB1UNGsfU2b0I0Ftn3AW0'
      },
      nodeblock: {
        title: 'node block',
        text: 'node Node [\nnode\n]'
      },
      database: {
        title: 'database',
        text: 'database',
        img: 'UDfpA2v9B2efpStXuaf9B4bCIYnELO0pehbSdBXYkRWSKlDIW4e0M8iEfW00'
      },
      databaseblock: {
        title: 'database block',
        text: 'database DB [\nDB\n]'
      },
      storage: {
        title: 'storage',
        text: 'storage',
        img: 'UDfpA2v9B2efpStXuYekoIzAJ4zLWD7HC16kM2ukXzIy5A0g09aj49K0'
      },
      storageblock: {
        title: 'storage block',
        text: 'storage Storage [\nstorage\n]'
      },
      component: {
        title: 'component',
        text: '[Component]',
        img: 'UDfpA2v9B2efpStXuefspiyjoCzBpIk9vU9oICrB0Oe20BAT2nK0'
      },
      skinparammonochrome: {
        title: 'skinparam\nmonochrome',
        text: 'skinparam monochrome true'
      },
      skinparammonochromereverse: {
        title: 'skinparam\nmonochrome\nreverse',
        text: 'skinparam monochrome reverse'
      },
      skinparamhandwritten: {
        title: 'skinparam\nhandwritten',
        text: 'skinparam handwritten true'
      },
      skinparamshadowing: {
        title: 'skinparam\nshadowing',
        text: 'skinparam shadowing false'
      },
      skinparambackgroundcolor: {
        title: 'skinparam\nbackgroundColor',
        text: 'skinparam backgroundColor #EEEEEE'
      }
    },
    usecase: {
      rectangle: {
        title: 'rectangle',
        text: 'rectangle Job {\n\n}'
      },
      up: {
        title: 'up',
        text: '-up->'
      },
      right: {
        title: 'right',
        text: '-right->'
      },
      down: {
        title: 'down',
        text: '-down->'
      },
      left: {
        title: 'left',
        text: '-left->'
      }
    },
    activity: {
      if: {
        title: 'if',
        text: 'if (try) then (true)\n\nelse (false)\n\nendif'
      },
      repeat: {
        title: 'repeat',
        text: 'repeat\n\nrepeat while (error)'
      },
      while: {
        title: 'while',
        text: 'while (try) is (true)\n\nendwhile (false)'
      },
      fork: {
        title: 'fork',
        text: 'fork\n\nfork again\n\nend fork'
      },
      partition: {
        title: 'partition',
        text: 'partition A {\n\n}'
      }
    },
    sequence: {
      autonumber: {
        title: 'autonumber',
        text: 'autonumber'
      },
      participant: {
        title: 'participant',
        text: 'participant ABC as abc',
        img: 'UDfpA2v9B2efpStXuYe0CZAJCmiIyqeK79sSkRWSKlDIW380uZKCBm00'
      },
      activate: {
        title: 'activate',
        text: 'activate'
      },
      deactivate: {
        title: 'deactivate',
        text: 'deactivate'
      },
      altelse: {
        title: 'alt/else',
        text: 'alt success\n\nelse error\n\nend'
      },
      loop: {
        title: 'loop',
        text: 'loop title\n\nend'
      },
      separate: {
        title: 'separate',
        text: '== =='
      }
    },
    object: {
      object: {
        title: 'object',
        text: 'object A {\n\n}'
      },
      extension: {
        title: 'Extension',
        text: '<|-'
      },
      composition: {
        title: 'Composition',
        text: '*-'
      },
      aggregation: {
        title: 'Aggregation',
        text: 'o-'
      }
    },
    class: {
      public: {
        title: 'Public',
        text: '+'
      },
      private: {
        title: 'Private',
        text: '-'
      },
      protected: {
        title: 'Protected',
        text: '#'
      },
      packageprivate: {
        title: 'Package Private',
        text: '~'
      },
      static: {
        title: 'static',
        text: '{static}'
      },
      abstract: {
        title: 'abstract',
        text: '{abstract}'
      },
      abstractkeyword: {
        title: 'abstract keyword',
        text: 'abstract'
      },
      interface: {
        title: 'interface',
        text: 'interface'
      },
      package: {
        title: 'package',
        text: 'package A {\n\n}'
      },
      namespace: {
        title: 'namespace',
        text: 'namespace A {\n\n}'
      }
    }
  }
}

const getters: any = {
  snippets ({contents}: any): { text?: string, displayText?: string }[] {
    let results: { text?: string, displayText?: string }[] = []
    _.forEach(contents, function (snippets: any, category: string) {
      _.forEach(snippets, function (snippet: any) {
        results[results.length] = {
          text: snippet.text,
          displayText: `${category}: ${snippet.title}`
        }
      })
    })
    return results
  }
}

export default {
  state,
  getters
}
<commit_msg>スニペットの表示が見にくかったので修正<commit_after>/* @flow */
import lodash from 'lodash'
const _: any = lodash

const state: any = {
  contents: {
    common: {
      header: {
        title: 'header',
        text: 'center header\n\nendheader'
      },
      footer: {
        title: 'footer',
        text: 'center footer\n\nendfooter'
      },
      scale: {
        title: 'scale',
        text: 'scale'
      },
      define: {
        title: 'define',
        text: '!define'
      },
      title: {
        title: 'title',
        text: 'title'
      },
      legend: {
        title: 'legend',
        text: 'legend center\n\nendlegend'
      },
      caption: {
        title: 'caption',
        text: 'caption'
      },
      direction: {
        title: 'direction',
        text: 'left to right direction'
      },
      label: {
        title: 'label',
        text: ':'
      },
      comment: {
        title: 'comment',
        text: '\''
      },
      blockcomment: {
        title: 'block comment',
        text: '/\'\ncomment\n\'/'
      },
      solidline: {
        title: 'solid line',
        text: '-->'
      },
      dashedline: {
        title: 'dashed line',
        text: '..>'
      },
      noteleft: {
        title: 'note left',
        text: 'note left :'
      },
      noteright: {
        title: 'note right',
        text: 'note right :'
      },
      noteblock: {
        title: 'note block',
        text: 'note left of A\n\nend note'
      },
      actor: {
        title: 'actor',
        text: 'actor',
        img: 'UDfpA2v9B2efpStXuh9oJ2x9Br98pCbCBBRYud98pKi1YWC0mMaBGG00'
      },
      actoralias: {
        title: 'actor',
        text: ':Actor alias:'
      },
      agent: {
        title: 'agent',
        text: 'agent',
        img: 'UDfpA2v9B2efpStXuafCJyqhKG2JN5mEgNafG540i5aAw000'
      },
      usecase: {
        title: 'usecase',
        text: 'usecase',
        img: 'UDfpA2v9B2efpStXuYejJarEB4vLWD9SN0wfUIb06G3bpmoS'
      },
      node: {
        title: 'node',
        text: 'node',
        img: 'UDfpA2v9B2efpStXuihBJqbL01FHO3PNB1UNGsfU2b0I0Ftn3AW0'
      },
      nodeblock: {
        title: 'node block',
        text: 'node Node [\nnode\n]'
      },
      database: {
        title: 'database',
        text: 'database',
        img: 'UDfpA2v9B2efpStXuaf9B4bCIYnELO0pehbSdBXYkRWSKlDIW4e0M8iEfW00'
      },
      databaseblock: {
        title: 'database block',
        text: 'database DB [\nDB\n]'
      },
      storage: {
        title: 'storage',
        text: 'storage',
        img: 'UDfpA2v9B2efpStXuYekoIzAJ4zLWD7HC16kM2ukXzIy5A0g09aj49K0'
      },
      storageblock: {
        title: 'storage block',
        text: 'storage Storage [\nstorage\n]'
      },
      component: {
        title: 'component',
        text: '[Component]',
        img: 'UDfpA2v9B2efpStXuefspiyjoCzBpIk9vU9oICrB0Oe20BAT2nK0'
      },
      skinparammonochrome: {
        title: 'skinparam\nmonochrome',
        text: 'skinparam monochrome true'
      },
      skinparammonochromereverse: {
        title: 'skinparam\nmonochrome\nreverse',
        text: 'skinparam monochrome reverse'
      },
      skinparamhandwritten: {
        title: 'skinparam\nhandwritten',
        text: 'skinparam handwritten true'
      },
      skinparamshadowing: {
        title: 'skinparam\nshadowing',
        text: 'skinparam shadowing false'
      },
      skinparambackgroundcolor: {
        title: 'skinparam\nbackgroundColor',
        text: 'skinparam backgroundColor #EEEEEE'
      }
    },
    usecase: {
      rectangle: {
        title: 'rectangle',
        text: 'rectangle Job {\n\n}'
      },
      up: {
        title: 'up',
        text: '-up->'
      },
      right: {
        title: 'right',
        text: '-right->'
      },
      down: {
        title: 'down',
        text: '-down->'
      },
      left: {
        title: 'left',
        text: '-left->'
      }
    },
    activity: {
      if: {
        title: 'if',
        text: 'if (try) then (true)\n\nelse (false)\n\nendif'
      },
      repeat: {
        title: 'repeat',
        text: 'repeat\n\nrepeat while (error)'
      },
      while: {
        title: 'while',
        text: 'while (try) is (true)\n\nendwhile (false)'
      },
      fork: {
        title: 'fork',
        text: 'fork\n\nfork again\n\nend fork'
      },
      partition: {
        title: 'partition',
        text: 'partition A {\n\n}'
      }
    },
    sequence: {
      autonumber: {
        title: 'autonumber',
        text: 'autonumber'
      },
      participant: {
        title: 'participant',
        text: 'participant ABC as abc',
        img: 'UDfpA2v9B2efpStXuYe0CZAJCmiIyqeK79sSkRWSKlDIW380uZKCBm00'
      },
      activate: {
        title: 'activate',
        text: 'activate'
      },
      deactivate: {
        title: 'deactivate',
        text: 'deactivate'
      },
      altelse: {
        title: 'alt/else',
        text: 'alt success\n\nelse error\n\nend'
      },
      loop: {
        title: 'loop',
        text: 'loop title\n\nend'
      },
      separate: {
        title: 'separate',
        text: '== =='
      }
    },
    object: {
      object: {
        title: 'object',
        text: 'object A {\n\n}'
      },
      extension: {
        title: 'Extension',
        text: '<|-'
      },
      composition: {
        title: 'Composition',
        text: '*-'
      },
      aggregation: {
        title: 'Aggregation',
        text: 'o-'
      }
    },
    class: {
      public: {
        title: 'Public',
        text: '+'
      },
      private: {
        title: 'Private',
        text: '-'
      },
      protected: {
        title: 'Protected',
        text: '#'
      },
      packageprivate: {
        title: 'Package Private',
        text: '~'
      },
      static: {
        title: 'static',
        text: '{static}'
      },
      abstract: {
        title: 'abstract',
        text: '{abstract}'
      },
      abstractkeyword: {
        title: 'abstract keyword',
        text: 'abstract'
      },
      interface: {
        title: 'interface',
        text: 'interface'
      },
      package: {
        title: 'package',
        text: 'package A {\n\n}'
      },
      namespace: {
        title: 'namespace',
        text: 'namespace A {\n\n}'
      }
    }
  }
}

const getters: any = {
  snippets ({contents}: any): { text?: string, displayText?: string }[] {
    let results: { text?: string, displayText?: string }[] = []
    _.forEach(contents, function (snippets: any, category: string) {
      _.forEach(snippets, function (snippet: any) {
        results[results.length] = {
          text: snippet.text,
          displayText: `${snippet.title} : ( ${category} )`
        }
      })
    })
    return results
  }
}

export default {
  state,
  getters
}
<|endoftext|>


<commit_before>/**
 * @class jQuery
 */

/**
 * Browser information. This object has 3 sub-properties: name, version and OS.

 * Overrides jQuery.browser.
 * You also get three 'is' prefixed boolean properties attached to ion:

 * 1. for OS (e.g ion.isWindows), 2. for browser vendor (e.g ion.isIE), and 3. vendor+version (e.g ion.isIE8).
 * @property browser
 * @type Object
 * @final
 * @credits Modified code from from http://www.quirksmode.org/js/detect.html.
 */
(function (Li) {
    var agent = navigator.userAgent.toLowerCase(),
        it, match,
        name, version, OS, OSVersion,
        browserList = [
            [/iemobile.([\d\.]+)/, 'IEMobile'],
            [/msie.([\d\.]+)/, 'IE'],
            [/chrome.([\d\.]+)/, 'Chrome'],
            [/firefox.([\d\.]+)/, 'Firefox'],
            [/version\/([\d\.]+).+?safari/, 'Safari'],
            [/opera.+?version\/([\d\.]+)/, 'Opera'],
            [/rv.([\d\.]+).+?gecko/, 'Gecko'],
            [/applewebkit.([\d\.]+)/, 'WebKit']
        ],
        OSList = [
            [/windows phone os ([\d\.]+)/, "WindowsPhone"],
            [/windows (nt [\d\.]+)/, "Windows"],
            [/mac os x ([\d_]+)/, "Mac"],
            [/android ([\d\.]+)/, "Android"],
            [/linux/, "Linux"],
            [/iphone os ([\d_]+)/, "IPhone"],
            [/ipad.+?os ([\d_]+)/, "IPad"],
            [/blackberry (\d+)/, "BlackBerry"],
            [/symbianos.([\d\.]+)/, "Symbian"]
        ];

    while ((it = browserList.shift())) {
        match = agent.match(it[0]);
        if (match) {
            name = it[1];
            version = match[1];
            break;
        }
    }

    if (name) {
        Li["is" + name] = true;
        if (version) {
            Li["is" + name + parseInt(version, 10)] = true;
        }
    }

    Li.isWebKit = Li.isChrome || Li.isSafari || Li.isWebKit;
    Li.isGecko = Li.isFirefox || Li.isGecko;
    Li.isIOS = Li.isIPhone || Li.isIPad;
    Li.isMobile = Li.isAndroid || Li.isIPhone || Li.isBlackBerry || Li.isWindowsPhone || Li.isSymbian;

    //TODO: Detect IE compatibility mode

    while ((it = OSList.shift())) {
        match = agent.match(it[0]);
        if (match) {
            OS = it[1];
            if ((OSVersion = match[1])) {
                OSVersion = OSVersion.replace('_', '.');
            }
            break;
        }
    }
    if (OS) {
        Li["is" + OS] = true;
    }

    //Bug that WebKit is being detected as Safari on non-iOS phones/tablets
    if (Li.isSafari && (Li.isAndroid || Li.isBlackBerry || Li.isSymbian)) {
        delete Li.isSafari;
        delete Li["is" + name + parseInt(version, 10)];
        name = 'WebKit';
        version = agent.match(/applewebkit.([\d\.]+)/)[1];
        Li["is" + name + parseInt(version, 10)] = true;
    }

    Li.browser = {
        name: name,
        version: version,
        OS: OS,
        OSVersion: OSVersion
    };
}(window.Li));
<commit_msg>Excluding Android/BlackBerry tablets from Li.isMobile.<commit_after>/**
 * @class jQuery
 */

/**
 * Browser information. This object has 3 sub-properties: name, version and OS.

 * Overrides jQuery.browser.
 * You also get three 'is' prefixed boolean properties attached to ion:

 * 1. for OS (e.g ion.isWindows), 2. for browser vendor (e.g ion.isIE), and 3. vendor+version (e.g ion.isIE8).
 * @property browser
 * @type Object
 * @final
 * @credits Modified code from from http://www.quirksmode.org/js/detect.html.
 */
(function (Li) {
    var agent = navigator.userAgent.toLowerCase(),
        it, match,
        name, version, OS, OSVersion,
        browserList = [
            [/iemobile.([\d\.]+)/, 'IEMobile'],
            [/msie.([\d\.]+)/, 'IE'],
            [/chrome.([\d\.]+)/, 'Chrome'],
            [/firefox.([\d\.]+)/, 'Firefox'],
            [/version\/([\d\.]+).+?safari/, 'Safari'],
            [/opera.+?version\/([\d\.]+)/, 'Opera'],
            [/rv.([\d\.]+).+?gecko/, 'Gecko'],
            [/applewebkit.([\d\.]+)/, 'WebKit']
        ],
        OSList = [
            [/windows phone os ([\d\.]+)/, "WindowsPhone"],
            [/windows (nt [\d\.]+)/, "Windows"],
            [/mac os x ([\d_]+)/, "Mac"],
            [/android ([\d\.]+)/, "Android"],
            [/linux/, "Linux"],
            [/iphone os ([\d_]+)/, "IPhone"],
            [/ipad.+?os ([\d_]+)/, "IPad"],
            [/blackberry (\d+)/, "BlackBerry"],
            [/symbianos.([\d\.]+)/, "Symbian"]
        ];

    while ((it = browserList.shift())) {
        match = agent.match(it[0]);
        if (match) {
            name = it[1];
            version = match[1];
            break;
        }
    }

    if (name) {
        Li["is" + name] = true;
        if (version) {
            Li["is" + name + parseInt(version, 10)] = true;
        }
    }

    Li.isWebKit = Li.isChrome || Li.isSafari || Li.isWebKit;
    Li.isGecko = Li.isFirefox || Li.isGecko;
    Li.isIOS = Li.isIPhone || Li.isIPad;
    Li.isMobile = Li.isAndroid || Li.isIPhone || Li.isBlackBerry || Li.isWindowsPhone || Li.isSymbian;
    //Detecting ' mobile ' from user agent isn't perfect but good enough.
    //http://stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent
    if ((Li.isAndroid || Li.isBlackBerry) && !(/ mobile /).test(agent)) {
        delete Li.isMobile;
    }

    //TODO: Detect IE compatibility mode

    while ((it = OSList.shift())) {
        match = agent.match(it[0]);
        if (match) {
            OS = it[1];
            if ((OSVersion = match[1])) {
                OSVersion = OSVersion.replace('_', '.');
            }
            break;
        }
    }
    if (OS) {
        Li["is" + OS] = true;
    }

    //Bug that WebKit is being detected as Safari on non-iOS phones/tablets
    if (Li.isSafari && (Li.isAndroid || Li.isBlackBerry || Li.isSymbian)) {
        delete Li.isSafari;
        delete Li["is" + name + parseInt(version, 10)];
        name = 'WebKit';
        version = agent.match(/applewebkit.([\d\.]+)/)[1];
        Li["is" + name + parseInt(version, 10)] = true;
    }

    Li.browser = {
        name: name,
        version: version,
        OS: OS,
        OSVersion: OSVersion
    };
}(window.Li));
<|endoftext|>


<commit_before>/* globals Promise:true */

var EventEmitter = require('events').EventEmitter
var inherits = require('util').inherits
var Promise = require('bluebird')

/**
 * @event Slaves#sendTx
 * @param {string} rawTx
 */

/**
 * @class Slaves
 */
function Slaves () {
  EventEmitter.call(this)
}

inherits(Slaves, EventEmitter)

/**
 * @return {Promise}
 */
Slaves.prototype.init = function () {
  var self = this

  function onSendTx (payload) {
    payload = JSON.parse(payload)
    self.emit('sendTx', payload.id, payload.rawtx)
  }

  return Promise.all([
    messages.listen('sendtx', onSendTx)
  ])
}

/**
 * @param {pg.Client} client
 * @param {string} id
 * @param {(Object|undefined)} err
 * @return {Promise}
 */
Slaves.prototype.sendTxResponse = function (client, id, err) {
  var payload = JSON.stringify({
    status: err === undefined ? 'success' : 'fail',
    id: id,
    code: (err || {}).code,
    message: escape((err || {}).message)
  })
  return messages.notify(client, 'sendtxresponse', payload)
}

/**
 * @param {pg.Client} client
 * @param {string} blockid
 * @param {number} height
 * @return {Promise}
 */
Slaves.prototype.newBlock = function (client, blockid, height) {
  var payload = JSON.stringify({blockid: blockid, height: height})
  return messages.notify(client, 'newblock', payload)
}

/**
 * @param {pg.Client} client
 * @param {string} txid
 * @return {Promise}
 */
Slaves.prototype.newTx = function (client, txid) {
  var payload = JSON.stringify({txid: txid})
  return messages.notify(client, 'newtx', payload)
}

/**
 * @param {pg.Client} client
 * @param {string} address
 * @param {string} txid
 * @return {Promise}
 */
Slaves.prototype.addressTouched = function (client, address, txid) {
  var payload = JSON.stringify({address: address, txid: txid})
  return messages.notify(client, 'addresstouched', payload)
}

module.exports = require('soop')(Slaves)
<commit_msg>change master/slaves<commit_after>var EventEmitter = require('events').EventEmitter
var inherits = require('util').inherits

var storage = require('../../lib/storage').default()

/**
 * @event Slaves#sendTx
 * @param {string} rawtx
 */

/**
 * @class Slaves
 */
function Slaves () {
  EventEmitter.call(this)
}

inherits(Slaves, EventEmitter)

/**
 * @return {Promise}
 */
Slaves.prototype.init = function () {
  var self = this
  return storage.listen('sendTx', function (payload) {
    payload = JSON.parse(payload)
    self.emit('sendTx', payload.id, payload.rawtx)
  })
}

/**
 * @param {string} id
 * @param {?Object} err
 * @param {Object} [opts]
 * @param {pg.Client} [opts.client]
 * @return {Promise}
 */
Slaves.prototype.sendTxResponse = function (id, err, opts) {
  var payload = JSON.stringify({
    status: err === null ? 'success' : 'fail',
    id: id,
    code: (err || {}).code,
    message: escape((err || {}).message)
  })
  return storage.notify('sendtxresponse', payload, opts)
}

/**
 * @param {string} blockid
 * @param {number} height
 * @param {Object} [opts]
 * @param {pg.Client} [opts.client]
 * @return {Promise}
 */
Slaves.prototype.broadcastBlock = function (blockid, height, opts) {
  var payload = JSON.stringify({blockid: blockid, height: height})
  return storage.notify('broadcastblock', payload, opts)
}

/**
 * @param {string} txid
 * @param {?string} blockHash
 * @param {?number} blockHeight
 * @param {Object} [opts]
 * @param {pg.Client} [opts.client]
 * @return {Promise}
 */
Slaves.prototype.broadcastTx = function (txid, blockHash, blockHeight, opts) {
  var payload = JSON.stringify({
    txid: txid,
    blockHash: blockHash,
    blockHeight: blockHeight
  })
  return storage.notify('broadcasttx', payload, opts)
}

/**
 * @param {string} address
 * @param {string} txid
 * @param {Object} [opts]
 * @param {pg.Client} [opts.client]
 * @return {Promise}
 */
Slaves.prototype.broadcastAddressTx = function (address, txid, opts) {
  var payload = JSON.stringify({address: address, txid: txid})
  return storage.notify('broadcastaddresstx', payload, opts)
}

/**
 * @param {Object} info
 * @param {Object} [opts]
 * @param {pg.Client} [opts.client]
 * @return {Promise}
 */
Slaves.prototype.broadcastSyncInfo = function (info, opts) {
  var payload = JSON.stringify(info)
  return storage.notify('broadcastsyncinfo', payload, opts)
}

module.exports = require('soop')(Slaves)
<|endoftext|>


<commit_before><commit_msg>no items model<commit_after>Ext.define('doweown.model.NoItems', {
    extend: 'Ext.data.Model',
    config: {
        belongsTo: 'Branch',
	fields: [
                {name: 'id',     type: 'string'},
                {name: 'url',    type: 'string'}
        ]
    }
});
<|endoftext|>


<commit_before>/*! Clipster - v0.1.0 - 2014-07-08
* https://github.com/kickstarter/jquery-clipster
* Copyright (c) 2014 Samuel Cole; Licensed MIT */
(function($) {
  var $overlay =
    $('

Press ⌘C to copy

<textarea></textarea>

'),
    $input = $overlay.find('textarea');
  $overlay.hide();

  $(function () {
    $('body').append($overlay);
  });

  $.clipster = function (selector, options) {
    $(document).on('click', selector, function (e) {
      var $this = $(this).clipster(options),
        clipster = $this.data('clipster');

      clipster.activate();
      e.preventDefault();
    });
  };

  // Collection method.
  $.fn.clipster = function(options) {
    return this.each(function() {
      var $this = $(this),
        clipster = $this.data('clipster');
      if (!clipster) {
        clipster = new Clipster($this, options);
        $this.data('clipster', clipster);
      }
    });
  };

  function Clipster ($elem, options) {
    if (!options) {
      options = {};
    }

    this.text = options.text || $elem.data('text') || $elem.text();
    this.$elem = $elem;
    this.is_on = false;

    this.bind();
  }

  Clipster.prototype.bind = function () {
    var _this = this;

    this.$elem.on('click', function (e) {
      _this.activate();
      e.preventDefault();
    });

    $(document).on('copy click', function (e) {
      var $target = $(e.target);
      if ($target.closest(_this.$elem).length ||
        (e.type === 'click' && $target.is($input))
      ){
        return;
      }
      _this.deactivate();
    });
  };

  Clipster.prototype.activate = function () {
    if (this.active) {
      return;
    }

    $overlay.show();

    $input.val(this.text);
    $input[0].select();
    $input.focus();

    this.active = true;
  };

  Clipster.prototype.deactivate = function () {
    if (this.active) {
      setTimeout(function () {
        $overlay.hide();
      });
      this.active = false;
    }
  };

}(jQuery));
<commit_msg>Make textarea one row<commit_after>/*! Clipster - v0.1.0 - 2014-07-08
* https://github.com/kickstarter/jquery-clipster
* Copyright (c) 2014 Samuel Cole; Licensed MIT */
(function($) {
  var $overlay =
    $('

Press ⌘C to copy

<textarea rows="1"></textarea>

'),
    $input = $overlay.find('textarea');
  $overlay.hide();

  $(function () {
    $('body').append($overlay);
  });

  $.clipster = function (selector, options) {
    $(document).on('click', selector, function (e) {
      var $this = $(this).clipster(options),
        clipster = $this.data('clipster');

      clipster.activate();
      e.preventDefault();
    });
  };

  // Collection method.
  $.fn.clipster = function(options) {
    return this.each(function() {
      var $this = $(this),
        clipster = $this.data('clipster');
      if (!clipster) {
        clipster = new Clipster($this, options);
        $this.data('clipster', clipster);
      }
    });
  };

  function Clipster ($elem, options) {
    if (!options) {
      options = {};
    }

    this.text = options.text || $elem.data('text') || $elem.text();
    this.$elem = $elem;
    this.is_on = false;

    this.bind();
  }

  Clipster.prototype.bind = function () {
    var _this = this;

    this.$elem.on('click', function (e) {
      _this.activate();
      e.preventDefault();
    });

    $(document).on('copy click', function (e) {
      var $target = $(e.target);
      if ($target.closest(_this.$elem).length ||
        (e.type === 'click' && $target.is($input))
      ){
        return;
      }
      _this.deactivate();
    });
  };

  Clipster.prototype.activate = function () {
    if (this.active) {
      return;
    }

    $overlay.show();

    $input.val(this.text);
    $input[0].select();
    $input.focus();

    this.active = true;
  };

  Clipster.prototype.deactivate = function () {
    if (this.active) {
      setTimeout(function () {
        $overlay.hide();
      });
      this.active = false;
    }
  };

}(jQuery));
<|endoftext|>


<commit_before>import "babel-polyfill";
import expect from 'expect.js';

import TelegramBotApi from './telegram-bot-events';

const
token = process.env.TEST_TOCKEN || '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
userId = process.env.TEST_USERID || 777000,
options = {
  autoUpdate: false,
  updateInterval: 1000,
  updateLimit: 50,
  updatePoolingTimeout: 0
},

expectToBePromise = (obj) => {
  expect(obj).to.be.an('object');
  expect(obj).to.have.property('then');
  expect(obj.then).to.be.a('function');
}
;

describe('telegram-bot-events', () => {
  var bot = new TelegramBotApi(token, options);
  after(() => {
    bot.stopAutoUpdate();
  })

  describe('new instance', () => {

    it('should have default options', () => {
      let bot = new TelegramBotApi(token);
      bot.stopAutoUpdate();
      expect(bot.options).to.be.eql(options);
    });

    it('should have default options with extend', () => {
      let bot = new TelegramBotApi(token, {});
      bot.stopAutoUpdate();
      expect(bot.options).to.be.eql(options);
    });

    it('should have extended options', () => {
      let bot = new TelegramBotApi(token, {foo: 'bar'});
      bot.stopAutoUpdate();
      expect(bot.options.foo).to.be.equal('bar');
    });

  });

  describe('events', () => {
    afterEach(() => {
      bot.offAll();
    });

    it('should have `on` method', () => {
      expect(bot).to.have.property('on');
      expect(bot.on).to.be.a('function');
    });

    it('should have `once` method', () => {
      expect(bot).to.have.property('once');
      expect(bot.once).to.be.a('function');
    });

    it('should have `off` method', () => {
      expect(bot).to.have.property('off');
      expect(bot.off).to.be.a('function');
    });

    it('should have `offAll` method', () => {
      expect(bot).to.have.property('offAll');
      expect(bot.offAll).to.be.a('function');
    });

    it('should have `events`', () => {
      expect(bot.events).to.be.a('object');
      expect(bot.events.on).to.be.a('function');
    });

    it('should can add listner', (done) => {
      let callback = function () {
        done('callback called !')
      };

      bot.on('junk', callback);
      let listeners = bot.events.listeners('junk');

      expect(listeners).to.be.an('array');
      expect(listeners.length).to.be.equal(1);
      expect(listeners[0]).to.be.equal(callback);
      done();
    });

    it('should can remove all special listners', (done) => {
      let callback1 = function () {
        done('callback1 called !')
      };
      bot.on('junk', callback1);
      bot.on('junk', callback1);

      let callback2 = function () {
        done('callback2 called !')
      };
      bot.on('junk', callback2);
      bot.on('junk', callback2);

      let callback3 = function () {
        done('callback3 called !')
      };
      bot.on('junk2', callback2);

      bot.offAll('junk');

      expect(bot.events.listeners('junk').length).to.be.equal(0);
      expect(bot.events.listeners('junk2').length).to.be.equal(1);
      done();
    });

    it('should can remove all listners', (done) => {
      let callback1 = function () {
        done('callback1 called !')
      };
      bot.on('junk', callback1);
      bot.on('junk', callback1);

      let callback2 = function () {
        done('callback2 called !')
      };
      bot.on('junk', callback2);
      bot.on('junk', callback2);

      let callback3 = function () {
        done('callback3 called !')
      };
      bot.on('junk2', callback2);

      bot.offAll();

      expect(bot.events.listeners('junk').length).to.be.equal(0);
      expect(bot.events.listeners('junk2').length).to.be.equal(0);
      done();
    });

    it('should can remove a special listner', (done) => {
      let callback1 = function () {
        done('callback1 called !')
      };
      bot.on('junk', callback1);

      let callback2 = function () {
        done('callback2 called !')
      };
      bot.on('junk', callback2);

      expect(bot.events.listeners('junk').length).to.be.equal(2); // also check offAll in afterEach

      bot.off('junk', callback1);

      expect(bot.events.listeners('junk').length).to.be.equal(1);
      expect(bot.events.listeners('junk')[0]).to.be.equal(callback2);
      done();
    });

  })

  describe('auto update', () => {
    afterEach(() => {
      bot.stopAutoUpdate();
      bot.offAll();
      console.log('!!!');
    });

    it('shout be stopAutoUpdated work', (done) => {
      let bot = new TelegramBotApi(token, options);
      bot.startAutoUpdate();

      setTimeout(()=>{
        bot.stopAutoUpdate();
        expect(bot._setTimeout._onTimeout).to.not.be.ok();
        expect(bot.options.autoUpdate).to.not.be.ok();
        bot.stopAutoUpdate();
        done();
      }, 200);
    });

    it('shout be not autoUpdated by default option', () => {
      let bot = new TelegramBotApi(token);
      expect(bot._setTimeout).to.not.be.ok();

      bot = new TelegramBotApi(token, {autoUpdate: false});
      expect(bot._setTimeout).to.not.be.ok();
    });

    it('shout be autoUpdated by default', () => {
      let bot = new TelegramBotApi(token, {autoUpdate: true});
      after(() => {
        bot.stopAutoUpdate();
      });
      expect(bot._setTimeout).to.be.ok();
    });

    it('shout be startAutoUpdated work', (done) => {
      let bot = new TelegramBotApi(token, {autoUpdate: false, updateInterval: 100});
      after(() => {
        bot.stopAutoUpdate();
      });
      expect(bot._setTimeout).to.not.be.ok();
      bot.startAutoUpdate();
      setTimeout(()=>{
        expect(bot._setTimeout).to.be.ok();
        bot.stopAutoUpdate();
        expect(bot._setTimeout._setTimeout).to.not.be.ok();
        done();
      }, 200);
    });

    it.skip('should trigger on update', (done) => {
      console.log('send message to this bot for test');
      bot.once('update', () => {
        done();
      });
      bot.startAutoUpdate();
    });

    it.skip('should trigger on message', (done) => {
      console.log('send message to this bot for test');
      bot.once('update.message', () => {
        done();
      });
      bot.startAutoUpdate();
    });

    it.skip('should trigger on inline_query', (done) => {
      console.log('send inline_query to this bot for test');
      bot.once('update.inline_query', () => {
        done();
      });
      bot.startAutoUpdate();
    });

  })

});
<commit_msg>test(events): cleaning<commit_after>import "babel-polyfill";
import expect from 'expect.js';

import TelegramBotApi from './telegram-bot-events';

const
token = process.env.TEST_TOCKEN || '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
userId = process.env.TEST_USERID || 777000,
options = {
  autoUpdate: false,
  updateInterval: 1000,
  updateLimit: 50,
  updatePoolingTimeout: 0
},

expectToBePromise = (obj) => {
  expect(obj).to.be.an('object');
  expect(obj).to.have.property('then');
  expect(obj.then).to.be.a('function');
}
;

describe('telegram-bot-events', () => {
  var bot = new TelegramBotApi(token, options);
  after(() => {
    bot.stopAutoUpdate();
  })

  describe('new instance', () => {

    it('should have default options', () => {
      let bot = new TelegramBotApi(token);
      bot.stopAutoUpdate();
      expect(bot.options).to.be.eql(options);
    });

    it('should have default options with extend', () => {
      let bot = new TelegramBotApi(token, {});
      bot.stopAutoUpdate();
      expect(bot.options).to.be.eql(options);
    });

    it('should have extended options', () => {
      let bot = new TelegramBotApi(token, {foo: 'bar'});
      bot.stopAutoUpdate();
      expect(bot.options.foo).to.be.equal('bar');
    });

  });

  describe('events', () => {
    afterEach(() => {
      bot.offAll();
    });

    it('should have `on` method', () => {
      expect(bot).to.have.property('on');
      expect(bot.on).to.be.a('function');
    });

    it('should have `once` method', () => {
      expect(bot).to.have.property('once');
      expect(bot.once).to.be.a('function');
    });

    it('should have `off` method', () => {
      expect(bot).to.have.property('off');
      expect(bot.off).to.be.a('function');
    });

    it('should have `offAll` method', () => {
      expect(bot).to.have.property('offAll');
      expect(bot.offAll).to.be.a('function');
    });

    it('should have `events`', () => {
      expect(bot.events).to.be.a('object');
      expect(bot.events.on).to.be.a('function');
    });

    it('should can add listner', (done) => {
      let callback = function () {
        done('callback called !')
      };

      bot.on('junk', callback);
      let listeners = bot.events.listeners('junk');

      expect(listeners).to.be.an('array');
      expect(listeners.length).to.be.equal(1);
      expect(listeners[0]).to.be.equal(callback);
      done();
    });

    it('should can remove all special listners', (done) => {
      let callback1 = function () {
        done('callback1 called !')
      };
      bot.on('junk', callback1);
      bot.on('junk', callback1);

      let callback2 = function () {
        done('callback2 called !')
      };
      bot.on('junk', callback2);
      bot.on('junk', callback2);

      let callback3 = function () {
        done('callback3 called !')
      };
      bot.on('junk2', callback2);

      bot.offAll('junk');

      expect(bot.events.listeners('junk').length).to.be.equal(0);
      expect(bot.events.listeners('junk2').length).to.be.equal(1);
      done();
    });

    it('should can remove all listners', (done) => {
      let callback1 = function () {
        done('callback1 called !')
      };
      bot.on('junk', callback1);
      bot.on('junk', callback1);

      let callback2 = function () {
        done('callback2 called !')
      };
      bot.on('junk', callback2);
      bot.on('junk', callback2);

      let callback3 = function () {
        done('callback3 called !')
      };
      bot.on('junk2', callback2);

      bot.offAll();

      expect(bot.events.listeners('junk').length).to.be.equal(0);
      expect(bot.events.listeners('junk2').length).to.be.equal(0);
      done();
    });

    it('should can remove a special listner', (done) => {
      let callback1 = function () {
        done('callback1 called !')
      };
      bot.on('junk', callback1);

      let callback2 = function () {
        done('callback2 called !')
      };
      bot.on('junk', callback2);

      expect(bot.events.listeners('junk').length).to.be.equal(2); // also check offAll in afterEach

      bot.off('junk', callback1);

      expect(bot.events.listeners('junk').length).to.be.equal(1);
      expect(bot.events.listeners('junk')[0]).to.be.equal(callback2);
      done();
    });

  })

  describe('auto update', () => {
    afterEach(() => {
      bot.stopAutoUpdate();
      bot.offAll();
    });

    it('shout be stopAutoUpdated work', (done) => {
      let bot = new TelegramBotApi(token, options);
      bot.startAutoUpdate();

      setTimeout(()=>{
        bot.stopAutoUpdate();
        expect(bot._setTimeout._onTimeout).to.not.be.ok();
        expect(bot.options.autoUpdate).to.not.be.ok();
        bot.stopAutoUpdate();
        done();
      }, 200);
    });

    it('shout be not autoUpdated by default option', () => {
      let bot = new TelegramBotApi(token);
      expect(bot._setTimeout).to.not.be.ok();

      bot = new TelegramBotApi(token, {autoUpdate: false});
      expect(bot._setTimeout).to.not.be.ok();
    });

    it('shout be autoUpdated by default', () => {
      let bot = new TelegramBotApi(token, {autoUpdate: true});
      after(() => {
        bot.stopAutoUpdate();
      });
      expect(bot._setTimeout).to.be.ok();
    });

    it('shout be startAutoUpdated work', (done) => {
      let bot = new TelegramBotApi(token, {autoUpdate: false, updateInterval: 100});
      after(() => {
        bot.stopAutoUpdate();
      });
      expect(bot._setTimeout).to.not.be.ok();
      bot.startAutoUpdate();
      setTimeout(()=>{
        expect(bot._setTimeout).to.be.ok();
        bot.stopAutoUpdate();
        expect(bot._setTimeout._setTimeout).to.not.be.ok();
        done();
      }, 200);
    });

    it.skip('should trigger on update', (done) => {
      console.log('send message to this bot for test');
      bot.once('update', () => {
        done();
      });
      bot.startAutoUpdate();
    });

    it.skip('should trigger on message', (done) => {
      console.log('send message to this bot for test');
      bot.once('update.message', () => {
        done();
      });
      bot.startAutoUpdate();
    });

    it.skip('should trigger on inline_query', (done) => {
      console.log('send inline_query to this bot for test');
      bot.once('update.inline_query', () => {
        done();
      });
      bot.startAutoUpdate();
    });

  })

});
<|endoftext|>


<commit_before>

/**
 * Global view
 */
function Board( p_session, p_canvas_id ) {

	var self = this;

    this.name = "Board";

	var _real_canvas = null;
	var _context = null;
	var _zones = null;
	var _users = null;
	var _session = null;

	/**
	 * Constructor
	 */
	this.initialize = function( p_session, p_canvas_id ) {

		_real_canvas = document.getElementById( p_canvas_id );
		_context = _real_canvas.getContext('2d');

		_session = p_session;
		_session.register( self );
		_zones = {};
		_users = {};

		// fill zones with zones from session
		_zones[_session.user_zone.index] = new Zone(
				_session.user_zone.index,
				_session.user_zone.position,
				_session.zone_column_count,
				_session.zone_line_count
				);

		for (var i=0; i<p_session.other_zones.length; i++) {
			var z = p_session.other_zones[i];

			_zones[z.index] = new Zone(
					z.index, z.position,
					_session.zone_column_count, _session.zone_line_count
					);
		}
		console.log("board/initialize: zones = %s", JSON.stringify( _zones ) );
	}

	/**
	 *
	 */
	this.handle_event = function( ev ) {
		console.log("board/handle_event : %s", JSON.stringify( ev ) );
		if ( ev.type == 'join' ) {
			var z = ev.desc.zone;
			_zones[z.index] = new Zone(
					z.index, z.position,
					_session.zone_column_count, _session.zone_line_count
					);
		} else if ( ev.type == 'leave' ) {
			var z = ev.desc.zone;
			_zones[z.index] = null;
		} else {
			// unknown event...
		}
	}

	/**
	 *
	 */
	this.get_zone = function( index ) {
		// console.log("board/get_zone(%s) : %s", index, JSON.stringify( _zones[index] ) );
		return _zones[index];
	}

	/**
	 * Return the list of existing zone ids
	 */
	this.get_zone_list = function() {
		var keys = [];
		for(var i in _zones) {
			if (_zones.hasOwnProperty(i))
			{
				keys.push( parseInt(i,10) );
			}
		}
		// console.log("board/get_zone_list : %s", JSON.stringify( keys ));
		return keys;
	}

	/**
	 *
	 */
	this.handle_stroke = function( stk ) {
		console.log("board/handle_stroke : stroke = %s", JSON.stringify( stk ));
		console.log("board/handle_stroke : zones = %s", JSON.stringify( _zones ));
		var z = _zones[stk.zone];

		z.patch_apply( stk );
	}

	this.initialize(p_session, p_canvas_id);
}

<commit_msg>js board: does not need a canvas nor a context.<commit_after>

/**
 * Global view
 */
function Board( p_session ) {

	var self = this;

    this.name = "Board";

	var _real_canvas = null;
	var _context = null;
	var _zones = null;
	var _users = null;
	var _session = null;

	/**
	 * Constructor
	 */
	this.initialize = function( p_session ) {

		_session = p_session;
		_session.register( self );
		_zones = {};
		_users = {};

		// fill zones with zones from session
		_zones[_session.user_zone.index] = new Zone(
				_session.user_zone.index,
				_session.user_zone.position,
				_session.zone_column_count,
				_session.zone_line_count
				);

		for (var i=0; i<p_session.other_zones.length; i++) {
			var z = p_session.other_zones[i];

			_zones[z.index] = new Zone(
					z.index, z.position,
					_session.zone_column_count, _session.zone_line_count
					);
		}
		console.log("board/initialize: zones = %s", JSON.stringify( _zones ) );
	}

	/**
	 *
	 */
	this.handle_event = function( ev ) {
		console.log("board/handle_event : %s", JSON.stringify( ev ) );
		if ( ev.type == 'join' ) {
			var z = ev.desc.zone;
			_zones[z.index] = new Zone(
					z.index, z.position,
					_session.zone_column_count, _session.zone_line_count
					);
		} else if ( ev.type == 'leave' ) {
			var z = ev.desc.zone;
			_zones[z.index] = null;
		} else {
			// unknown event...
		}
	}

	/**
	 *
	 */
	this.get_zone = function( index ) {
		// console.log("board/get_zone(%s) : %s", index, JSON.stringify( _zones[index] ) );
		return _zones[index];
	}

	/**
	 * Return the list of existing zone ids
	 */
	this.get_zone_list = function() {
		var keys = [];
		for(var i in _zones) {
			if (_zones.hasOwnProperty(i))
			{
				keys.push( parseInt(i,10) );
			}
		}
		// console.log("board/get_zone_list : %s", JSON.stringify( keys ));
		return keys;
	}

	/**
	 *
	 */
	this.handle_stroke = function( stk ) {
		console.log("board/handle_stroke : stroke = %s", JSON.stringify( stk ));
		console.log("board/handle_stroke : zones = %s", JSON.stringify( _zones ));
		var z = _zones[stk.zone];

		z.patch_apply( stk );
	}

	this.initialize(p_session, p_canvas_id);
}

<|endoftext|>