<commit_before>/* global JasminePromiseMatchers */
import log from 'loglevel';
import websql from '../src';
import asyncTest from './helpers/asyncTest';

log.setLevel('trace');

describe('index', () => {
  it('should return object with db property set', () => {
    const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
    const websqlPromise = websql(db);
    expect(websqlPromise.db).toBe(db);
  });

  it('should return object with transaction function', () => {
    const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
    const websqlPromise = websql(db);
    expect(typeof websqlPromise.transaction).toBe('function');
  });

  describe('transaction', () => {
    it('should reject when no function passed',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);
      try {
        await websqlPromise.transaction();
        done.fail();
      } catch (error) {
        done();
      }
    }));

    it('should resolve empty array when no executeSql executions',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);
      const results = await websqlPromise.transaction(() => {});
      expect(results).toEqual([]);
      done();
    }));

    it('should execute given function passing object with executeSql function',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);
      await websqlPromise.transaction((tx) => {
        expect(typeof tx.executeSql).toBe('function');
        done();
      });
    }));

    it('should resolve array of results from queries',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);

      // Set up table
      await new Promise((resolve, reject) => {
        db.transaction((tx) => {
          tx.executeSql('DROP TABLE IF EXISTS logs');
          tx.executeSql('CREATE TABLE IF NOT EXISTS logs (log)');
        }, reject, resolve);
      });

      const result = await websqlPromise.transaction((tx) => {
        tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello1']);
        tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello2']);
        tx.executeSql('SELECT * FROM logs');
      });
      expect(result.length).toBe(3);
      expect(result[2].rows.item(0)).toEqual({ log: 'hello1' });
      expect(result[2].rows.item(1)).toEqual({ log: 'hello2' });
      done();
    }));

    it('should be able to execute parallel transactions',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);

      // Fill database
      await new Promise((resolve, reject) => {
        db.transaction((tx) => {
          tx.executeSql('DROP TABLE IF EXISTS logs');
          tx.executeSql('CREATE TABLE IF NOT EXISTS logs (log)');
          tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello1']);
          tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello2']);
        }, reject, resolve);
      });

      websqlPromise.transaction((tx) => {
        tx.executeSql('SELECT * FROM logs LIMIT 1');
      })
      .then((results) => {
        expect(results.length).toBe(1);
        expect(results[0].rows.length).toBe(1);
        expect(results[0].rows.item(0)).toEqual({ log: 'hello1' });
      });
      websqlPromise.transaction((tx) => {
        tx.executeSql('SELECT * FROM logs LIMIT 2');
      })
      .then((results) => {
        expect(results.length).toBe(1);
        expect(results[0].rows.length).toBe(2);
        expect(results[0].rows.item(0)).toEqual({ log: 'hello1' });
        expect(results[0].rows.item(1)).toEqual({ log: 'hello2' });
      });
      setTimeout(done, 100); // Ugly, but gets the job done
    }));

    describe('tx.executeSql', () => {
      it('should make transaction reject when called with no query',
      asyncTest(async (done) => {
        const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        const websqlPromise = websql(db);
        try {
          await websqlPromise.transaction((tx) => {
            tx.executeSql();
          });
          done.fail();
        } catch (error) {
          done();
        }
      }));

      it('should make transaction fail when given invalid query',
      asyncTest(async (done) => {
        const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        const websqlPromise = websql(db);
        try {
          await websqlPromise.transaction((tx) => {
            tx.executeSql('ASDF');
          });
          done.fail();
        } catch (error) {
          done();
        }
      }));

      describe('callback', () => {
        beforeEach(asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          // Fill database
          await new Promise((resolve, reject) => {
            db.transaction((tx) => {
              tx.executeSql('DROP TABLE IF EXISTS logs');
              tx.executeSql('CREATE TABLE IF NOT EXISTS logs (log)');
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello1']);
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello2']);
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello3']);
            }, reject, resolve);
          });
          done();
        }));

        it('should be called with tx that has correct executeSql',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from logs WHERE log = "hello1"', [],
              (chainTx) => {
                // Not the _same_ function since fakeTransaction returns new
                // instance, but the implementation should be the same.
                // Not perfect solution but it' is something.
                expect(chainTx.executeSql.toString())
                  .toEqual(tx.executeSql.toString());
                done();
              });
          });
        }));

        it('should be called with correct result',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from logs WHERE log = "hello1"', [],
              (tx, result) => {
                expect(result.rows.item(0).log).toEqual('hello1');
                done();
              });
          });
        }));

        it('should support nested callbacks with results in correct order',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          const result = await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from logs WHERE log = "hello1"', [],
            (tx) => {
              tx.executeSql('SELECT * from logs WHERE log = "hello2"', [],
              (tx) => {
                tx.executeSql('SELECT * from logs WHERE log = "hello3"');
              });
            });
          });

          expect(result[0].rows.item(0).log).toEqual('hello1');
          expect(result[0].rows.length).toBe(1);
          expect(result[1].rows.item(0).log).toEqual('hello2');
          expect(result[1].rows.length).toBe(1);
          expect(result[2].rows.item(0).log).toEqual('hello3');
          expect(result[2].rows.length).toBe(1);
          done();
        }));
      });

      describe('errorCallback', () => {
        beforeEach(asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          // Fill database
          await new Promise((resolve, reject) => {
            db.transaction((tx) => {
              tx.executeSql('DROP TABLE IF EXISTS logs');
              tx.executeSql('CREATE TABLE IF NOT EXISTS logs (log)');
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello1']);
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello2']);
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello3']);
            }, reject, resolve);
          });
          done();
        }));
        it('should be called with tx that has correct executeSql',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from nonExistingTable',
              [], () => {},
              (chainTx) => {
                expect(chainTx.executeSql.toString())
                  .toEqual(tx.executeSql.toString());
                done();
              });
          });
        }));

        it('should be called with correct error',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from nonExistingTable', [],
              () => {},
              (tx, error) => {
                expect(error.constructor.name).toEqual('SQLError');
                done();
              });
          });
        }));

        it('should support nested callbacks with results in correct order',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          const result = await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from nonExistingTable', [],
            () => {},
            (tx) => {
              tx.executeSql('SELECT * from logs WHERE log = "hello2"', [],
              (tx) => {
                tx.executeSql('SELECT * from logs WHERE log = "hello3"');
              });
            });
          });

          expect(result[0].constructor.name).toEqual('SQLError');
          expect(result[1].rows.item(0).log).toEqual('hello2');
          expect(result[1].rows.length).toBe(1);
          expect(result[2].rows.item(0).log).toEqual('hello3');
          expect(result[2].rows.length).toBe(1);
          done();
        }));
      });

      it('should continue execution when errorCallback return false',
      asyncTest(async (done) => {
        const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        const websqlPromise = websql(db);

        const result = await websqlPromise.transaction((tx) => {
        tx.executeSql('SELECT * from nonExistingTable', [],
          () => {},
          (tx) => {
            return false;
          });
          tx.executeSql('SELECT * from logs WHERE log = "hello2"', [],
          (tx) => {
          tx.executeSql('SELECT * from logs WHERE log = "hello3"');
          });
        });

        expect(result[0].constructor.name).toEqual('SQLError');
        expect(result[1].rows.item(0).log).toEqual('hello2');
        expect(result[1].rows.length).toBe(1);
        expect(result[2].rows.item(0).log).toEqual('hello3');
        expect(result[2].rows.length).toBe(1);
        done();
      }));

      it('should reject transaction when errorCallback return true',
      asyncTest(async (done) => {
        const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        const websqlPromise = websql(db);

        try {
          const result = await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from nonExistingTable', [],
            () => {},
            (tx) => {
              return true;
            });
          });
          done.fail();
        } catch (e) {
          done();
        }
      }));
    });
  });
});
<commit_msg>Fix failing tests<commit_after>/* global JasminePromiseMatchers */
import log from 'loglevel';
import websql from '../src';
import asyncTest from './helpers/asyncTest';

