Skip to content

Commit

Permalink
[_refactored] Scheduler tests to follow Starmap organization
Browse files Browse the repository at this point in the history
Summary:
We'd like the unit tests to follow the organization of the [Starmap](https://material-motion.gitbooks.io/material-motion-starmap/content/specifications/runtime/scheduler.html), to make it easy to cross-link between them.  To that end, I've refactored these tests by:

- Renaming `Scheduler.test` to `Scheduler-addPlan.test`
- Collapsing all tests to top level `describe` call, combining `beforeEach` calls as needed

Reviewers: featherless, O2 Material Motion

Reviewed By: featherless, O2 Material Motion

Subscribers: featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D1715
  • Loading branch information
appsforartists committed Oct 13, 2016
1 parent 857e05b commit 311644a
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 139 deletions.
124 changes: 124 additions & 0 deletions packages/runtime/src/__tests__/Scheduler-addPlan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/** @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.addPlan',
() => {
let scheduler;
let addPlanSpy;
let PerformerSpy;
let planWithSpies;
let target = {};

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

addPlanSpy = stub();

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

planWithSpies = {
_performerType: PerformerSpy,
}
}
);

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

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

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

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;
}
);
}
);
139 changes: 0 additions & 139 deletions packages/runtime/src/__tests__/Scheduler.test.ts

This file was deleted.

0 comments on commit 311644a

Please sign in to comment.