Add flash test, avoid using sinon.useFakeTimers in tests.

sinon.useFakeTimers mocks setInterval, setTimeout, etc,
but not requestAnimationFrame, which d3 transitions rely on.
This commit is contained in:
Bryan Housel
2017-02-11 00:19:49 -05:00
parent 5aa519affb
commit c18cc7577d
4 changed files with 23 additions and 26 deletions

View File

@@ -1,5 +1,4 @@
import * as d3 from 'd3';
import { uiModal } from './modal';
var timeout;

View File

@@ -43,14 +43,14 @@ describe('iD.behaviorHash', function () {
location.hash = 'map=20.00/38.87952/-77.02405';
});
it('stores the current zoom and coordinates in location.hash on map move events', function () {
it('stores the current zoom and coordinates in location.hash on map move events', function (done) {
location.hash = '';
hash();
var clock = sinon.useFakeTimers();
context.map().center([-77.0, 38.9]);
context.map().zoom(2.0);
clock.tick(500);
expect(location.hash).to.equal('#map=2.00/38.9/-77.0');
clock.restore();
window.setTimeout(function() {
expect(location.hash).to.equal('#map=2.00/38.9/-77.0');
done();
}, 300);
});
});

View File

@@ -1,25 +1,28 @@
describe('iD.uiFlash', function () {
var clock;
var elem;
beforeEach(function() {
elem = d3.select('body').append('div');
});
afterEach(function() { elem.remove(); });
beforeEach(function () {
clock = sinon.useFakeTimers();
elem = d3.select('body')
.append('div')
.attr('id', 'flash');
});
afterEach(function () {
clock.restore();
elem.remove();
});
it('leaves after 1000 ms', function () {
var flash = iD.uiFlash(elem);
clock.tick(1610);
expect(flash.node().parentNode).to.be.null;
it('creates a flash', function () {
iD.uiFlash();
expect(elem.selectAll('#flash .content').size()).to.eql(1);
});
it.skip('flash goes away', function (done) {
// test doesn't work on PhantomJS
iD.uiFlash();
window.setTimeout(function() {
expect(elem.selectAll('#flash .content').size()).to.eql(0);
done();
}, 1900);
});
});

View File

@@ -1,12 +1,7 @@
describe('iD.utilSessionMutex', function() {
var clock, a, b;
beforeEach(function () {
clock = sinon.useFakeTimers(Date.now());
});
var a, b;
afterEach(function() {
clock.restore();
if (a) a.unlock();
if (b) b.unlock();
});