log.setLevel('trace');

describe('index', () => {
  it('should return object with db property set', () => {
    const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
    const websqlPromise = websql(db);
    expect(websqlPromise.db).toBe(db);
  });

  it('should return object with transaction function', () => {
    const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
    const websqlPromise = websql(db);
    expect(typeof websqlPromise.transaction).toBe('function');
  });

  describe('transaction', () => {
    it('should reject when no function passed',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);
      try {
        await websqlPromise.transaction();
        done.fail();
      } catch (error) {
        done();
      }
    }));

    it('should resolve empty array when no executeSql executions',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);
      const results = await websqlPromise.transaction(() => {});
      expect(results).toEqual([]);
      done();
    }));

    it('should execute given function passing object with executeSql function',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);
      await websqlPromise.transaction((tx) => {
        expect(typeof tx.executeSql).toBe('function');
        done();
      });
    }));

    it('should resolve array of results from queries',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);

      // Set up table
      await new Promise((resolve, reject) => {
        db.transaction((tx) => {
          tx.executeSql('DROP TABLE IF EXISTS logs');
          tx.executeSql('CREATE TABLE IF NOT EXISTS logs (log)');
        }, reject, resolve);
      });

      const result = await websqlPromise.transaction((tx) => {
        tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello1']);
        tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello2']);
        tx.executeSql('SELECT * FROM logs');
      });
      expect(result.length).toBe(3);
      expect(result[2].rows.item(0)).toEqual({ log: 'hello1' });
      expect(result[2].rows.item(1)).toEqual({ log: 'hello2' });
      done();
    }));

    it('should be able to execute parallel transactions',
    asyncTest(async (done) => {
      const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
      const websqlPromise = websql(db);

      // Fill database
      await new Promise((resolve, reject) => {
        db.transaction((tx) => {
          tx.executeSql('DROP TABLE IF EXISTS logs');
          tx.executeSql('CREATE TABLE IF NOT EXISTS logs (log)');
          tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello1']);
          tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello2']);
        }, reject, resolve);
      });

      websqlPromise.transaction((tx) => {
        tx.executeSql('SELECT * FROM logs LIMIT 1');
      })
      .then((results) => {
        expect(results.length).toBe(1);
        expect(results[0].rows.length).toBe(1);
        expect(results[0].rows.item(0)).toEqual({ log: 'hello1' });
      });
      websqlPromise.transaction((tx) => {
        tx.executeSql('SELECT * FROM logs LIMIT 2');
      })
      .then((results) => {
        expect(results.length).toBe(1);
        expect(results[0].rows.length).toBe(2);
        expect(results[0].rows.item(0)).toEqual({ log: 'hello1' });
        expect(results[0].rows.item(1)).toEqual({ log: 'hello2' });
      });
      setTimeout(done, 100); // Ugly, but gets the job done
    }));

    describe('tx.executeSql', () => {
      it('should make transaction reject when called with no query',
      asyncTest(async (done) => {
        const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        const websqlPromise = websql(db);
        try {
          await websqlPromise.transaction((tx) => {
            tx.executeSql();
          });
          done.fail();
        } catch (error) {
          done();
        }
      }));

      it('should make transaction fail when given invalid query',
      asyncTest(async (done) => {
        const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        const websqlPromise = websql(db);
        try {
          await websqlPromise.transaction((tx) => {
            tx.executeSql('ASDF');
          });
          done.fail();
        } catch (error) {
          done();
        }
      }));

      describe('callback', () => {
        beforeEach(asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          // Fill database
          await new Promise((resolve, reject) => {
            db.transaction((tx) => {
              tx.executeSql('DROP TABLE IF EXISTS logs');
              tx.executeSql('CREATE TABLE IF NOT EXISTS logs (log)');
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello1']);
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello2']);
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello3']);
            }, reject, resolve);
          });
          done();
        }));

        it('should be called with tx that has correct executeSql',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from logs WHERE log = "hello1"', [],
              (chainTx) => {
                // Not the _same_ function since fakeTransaction returns new
                // instance, but the implementation should be the same.
                // Not perfect solution but it' is something.
                expect(chainTx.executeSql.toString())
                  .toEqual(tx.executeSql.toString());
                done();
              });
          });
        }));

        it('should be called with correct result',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from logs WHERE log = "hello1"', [],
              (tx, result) => {
                expect(result.rows.item(0).log).toEqual('hello1');
                done();
              });
          });
        }));

        it('should support nested callbacks with results in correct order',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          const result = await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from logs WHERE log = "hello1"', [],
            (tx) => {
              tx.executeSql('SELECT * from logs WHERE log = "hello2"', [],
              (tx) => {
                tx.executeSql('SELECT * from logs WHERE log = "hello3"');
              });
            });
          });

          expect(result[0].rows.item(0).log).toEqual('hello1');
          expect(result[0].rows.length).toBe(1);
          expect(result[1].rows.item(0).log).toEqual('hello2');
          expect(result[1].rows.length).toBe(1);
          expect(result[2].rows.item(0).log).toEqual('hello3');
          expect(result[2].rows.length).toBe(1);
          done();
        }));
      });

      describe('errorCallback', () => {
        beforeEach(asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          // Fill database
          await new Promise((resolve, reject) => {
            db.transaction((tx) => {
              tx.executeSql('DROP TABLE IF EXISTS logs');
              tx.executeSql('CREATE TABLE IF NOT EXISTS logs (log)');
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello1']);
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello2']);
              tx.executeSql('INSERT INTO logs (log) VALUES (?)', ['hello3']);
            }, reject, resolve);
          });
          done();
        }));
        it('should be called with tx that has correct executeSql',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from nonExistingTable',
              [], () => {},
              (chainTx) => {
                expect(chainTx.executeSql.toString())
                  .toEqual(tx.executeSql.toString());
                done();
              });
          });
        }));

        it('should be called with correct error',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from nonExistingTable', [],
              () => {},
              (tx, error) => {
                expect(error.message)
                  .toEqual('could not prepare statement (1 no such table: ' +
                  'nonExistingTable)');
                done();
              });
          });
        }));

        it('should support nested callbacks with results in correct order',
        asyncTest(async (done) => {
          const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
          const websqlPromise = websql(db);

          const result = await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from nonExistingTable', [],
            () => {},
            (tx) => {
              tx.executeSql('SELECT * from logs WHERE log = "hello2"', [],
              (tx) => {
                tx.executeSql('SELECT * from logs WHERE log = "hello3"');
              });
            });
          });

          expect(result[0].message)
            .toEqual('could not prepare statement (1 no such table: ' +
            'nonExistingTable)');
          expect(result[1].rows.item(0).log).toEqual('hello2');
          expect(result[1].rows.length).toBe(1);
          expect(result[2].rows.item(0).log).toEqual('hello3');
          expect(result[2].rows.length).toBe(1);
          done();
        }));
      });

      it('should continue execution when errorCallback return false',
      asyncTest(async (done) => {
        const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        const websqlPromise = websql(db);

        const result = await websqlPromise.transaction((tx) => {
        tx.executeSql('SELECT * from nonExistingTable', [],
          () => {},
          (tx) => {
            return false;
          });
          tx.executeSql('SELECT * from logs WHERE log = "hello2"', [],
          (tx) => {
          tx.executeSql('SELECT * from logs WHERE log = "hello3"');
          });
        });

        expect(result[0].message)
          .toEqual('could not prepare statement (1 no such table: ' +
          'nonExistingTable)');
        expect(result[1].rows.item(0).log).toEqual('hello2');
        expect(result[1].rows.length).toBe(1);
        expect(result[2].rows.item(0).log).toEqual('hello3');
        expect(result[2].rows.length).toBe(1);
        done();
      }));

      it('should reject transaction when errorCallback return true',
      asyncTest(async (done) => {
        const db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
        const websqlPromise = websql(db);

        try {
          const result = await websqlPromise.transaction((tx) => {
            tx.executeSql('SELECT * from nonExistingTable', [],
            () => {},
            (tx) => {
              return true;
            });
          });
          done.fail();
        } catch (e) {
          done();
        }
      }));
    });
  });
});
<|endoftext|>


