Skip to content

Commit

Permalink
[added] Scheduler unit tests
Browse files Browse the repository at this point in the history
Summary: Closes #74

Reviewers: markwei, shyndman, featherless, O2 Material Motion

Reviewed By: shyndman, featherless, O2 Material Motion

Tags: #material_motion

Differential Revision: http://codereview.cc/D1711
  • Loading branch information
appsforartists committed Oct 12, 2016
1 parent 3e6ec5d commit 857e05b
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 36 deletions.
9 changes: 5 additions & 4 deletions packages/runtime/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ module.exports = function(config) {
'**/*.js': ['webpack'],
},
webpack: {
devtool: 'eval',
resolve: {
extensions: ['.js', '.ts'],
},
module: {
loaders: [
{
test: /\.tsx?$/, loader: 'ts-loader',
test: /\.tsx?$/, loader: 'ts-loader?transpileOnly=true',
},
],
},
},
ts: {
noResolve: true,
},
mime: {
'text/x-typescript': ['ts', 'tsx'],
},
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"lerna": "2.0.0-beta.30",
"mocha": "3.1.1",
"mocha-sugar-free": "1.3.1",
"sinon": "2.0.0-pre.3",
"sinon-chai": "2.8.0",
"ts-loader": "0.9.0",
"tsickle": "0.2.0",
"typescript": "2.0.3",
Expand Down
32 changes: 0 additions & 32 deletions packages/runtime/src/__tests__/Scheduler.test.js

This file was deleted.

139 changes: 139 additions & 0 deletions packages/runtime/src/__tests__/Scheduler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/** @license
* Copyright 2016 The Material Motion Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

import { expect } from 'chai';

import {
beforeEach,
describe,
it,
} from 'mocha-sugar-free';

import {
stub,
} from 'sinon';

import Scheduler from '../Scheduler';

// chai really doesn't like being imported as an ES2015 module; will be fixed in v4
require('chai').use(
require('sinon-chai')
);

describe('Scheduler',
() => {
let scheduler;
let plan;
let target = {};

beforeEach(
() => {
scheduler = new Scheduler();
plan = {};
}
);

describe(`addPlan`,
() => {
it(`should require arguments`,
() => {
expect(
() => {
scheduler.addPlan();
}
).to.throw(`Scheduler.addPlan requires`);
}
);

it(`should require a target`,
() => {
expect(
() => {
scheduler.addPlan({ plan });
}
).to.throw(`requires a target`);
}
);

it(`should require a plan`,
() => {
expect(
() => {
scheduler.addPlan({ target });
}
).to.throw(`requires a plan`);
}
);

describe('performers',
() => {
let addPlanSpy;
let PerformerSpy;
let planWithSpies;

beforeEach(
() => {
addPlanSpy = stub();

PerformerSpy = stub().returns(
{
addPlan: addPlanSpy,
}
);

planWithSpies = {
_performerType: PerformerSpy,
}
}
);

it(`should create a performer from plan._performerType`,
() => {
scheduler.addPlan({ plan: planWithSpies, target });

expect(planWithSpies._performerType).to.be.calledWithNew;
}
);

it(`should recycle performers for the same plan and target`,
() => {
scheduler.addPlan({ plan: planWithSpies, target });
scheduler.addPlan({ plan: planWithSpies, target });
expect(PerformerSpy).to.have.been.calledOnce;
}
);

it(`should create new performers for each target`,
() => {
scheduler.addPlan({ plan: planWithSpies, target });
scheduler.addPlan({ plan: planWithSpies, target: {} });
expect(PerformerSpy).to.have.been.calledTwice;
}
);

it(`should call performer.addPlan for each plan`,
() => {
scheduler.addPlan({ plan: planWithSpies, target });
scheduler.addPlan({ plan: planWithSpies, target });
expect(addPlanSpy).to.have.been.calledTwice;
}
);
}
);
}
);
}
);

0 comments on commit 857e05b

Please sign in to comment.