<commit_before>'use strict';

var expect = require('expect.js');
var React = require('react/addons');
var TestUtils = React.addons.TestUtils;
var Simulate = TestUtils.Simulate;
var $ = require('jquery');
window.$ = $;
require('../assets/bootstrap.less');
var Tooltip = require('../index');
var scryRenderedDOMComponentsWithClass = TestUtils.scryRenderedDOMComponentsWithClass;
require('./test.less');
var async = require('async');

function timeout(ms) {
  return (done)=> {
    setTimeout(done, ms);
  }
}

describe('rc-tooltip', function () {
  this.timeout(40000);
  var div = document.createElement('div');
  div.style.margin = '100px';
  document.body.insertBefore(div, document.body.firstChild);

  afterEach(()=> {
    React.unmountComponentAtNode(div);
  });

  describe('trigger', ()=> {
    it('click works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="left"
                                          overlay={tooltip2}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      async.series([timeout(20), (next)=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect($(popupDomNode).find('.x-content').html()).to.be('tooltip2');
        expect(popupDomNode).to.be.ok();
        Simulate.click(domNode);
        next();
      }, timeout(20), (next)=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect($(popupDomNode).css('display')).to.be('none');
        next();
      }], done);
    });

    it('hover works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['hover']}
                                          placement="left"
                                          overlay={tooltip}>

click

      </Tooltip>, div);
      var target = scryRenderedDOMComponentsWithClass(tooltip, 'target')[0];
      // can not simulate mouseenter
      target.props.onMouseEnter();
      async.series([timeout(200), (next)=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        target.props.onMouseLeave();
        next();
      }, timeout(200), (next)=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect($(popupDomNode).css('display')).to.be('none');
        next();
      }], done);
    });
  });

  describe('placement', ()=> {
    it('left works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="left"
                                          overlayStyle={{width:50}}
                                          overlay={
tooltip
}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        expect(popupOffset.left + $(popupDomNode).outerWidth()).to.be(targetOffset.left-3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('auto adjust left works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="left"
                                          overlayStyle={{width:400}}
                                          overlay={
tooltip
}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        // offset is 3
        expect(popupOffset.left).to.be(targetOffset.left + $(domNode).outerWidth() + 3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('right works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="right" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.left).to.be(targetOffset.left + $(domNode).outerWidth()+3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('bottom works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="bottom" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top + $(domNode).outerHeight()+3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('bottomRight works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="bottomRight"
                                          overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top + $(domNode).outerHeight()+3);
        expect(arrowOffset.left).to.be(180);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('bottomLeft works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="bottomLeft" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top + $(domNode).outerHeight()+3);
        expect(arrowOffset.left).to.be(110);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('top works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="top" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top - $(popupDomNode).outerHeight()-3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('topLeft works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="topLeft" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top - $(popupDomNode).outerHeight()-3);
        expect(popupOffset.left).to.be(targetOffset.left);
        expect(arrowOffset.left).to.be(110);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('topRight works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="topRight" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top - $(popupDomNode).outerHeight()-3);
        expect(popupOffset.left).to.be(targetOffset.left);
        expect(arrowOffset.left).to.be(180);
        Simulate.click(domNode);
        done();
      }, 20);
    });
  });

  if (window.TransitionEvent) {
    it('transitionName works', (done)=> {
      var tooltip = React.render(<Tooltip
        trigger={['click']}
        transitionName="fade"
        placement="top"
        overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      async.series([
          timeout(100),
          (next)=> {
            var popupDomNode = tooltip.getPopupDomNode();
            expect(popupDomNode).to.be.ok();
            expect($(popupDomNode).css('opacity')).not.to.be('1');
            next();
          },
          timeout(500),
          (next)=> {
            var popupDomNode = tooltip.getPopupDomNode();
            expect(popupDomNode).to.be.ok();
            expect($(popupDomNode).css('opacity')).to.be('1');
            Simulate.click(domNode);
            next();
          },
          timeout(100),
          (next)=> {
            var popupDomNode = tooltip.getPopupDomNode();
            expect(popupDomNode).to.be.ok();

            expect($(popupDomNode).css('opacity')).not.to.be('1');
            next();
          },
          timeout(500),
          (next)=> {
            var popupDomNode = tooltip.getPopupDomNode();
            expect($(popupDomNode).css('display')).to.be('none');
            next();
          }],
        done);
    });
  }
});
<commit_msg>fix tc<commit_after>'use strict';

var expect = require('expect.js');
var React = require('react/addons');
var TestUtils = React.addons.TestUtils;
var Simulate = TestUtils.Simulate;
var $ = require('jquery');
window.$ = $;
require('../assets/bootstrap.less');
var Tooltip = require('../index');
var scryRenderedDOMComponentsWithClass = TestUtils.scryRenderedDOMComponentsWithClass;
require('./test.less');
var async = require('async');

function timeout(ms) {
  return (done)=> {
    setTimeout(done, ms);
  }
}

describe('rc-tooltip', function () {
  this.timeout(40000);
  var div = document.createElement('div');
  div.style.margin = '100px';
  document.body.insertBefore(div, document.body.firstChild);

  afterEach(()=> {
    React.unmountComponentAtNode(div);
  });

  describe('trigger', ()=> {
    it('click works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="left"
                                          overlay={tooltip2}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      async.series([timeout(20), (next)=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect($(popupDomNode).find('.x-content').html()).to.be('tooltip2');
        expect(popupDomNode).to.be.ok();
        Simulate.click(domNode);
        next();
      }, timeout(20), (next)=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect($(popupDomNode).css('display')).to.be('none');
        next();
      }], done);
    });

    it('hover works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['hover']}
                                          placement="left"
                                          overlay={tooltip}>

click

      </Tooltip>, div);
      var target = scryRenderedDOMComponentsWithClass(tooltip, 'target')[0];
      // can not simulate mouseenter
      target.props.onMouseEnter();
      async.series([timeout(200), (next)=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        target.props.onMouseLeave();
        next();
      }, timeout(200), (next)=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect($(popupDomNode).css('display')).to.be('none');
        next();
      }], done);
    });
  });

  describe('placement', ()=> {
    it('left works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="left"
                                          overlayStyle={{width:50}}
                                          overlay={
tooltip
}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        expect(popupOffset.left + $(popupDomNode).outerWidth()).to.be(targetOffset.left-3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('auto adjust left works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="left"
                                          overlayStyle={{width:400}}
                                          overlay={
tooltip
}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        // offset is 3
        if(!window.callPhantom) {
          expect(popupOffset.left).to.be(targetOffset.left + $(domNode).outerWidth() + 3);
        }
        done();
      }, 100);
    });

    it('right works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="right" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.left).to.be(targetOffset.left + $(domNode).outerWidth()+3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('bottom works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="bottom" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top + $(domNode).outerHeight()+3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('bottomRight works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="bottomRight"
                                          overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top + $(domNode).outerHeight()+3);
        expect(arrowOffset.left).to.be(180);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('bottomLeft works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="bottomLeft" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top + $(domNode).outerHeight()+3);
        expect(arrowOffset.left).to.be(110);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('top works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="top" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top - $(popupDomNode).outerHeight()-3);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('topLeft works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="topLeft" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top - $(popupDomNode).outerHeight()-3);
        expect(popupOffset.left).to.be(targetOffset.left);
        expect(arrowOffset.left).to.be(110);
        Simulate.click(domNode);
        done();
      }, 20);
    });

    it('topRight works', (done)=> {
      var tooltip = React.render(<Tooltip trigger={['click']} placement="topRight" overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      setTimeout(()=> {
        var popupDomNode = tooltip.getPopupDomNode();
        expect(popupDomNode).to.be.ok();
        var targetOffset = $(domNode).offset();
        var popupOffset = $(popupDomNode).offset();
        var arrowOffset = $(popupDomNode).find('.rc-tooltip-arrow').offset();
        console.log(popupOffset, targetOffset);
        expect(popupOffset.top).to.be(targetOffset.top - $(popupDomNode).outerHeight()-3);
        expect(popupOffset.left).to.be(targetOffset.left);
        expect(arrowOffset.left).to.be(180);
        Simulate.click(domNode);
        done();
      }, 20);
    });
  });

  if (window.TransitionEvent) {
    it('transitionName works', (done)=> {
      var tooltip = React.render(<Tooltip
        trigger={['click']}
        transitionName="fade"
        placement="top"
        overlay={tooltip}>

click

      </Tooltip>, div);
      var domNode = React.findDOMNode(tooltip).firstChild;
      Simulate.click(domNode);
      async.series([
          timeout(100),
          (next)=> {
            var popupDomNode = tooltip.getPopupDomNode();
            expect(popupDomNode).to.be.ok();
            expect($(popupDomNode).css('opacity')).not.to.be('1');
            next();
          },
          timeout(500),
          (next)=> {
            var popupDomNode = tooltip.getPopupDomNode();
            expect(popupDomNode).to.be.ok();
            expect($(popupDomNode).css('opacity')).to.be('1');
            Simulate.click(domNode);
            next();
          },
          timeout(100),
          (next)=> {
            var popupDomNode = tooltip.getPopupDomNode();
            expect(popupDomNode).to.be.ok();

            expect($(popupDomNode).css('opacity')).not.to.be('1');
            next();
          },
          timeout(500),
          (next)=> {
            var popupDomNode = tooltip.getPopupDomNode();
            expect($(popupDomNode).css('display')).to.be('none');
            next();
          }],
        done);
    });
  }
});
<|endoftext|>


<commit_before>import assert from 'assert';
import oq from '../src/index';

describe('oq.format()', () => {
    [
        [
            'a',
            'a'
        ],
        [
            ['a'],
            'a'
        ],
        [
            [[0, 2]],
            '[0,2]'
        ],
        [
            [{start: 0, end: 2}],
            '[0:2]'
        ],
        [
            [1],
            '[1]'
        ],
        [
            [1, 2],
            '[1][2]'
        ],
        [
            ['a', 'b', {start: 0, end: 2}, 1, 2, [1, 2, 3]],
            'a.b[0:2][1][2][1,2,3]'
        ]
    ].forEach((test) => {
            let [query, expected] = test;

            it(`returns "${expected}" for query ${JSON.stringify(query)}`, () => {
                assert.strictEqual(oq.format(query), expected);
            });
        });
});

describe('oq.parse()', () => {
    [
        [
            ['a'],
            ['a']
        ],
        [
            'a',
            ['a']
        ],
        [
            '[0,2]',
            [[0, 2]]
        ],
        [
            '[0:2]',
            [{start: 0, end: 2}]
        ],
        [
            '[1]',
            [1]
        ],
        [
            '[1][2]',
            [1, 2]
        ],
        [
            'a.b[0:2][1][2][1,2,3]',
            ['a', 'b', {start: 0, end: 2}, 1, 2, [1, 2, 3]]
        ]
    ].forEach((test) => {
            let [query, expected] = test;

            it(`returns ${JSON.stringify(expected)} for query "${query}"`, () => {
                assert.deepEqual(oq.parse(query), expected);
            });
        });
});

describe('oq.get()', () => {
    const ARRAY_OF_SCALARS = [1, 2, 3, 4, 5, 6];
    const ARRAY_OF_OBJECTS = [
        {a: 1, b: {c: 1}, d: [null, {e: 1, f: [{g: 1, h: [1, 2, 3, 4]}]}]},
        {a: 2, b: {c: 2}, d: [null, {e: 2, f: [{g: 2, h: [2, 3, 4, 5]}]}]},
        {a: 3, b: {c: 3}, d: [null, {e: 3, f: [{g: 3, h: [3, 4, 5, 6]}]}]}
    ];
    const OBJECT = {
        a: 1,
        b: {
            c: 1
        }
    };

    it('oq === oq.get', () => {
        assert.strictEqual(oq, oq.get);
    });

    it('returns a function', () => {
        let o = oq.get('test');
        assert.strictEqual(typeof o, 'function');
    });

    describe('run query', () => {
        [
            [
                ARRAY_OF_SCALARS,
                '[0, 1, 2]',
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                [[0, 1, 2]],
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                '[*]',
                [
                    1, 2, 3, 4, 5, 6
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                [true],
                [
                    1, 2, 3, 4, 5, 6
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                '[0:3]',
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                [{start: 0, end: 3}],
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].a',
                [1, 2, 3]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'a'],
                [1, 2, 3]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].aa',
                [undefined, undefined, undefined]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'aa'],
                [undefined, undefined, undefined]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].b.c',
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'b', 'c'],
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h',
                [
                    [1, 2, 3, 4],
                    [2, 3, 4, 5],
                    [3, 4, 5, 6]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h'],
                [
                    [1, 2, 3, 4],
                    [2, 3, 4, 5],
                    [3, 4, 5, 6]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h[0]',
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h', 0],
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h[*]',
                [
                    [1, 2, 3, 4],
                    [2, 3, 4, 5],
                    [3, 4, 5, 6]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h', true],
                [
                    [1, 2, 3, 4],
                    [2, 3, 4, 5],
                    [3, 4, 5, 6]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h[0, 2]',
                [
                    [1, 3],
                    [2, 4],
                    [3, 5]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h', [0, 2]],
                [
                    [1, 3],
                    [2, 4],
                    [3, 5]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h[0:3]',
                [
                    [1, 2, 3],
                    [2, 3, 4],
                    [3, 4, 5]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h', {start: 0, end: 3}],
                [
                    [1, 2, 3],
                    [2, 3, 4],
                    [3, 4, 5]
                ]
            ],
            [
                OBJECT,
                'a',
                1
            ],
            [
                OBJECT,
                ['a'],
                1
            ],
            [
                OBJECT,
                'b.c',
                1
            ],
            [
                OBJECT,
                ['b', 'c'],
                1
            ]
        ].forEach((test) => {
                let [data, query, expected] = test;

                it(`returns correct result for ${(typeof query == 'string' ? '"' + query + '"': JSON.stringify(query))}`, () => {
                    let getter = oq.get(query);

                    assert.deepEqual(getter(data), expected);
                });
            });
    });
});
<commit_msg>oq !== oq.get now<commit_after>import assert from 'assert';
import oq from '../src/index';

describe('oq.format()', () => {
    [
        [
            'a',
            'a'
        ],
        [
            ['a'],
            'a'
        ],
        [
            [[0, 2]],
            '[0,2]'
        ],
        [
            [{start: 0, end: 2}],
            '[0:2]'
        ],
        [
            [1],
            '[1]'
        ],
        [
            [1, 2],
            '[1][2]'
        ],
        [
            ['a', 'b', {start: 0, end: 2}, 1, 2, [1, 2, 3]],
            'a.b[0:2][1][2][1,2,3]'
        ]
    ].forEach((test) => {
            let [query, expected] = test;

            it(`returns "${expected}" for query ${JSON.stringify(query)}`, () => {
                assert.strictEqual(oq.format(query), expected);
            });
        });
});

describe('oq.parse()', () => {
    [
        [
            ['a'],
            ['a']
        ],
        [
            'a',
            ['a']
        ],
        [
            '[0,2]',
            [[0, 2]]
        ],
        [
            '[0:2]',
            [{start: 0, end: 2}]
        ],
        [
            '[1]',
            [1]
        ],
        [
            '[1][2]',
            [1, 2]
        ],
        [
            'a.b[0:2][1][2][1,2,3]',
            ['a', 'b', {start: 0, end: 2}, 1, 2, [1, 2, 3]]
        ]
    ].forEach((test) => {
            let [query, expected] = test;

            it(`returns ${JSON.stringify(expected)} for query "${query}"`, () => {
                assert.deepEqual(oq.parse(query), expected);
            });
        });
});

describe('oq.get()', () => {
    const ARRAY_OF_SCALARS = [1, 2, 3, 4, 5, 6];
    const ARRAY_OF_OBJECTS = [
        {a: 1, b: {c: 1}, d: [null, {e: 1, f: [{g: 1, h: [1, 2, 3, 4]}]}]},
        {a: 2, b: {c: 2}, d: [null, {e: 2, f: [{g: 2, h: [2, 3, 4, 5]}]}]},
        {a: 3, b: {c: 3}, d: [null, {e: 3, f: [{g: 3, h: [3, 4, 5, 6]}]}]}
    ];
    const OBJECT = {
        a: 1,
        b: {
            c: 1
        }
    };

    it('returns a function', () => {
        let o = oq.get('test');
        assert.strictEqual(typeof o, 'function');
    });

    describe('run query', () => {
        [
            [
                ARRAY_OF_SCALARS,
                '[0, 1, 2]',
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                [[0, 1, 2]],
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                '[*]',
                [
                    1, 2, 3, 4, 5, 6
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                [true],
                [
                    1, 2, 3, 4, 5, 6
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                '[0:3]',
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_SCALARS,
                [{start: 0, end: 3}],
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].a',
                [1, 2, 3]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'a'],
                [1, 2, 3]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].aa',
                [undefined, undefined, undefined]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'aa'],
                [undefined, undefined, undefined]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].b.c',
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'b', 'c'],
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h',
                [
                    [1, 2, 3, 4],
                    [2, 3, 4, 5],
                    [3, 4, 5, 6]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h'],
                [
                    [1, 2, 3, 4],
                    [2, 3, 4, 5],
                    [3, 4, 5, 6]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h[0]',
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h', 0],
                [
                    1, 2, 3
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h[*]',
                [
                    [1, 2, 3, 4],
                    [2, 3, 4, 5],
                    [3, 4, 5, 6]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h', true],
                [
                    [1, 2, 3, 4],
                    [2, 3, 4, 5],
                    [3, 4, 5, 6]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h[0, 2]',
                [
                    [1, 3],
                    [2, 4],
                    [3, 5]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h', [0, 2]],
                [
                    [1, 3],
                    [2, 4],
                    [3, 5]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                '[*].d[1].f[0].h[0:3]',
                [
                    [1, 2, 3],
                    [2, 3, 4],
                    [3, 4, 5]
                ]
            ],
            [
                ARRAY_OF_OBJECTS,
                [true, 'd', 1, 'f', 0, 'h', {start: 0, end: 3}],
                [
                    [1, 2, 3],
                    [2, 3, 4],
                    [3, 4, 5]
                ]
            ],
            [
                OBJECT,
                'a',
                1
            ],
            [
                OBJECT,
                ['a'],
                1
            ],
            [
                OBJECT,
                'b.c',
                1
            ],
            [
                OBJECT,
                ['b', 'c'],
                1
            ]
        ].forEach((test) => {
                let [data, query, expected] = test;

                it(`returns correct result for ${(typeof query == 'string' ? '"' + query + '"': JSON.stringify(query))}`, () => {
                    let getter = oq.get(query);

                    assert.deepEqual(getter(data), expected);
                });
            });
    });
});
<|endoftext|>


<commit_before>// Karma configuration
// Generated on Sun May 08 2016 23:14:26 GMT-0700 (PDT)

module.exports = function(config) {
  var settings = {

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '..',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],

    // list of files / patterns to load in the browser
    files: [
      //{pattern: 'node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js', watched: false, included: true, served: true},
      //{pattern: 'tests/boot.js', watched: true, included: true, served: true},
      //{pattern: 'build/*', watched: true, included: true, served: true},
      {pattern: 'build/janusweb.js', watched: true, included: true, served: true},
      {pattern: 'build/janusweb.assetworker.js', watched: true, included: false, served: true},
      {pattern: 'build/janusweb.css', watched: true, included: true, served: true},
      {pattern: 'build/media/*', watched: false, included: false, served: true},
      {pattern: 'build/media/**', watched: false, included: false, served: true},
      //'tests/imagediff.js',
      //{pattern: 'tests/janusweb.test.js', watched: true, included: true, served: true},
      {pattern: 'tests/assets/*.test.js', watched: true, included: true, served: true},
      {pattern: 'tests/render/*.test.js', watched: true, included: true, served: true},
      {pattern: 'tests/room.test.js', watched: true, included: true, served: true},
    ],

    // list of files to exclude
    exclude: [
    ],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],

    // web server port
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_WARN,

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,

    customLaunchers: {
        Chrome_travis_ci: {
            base: 'Chrome',
            flags: ['--no-sandbox', '--enable-webgl', '--ignore-gpu-blacklist']
        }
    },

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    //browsers: ['Chrome', 'Firefox'],
    //browsers: ['Chrome_travis_ci'],
    browsers: ['ChromeHeadless'],
    browserNoActivityTimeout: 60000,

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  };

  if (process.env.TRAVIS) {
    //settings.browsers = ['Chrome_travis_ci'];
  }

  config.set(settings);
}
<commit_msg>Disabled texture tests for now<commit_after>// Karma configuration
// Generated on Sun May 08 2016 23:14:26 GMT-0700 (PDT)

module.exports = function(config) {
  var settings = {

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '..',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],

    // list of files / patterns to load in the browser
    files: [
      //{pattern: 'node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js', watched: false, included: true, served: true},
      //{pattern: 'tests/boot.js', watched: true, included: true, served: true},
      //{pattern: 'build/*', watched: true, included: true, served: true},
      {pattern: 'build/janusweb.js', watched: true, included: true, served: true},
      {pattern: 'build/janusweb.assetworker.js', watched: true, included: false, served: true},
      {pattern: 'build/janusweb.css', watched: true, included: true, served: true},
      {pattern: 'build/media/*', watched: false, included: false, served: true},
      {pattern: 'build/media/**', watched: false, included: false, served: true},
      //'tests/imagediff.js',
      //{pattern: 'tests/janusweb.test.js', watched: true, included: true, served: true},
      {pattern: 'tests/assets/*.test.js', watched: true, included: true, served: true},
      //{pattern: 'tests/render/*.test.js', watched: true, included: true, served: true},
      {pattern: 'tests/room.test.js', watched: true, included: true, served: true},
    ],

    // list of files to exclude
    exclude: [
    ],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],

    // web server port
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_WARN,

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,

    customLaunchers: {
        Chrome_travis_ci: {
            base: 'Chrome',
            flags: ['--no-sandbox', '--enable-webgl', '--ignore-gpu-blacklist']
        }
    },

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    //browsers: ['Chrome', 'Firefox'],
    //browsers: ['Chrome_travis_ci'],
    browsers: ['ChromeHeadless'],
    browserNoActivityTimeout: 60000,

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  };

  if (process.env.TRAVIS) {
    //settings.browsers = ['Chrome_travis_ci'];
  }

  config.set(settings);
}
<|endoftext|>


<commit_before>"use strict";

const _ = require( 'underscore' );
const Backbone = require( 'backbone' );
//require( 'backbone-event-logger' );

const VariableListCollection = require( '../collections/dirPickerVariableList' );

//noinspection JSUnusedGlobalSymbols
/**
 * @class
 * @extends {Backbone.Model}
 */
const ModelsDirPickerVariable = Backbone.Model.extend( {
  /**
   * @type {CollectionsDirPickerVariableList}
   */
  listCollection: undefined,
  defaults      : {
    "name": '名称未設変数',
    "list": []
  },
  initialize    : function ( attributes ) {
    //this.debugEvents('ModelsVariable');
    const _self = this;
    this.set( 'name', this.makeUniqueName( (attributes && attributes.name) || this.defaults.name ) );
    this.set( 'list', (attributes && attributes.list) || this.defaults.list );
    this.listCollection = new VariableListCollection( this.get( 'list' ) );
    this.listCollection.on( 'change', function () {
      _self.updateList();
    } );
    this.listCollection.on( 'add', function () {
      _self.trigger( 'badgeUpdate' );
      _self.updateList();
    } );
    this.listCollection.on( 'remove', function () {
      _self.trigger( 'badgeUpdate' );
      _self.updateList();
    } );
  },
  updateList    : function () {
    this.save( 'list', _.map( this.listCollection.sort( {silent: true} ).toJSON(), function ( listRow ) {
      return _.pick( listRow, 'label', 'val' );
    } ), {wait: true, silent: true} );
  }
} );
_.extend( ModelsDirPickerVariable.prototype, require( './mixin' ) );

module.exports = ModelsDirPickerVariable;
<commit_msg>Refactor to ES6<commit_after>"use strict";

import _ from 'underscore';
import DirPickerModelBase from './dirPickerModelBase';
import VariableListCollection from '../collections/dirPickerVariableList';

/**
 * 定義済み変数を表すモデル
 */
export default class DirPickerVariable extends DirPickerModelBase {

  /**
   * @param {object} [attr]
   * @param {object} [options]
   */
  constructor ( attr, options ) {
    super( attr, options );
    this.debugEvents( 'ModelsVariable' );

    this.set( 'name', this.makeUniqueName( (attr && attr.name) || this.defaults.name ) );
    this.set( 'list', (attr && attr.list) || this.defaults.list );

    /**
     * @type {DirPickerVariableList}
     */
    this.listCollection = new VariableListCollection( this.get( 'list' ) );
    this.listCollection.on( 'change', ()=> {
      this.updateList();
    } );
    this.listCollection.on( 'add remove', ()=> {
      this.trigger( 'badgeUpdate' );
      this.updateList();
    } );

    this.on( 'destroy', ()=> {
      this.listCollection.off();
    } );
  }

  //noinspection JSMethodCanBeStatic
  /**
   *
   * @returns {{name: '名称未設変数', list: Array}}
   */
  get defaults () {
    return {
      "name": '名称未設変数',
      "list": []
    }
  }

  /**
   *
   */
  updateList () {
    this.save( 'list', _.map( this.listCollection.sort( {silent: true} ).toJSON(), ( listRow )=> {
      return _.pick( listRow, 'label', 'val' );
    } ), {wait: true, silent: true} );
  }
}
<|endoftext|>


<commit_before>var allBrowsers = process.env.ALL
var projectName = require('../package').name

const customLaunchers = {
  BS_Chrome: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '10',
    browser: 'chrome',
    browser_version: '47.0'
  },
  BS_Firefox: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '10',
    browser: 'firefox',
    browser_version: '43.0'
  },
  BS_Safari: {
    base: 'BrowserStack',
    os: 'OS X',
    os_version: 'El Capitan',
    browser: 'safari',
    browser_version: '9.0'
  },
  BS_MobileSafari8: {
    base: 'BrowserStack',
    os: 'ios',
    os_version: '8.3',
    browser: 'iphone',
    real_mobile: false
  },
  BS_MobileSafari9: {
    base: 'BrowserStack',
    os: 'ios',
    os_version: '9.1',
    browser: 'iphone',
    real_mobile: false
  },
  BS_InternetExplorer9: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '7',
    browser: 'ie',
    browser_version: '9.0'
  },
  BS_InternetExplorer10: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '8',
    browser: 'ie',
    browser_version: '10.0'
  },
  BS_InternetExplorer11: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '10',
    browser: 'ie',
    browser_version: '11.0'
  }
}

module.exports = function (config) {
  config.set({
    frameworks: [ 'browserify', 'mocha' ],
    browsers: allBrowsers ? [ 'PhantomJS', 'Firefox', 'Chrome', 'Safari', 'MobileSafari' ] : [ 'PhantomJS' ],
    reporters: [ 'mocha' ],
    preprocessors: {
      'index.js': [ 'browserify' ]
    },
    files: [ 'index.js' ],
    browserify: {
      transform: [ [
        'babelify', {
          presets: [ 'es2015', 'stage-0', 'react' ]
        }
      ], 'envify' ]
    }
  })

  if (process.env.USE_CLOUD) {
    config.customLaunchers = customLaunchers
    config.browsers = Object.keys(customLaunchers)
    config.reporters = [ 'dots' ]
    config.concurrency = 2

    config.browserDisconnectTimeout = 10000
    config.browserDisconnectTolerance = 3

    if (process.env.TRAVIS) {
      config.browserStack = {
        project: projectName,
        build: process.env.TRAVIS_BUILD_NUMBER,
        name: process.env.TRAVIS_JOB_NUMBER
      }

      config.singleRun = true
    } else {
      config.browserStack = {
        project: projectName
      }
    }

  }
}
<commit_msg>lose mobile safari in runners<commit_after>var allBrowsers = process.env.ALL
var projectName = require('../package').name

const customLaunchers = {
  BS_Chrome: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '10',
    browser: 'chrome',
    browser_version: '47.0'
  },
  BS_Firefox: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '10',
    browser: 'firefox',
    browser_version: '43.0'
  },
  BS_Safari: {
    base: 'BrowserStack',
    os: 'OS X',
    os_version: 'El Capitan',
    browser: 'safari',
    browser_version: '9.0'
  },
  BS_MobileSafari8: {
    base: 'BrowserStack',
    os: 'ios',
    os_version: '8.3',
    browser: 'iphone',
    real_mobile: false
  },
  BS_MobileSafari9: {
    base: 'BrowserStack',
    os: 'ios',
    os_version: '9.1',
    browser: 'iphone',
    real_mobile: false
  },
  BS_InternetExplorer9: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '7',
    browser: 'ie',
    browser_version: '9.0'
  },
  BS_InternetExplorer10: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '8',
    browser: 'ie',
    browser_version: '10.0'
  },
  BS_InternetExplorer11: {
    base: 'BrowserStack',
    os: 'Windows',
    os_version: '10',
    browser: 'ie',
    browser_version: '11.0'
  }
}

module.exports = function (config) {
  config.set({
    frameworks: [ 'browserify', 'mocha' ],
    browsers: allBrowsers ? [ 'PhantomJS', 'Firefox', 'Chrome', 'Safari' ] : [ 'PhantomJS' ],
    reporters: [ 'mocha' ],
    preprocessors: {
      'index.js': [ 'browserify' ]
    },
    files: [ 'index.js' ],
    browserify: {
      transform: [ [
        'babelify', {
          presets: [ 'es2015', 'stage-0', 'react' ]
        }
      ], 'envify' ]
    }
  })

  if (process.env.USE_CLOUD) {
    config.customLaunchers = customLaunchers
    config.browsers = Object.keys(customLaunchers)
    config.reporters = [ 'dots' ]
    config.concurrency = 2

    config.browserDisconnectTimeout = 10000
    config.browserDisconnectTolerance = 3

    if (process.env.TRAVIS) {
      config.browserStack = {
        project: projectName,
        build: process.env.TRAVIS_BUILD_NUMBER,
        name: process.env.TRAVIS_JOB_NUMBER
      }

      config.singleRun = true
    } else {
      config.browserStack = {
        project: projectName
      }
    }

  }
}
<|endoftext|>


<commit_before><commit_msg>remove unused test file<commit_after><|endoftext|>


<commit_before>/* eslint-env mocha */
import React from 'react';
import ReactDOM from 'react-dom';
import {assert} from 'chai';
import {spy} from 'sinon';
import Portal from './Portal';
import {createMountWithContext} from 'test/utils';

describe('<Portal>', () => {
  let mount;

  before(() => mount = createMountWithContext());
  after(() => mount.cleanUp());

  it('should render nothing directly', () => {
    const wrapper = mount(<Portal>
Hello
</Portal>);
    assert.strictEqual(wrapper.children().length, 0, 'should have no children');
  });

  it('should not open by default', () => {
    const wrapper = mount(<Portal>
Hello
</Portal>);
    const instance = wrapper.instance();
    assert.strictEqual(wrapper.prop('open'), false, 'should be false by default');
    assert.strictEqual(instance.layer, undefined, 'should not have a layer');
  });

  describe('rendering and unrendering', () => {
    let wrapper;
    let instance;
    let portal;

    before(() => {
      wrapper = mount(<Portal open={true}>
Hello
</Portal>);
      instance = wrapper.instance();
      portal = instance.layer;
    });

    it('should render the contents through a portal layer div', () => {
      assert.strictEqual(portal.tagName.toLowerCase(), 'div', 'should render a div element as the portal');
      assert.strictEqual(portal.firstChild.tagName.toLowerCase(), 'h1', 'should be a heading tag');
      assert.strictEqual(portal.firstChild.getAttribute('id'), 'woof', 'should have the woof id');
      assert.strictEqual(portal.firstChild.innerHTML, 'Hello', 'have the contents');
      portal.setAttribute('id', 'meow');
      assert.strictEqual(document.getElementById('meow'), portal, 'should have the portal in the DOM');
      assert.strictEqual(document.getElementById('woof'), portal.firstChild, 'should have the heading in the DOM');
    });

    it('should unrender the contents and remove the layer', () => {
      wrapper.setProps({open: false});
      assert.strictEqual(document.getElementById('meow'), null, 'should not have the portal in the DOM');
      assert.strictEqual(document.getElementById('woof'), null, 'should not have the heading in the DOM');
    });
  });
});
<commit_msg>Fix lint errrors<commit_after>/* eslint-env mocha */
import React from 'react';
import {assert} from 'chai';
import Portal from './Portal';
import {createMountWithContext} from 'test/utils';

describe('<Portal>', () => {
  let mount;

  before(() => mount = createMountWithContext());
  after(() => mount.cleanUp());

  it('should render nothing directly', () => {
    const wrapper = mount(<Portal>
Hello
</Portal>);
    assert.strictEqual(wrapper.children().length, 0, 'should have no children');
  });

  it('should not open by default', () => {
    const wrapper = mount(<Portal>
Hello
</Portal>);
    const instance = wrapper.instance();
    assert.strictEqual(wrapper.prop('open'), false, 'should be false by default');
    assert.strictEqual(instance.layer, undefined, 'should not have a layer');
  });

  describe('rendering and unrendering', () => {
    let wrapper;
    let instance;
    let portal;

    before(() => {
      wrapper = mount(<Portal open={true}>
Hello
</Portal>);
      instance = wrapper.instance();
      portal = instance.layer;
    });

    it('should render the contents through a portal layer div', () => {
      assert.strictEqual(portal.tagName.toLowerCase(), 'div', 'should render a div element as the portal');
      assert.strictEqual(portal.firstChild.tagName.toLowerCase(), 'h1', 'should be a heading tag');
      assert.strictEqual(portal.firstChild.getAttribute('id'), 'woof', 'should have the woof id');
      assert.strictEqual(portal.firstChild.innerHTML, 'Hello', 'have the contents');
      portal.setAttribute('id', 'meow');
      assert.strictEqual(document.getElementById('meow'), portal, 'should have the portal in the DOM');
      assert.strictEqual(document.getElementById('woof'), portal.firstChild, 'should have the heading in the DOM');
    });

    it('should unrender the contents and remove the layer', () => {
      wrapper.setProps({open: false});
      assert.strictEqual(document.getElementById('meow'), null, 'should not have the portal in the DOM');
      assert.strictEqual(document.getElementById('woof'), null, 'should not have the heading in the DOM');
    });
  });
});
<|endoftext|>