[Timer] Updated Timer UI and fixed tests
Added peeking stop button to view, added legacy and first run support, added new and fixed old tests
This commit is contained in:
@@ -62,27 +62,34 @@ define(
|
||||
action = new PauseTimerAction(mockNow, testContext);
|
||||
});
|
||||
|
||||
it("updates the model with a timestamp", function () {
|
||||
it("updates the model with a timerState", function () {
|
||||
testModel.timerState = 'started';
|
||||
action.perform();
|
||||
expect(testModel.timerState).toEqual('paused');
|
||||
});
|
||||
|
||||
it("updates the model with a pausedTime", function () {
|
||||
testModel.pausedTime = undefined;
|
||||
mockNow.andReturn(12000);
|
||||
action.perform();
|
||||
expect(testModel.timestamp).toEqual(12000);
|
||||
expect(testModel.pausedTime).toEqual(12000);
|
||||
});
|
||||
|
||||
it("applies only to timers in a playing state", function () {
|
||||
//in a stopped state
|
||||
testStates(testModel, 'timer', undefined, undefined, false);
|
||||
testState('timer', 'stopped', undefined, false);
|
||||
|
||||
//in a paused state
|
||||
testStates(testModel, 'timer', 'pause', undefined, false);
|
||||
testState('timer', 'paused', 12000, false);
|
||||
|
||||
//in a playing state
|
||||
testStates(testModel, 'timer', 'play', undefined, true);
|
||||
testState('timer', 'started', 12000, true);
|
||||
|
||||
//not a timer
|
||||
testStates(testModel, 'clock', 'pause', undefined, false);
|
||||
testState('clock', 'started', 12000, false);
|
||||
});
|
||||
|
||||
function testStates(testModel, type, timerState, timestamp, expected) {
|
||||
function testState(type, timerState, timestamp, expected) {
|
||||
testModel.type = type;
|
||||
testModel.timerState = timerState;
|
||||
testModel.timestamp = timestamp;
|
||||
@@ -92,11 +99,6 @@ define(
|
||||
} else {
|
||||
expect(PauseTimerAction.appliesTo(testContext)).toBeFalsy()
|
||||
}
|
||||
|
||||
//first test without time, this test with time
|
||||
if (timestamp === undefined) {
|
||||
testStates(testModel, type, timerState, 12000, expected);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,26 +63,39 @@ define(
|
||||
});
|
||||
|
||||
it("updates the model with a timestamp", function () {
|
||||
testModel.pausedTime = 12000;
|
||||
mockNow.andReturn(12000);
|
||||
action.perform();
|
||||
expect(testModel.timestamp).toEqual(12000);
|
||||
});
|
||||
|
||||
it("applies only to timers in a non-stopped state", function () {
|
||||
//in a stopped state
|
||||
testStates(testModel, 'timer', undefined, undefined, false);
|
||||
|
||||
//in a paused state
|
||||
testStates(testModel, 'timer', 'pause', undefined, true);
|
||||
|
||||
//in a playing state
|
||||
testStates(testModel, 'timer', 'play', undefined, true);
|
||||
|
||||
//not a timer
|
||||
testStates(testModel, 'clock', 'pause', undefined, false);
|
||||
it("updates the model with a pausedTime", function () {
|
||||
testModel.pausedTime = 12000;
|
||||
action.perform();
|
||||
expect(testModel.pausedTime).toEqual(undefined);
|
||||
});
|
||||
|
||||
function testStates(testModel, type, timerState, timestamp, expected) {
|
||||
it("updates the model with a timerState", function () {
|
||||
testModel.timerState = 'stopped';
|
||||
action.perform();
|
||||
expect(testModel.timerState).toEqual('started');
|
||||
});
|
||||
|
||||
it("applies only to timers in a non-stopped state", function () {
|
||||
//in a stopped state
|
||||
testState('timer', 'stopped', undefined, false);
|
||||
|
||||
//in a paused state
|
||||
testState('timer', 'paused', 12000, true);
|
||||
|
||||
//in a playing state
|
||||
testState('timer', 'started', 12000, true);
|
||||
|
||||
//not a timer
|
||||
testState('clock', 'paused', 12000, false);
|
||||
});
|
||||
|
||||
function testState(type, timerState, timestamp, expected) {
|
||||
testModel.type = type;
|
||||
testModel.timerState = timerState;
|
||||
testModel.timestamp = timestamp;
|
||||
@@ -92,11 +105,6 @@ define(
|
||||
} else {
|
||||
expect(RestartTimerAction.appliesTo(testContext)).toBeFalsy()
|
||||
}
|
||||
|
||||
//first test without time, this test with time
|
||||
if (timestamp === undefined) {
|
||||
testStates(testModel, type, timerState, 12000, expected);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,21 +68,33 @@ define(
|
||||
expect(testModel.timestamp).toEqual(12000);
|
||||
});
|
||||
|
||||
it("applies only to timers not in a playing state", function () {
|
||||
//in a stopped state
|
||||
testStates(testModel, 'timer', undefined, undefined, true);
|
||||
|
||||
//in a paused state
|
||||
testStates(testModel, 'timer', 'pause', undefined, true);
|
||||
|
||||
//in a playing state
|
||||
testStates(testModel, 'timer', 'play', undefined, false);
|
||||
|
||||
//not a timer
|
||||
testStates(testModel, 'clock', 'pause', undefined, false);
|
||||
it("updates the model with a pausedTime", function () {
|
||||
testModel.pausedTime = 12000;
|
||||
action.perform();
|
||||
expect(testModel.pausedTime).toEqual(undefined);
|
||||
});
|
||||
|
||||
function testStates(testModel, type, timerState, timestamp, expected) {
|
||||
it("updates the model with a timerState", function () {
|
||||
testModel.timerState = undefined;
|
||||
action.perform();
|
||||
expect(testModel.timerState).toEqual('started');
|
||||
});
|
||||
|
||||
it("applies only to timers not in a playing state", function () {
|
||||
//in a stopped state
|
||||
testState('timer', 'stopped', undefined, true);
|
||||
|
||||
//in a paused state
|
||||
testState('timer', 'paused', 12000, true);
|
||||
|
||||
//in a playing state
|
||||
testState('timer', 'started', 12000, false);
|
||||
|
||||
//not a timer
|
||||
testState('clock', 'paused', 12000, false);
|
||||
});
|
||||
|
||||
function testState(type, timerState, timestamp, expected) {
|
||||
testModel.type = type;
|
||||
testModel.timerState = timerState;
|
||||
testModel.timestamp = timestamp;
|
||||
@@ -92,11 +104,6 @@ define(
|
||||
} else {
|
||||
expect(StartTimerAction.appliesTo(testContext)).toBeFalsy()
|
||||
}
|
||||
|
||||
//first test without time, this test with time
|
||||
if (timestamp === undefined) {
|
||||
testStates(testModel, type, timerState, 12000, expected);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -65,24 +65,36 @@ define(
|
||||
it("updates the model with a timestamp", function () {
|
||||
mockNow.andReturn(12000);
|
||||
action.perform();
|
||||
expect(testModel.timestamp).toEqual(12000);
|
||||
expect(testModel.timestamp).toEqual(undefined);
|
||||
});
|
||||
|
||||
it("updates the model with a pausedTime", function () {
|
||||
testModel.pausedTime = 12000;
|
||||
action.perform();
|
||||
expect(testModel.pausedTime).toEqual(undefined);
|
||||
});
|
||||
|
||||
it("updates the model with a timerState", function () {
|
||||
testModel.timerState = 'started';
|
||||
action.perform();
|
||||
expect(testModel.timerState).toEqual('stopped');
|
||||
});
|
||||
|
||||
it("applies only to timers in a non-stopped state", function () {
|
||||
//in a stopped state
|
||||
testStates(testModel, 'timer', undefined, undefined, false);
|
||||
testState('timer', 'stopped', undefined, false);
|
||||
|
||||
//in a paused state
|
||||
testStates(testModel, 'timer', 'pause', undefined, true);
|
||||
testState('timer', 'paused', 12000, true);
|
||||
|
||||
//in a playing state
|
||||
testStates(testModel, 'timer', 'play', undefined, true);
|
||||
testState('timer', 'started', 12000, true);
|
||||
|
||||
//not a timer
|
||||
testStates(testModel, 'clock', 'pause', undefined, false);
|
||||
testState('clock', 'paused', 12000, false);
|
||||
});
|
||||
|
||||
function testStates(testModel, type, timerState, timestamp, expected) {
|
||||
function testState(type, timerState, timestamp, expected) {
|
||||
testModel.type = type;
|
||||
testModel.timerState = timerState;
|
||||
testModel.timestamp = timestamp;
|
||||
@@ -92,11 +104,6 @@ define(
|
||||
} else {
|
||||
expect(StopTimerAction.appliesTo(testContext)).toBeFalsy()
|
||||
}
|
||||
|
||||
//first test without time, this test with time
|
||||
if (timestamp === undefined) {
|
||||
testStates(testModel, type, timerState, 12000, expected);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ define(
|
||||
mockActionCapability,
|
||||
mockStart,
|
||||
mockPause,
|
||||
mockStop,
|
||||
testModel,
|
||||
controller;
|
||||
|
||||
@@ -68,7 +69,11 @@ define(
|
||||
['getMetadata', 'perform']
|
||||
);
|
||||
mockPause = jasmine.createSpyObj(
|
||||
'pause',
|
||||
'paused',
|
||||
['getMetadata', 'perform']
|
||||
);
|
||||
mockStop = jasmine.createSpyObj(
|
||||
'stopped',
|
||||
['getMetadata', 'perform']
|
||||
);
|
||||
mockNow = jasmine.createSpy('now');
|
||||
@@ -82,11 +87,13 @@ define(
|
||||
mockActionCapability.getActions.andCallFake(function (k) {
|
||||
return [{
|
||||
'timer.start': mockStart,
|
||||
'timer.pause': mockPause
|
||||
'timer.pause': mockPause,
|
||||
'timer.stop': mockStop
|
||||
}[k]];
|
||||
});
|
||||
mockStart.getMetadata.andReturn({cssclass: "icon-play", name: "Start"});
|
||||
mockPause.getMetadata.andReturn({cssclass: "icon-pause", name: "Pause"});
|
||||
mockStop.getMetadata.andReturn({cssclass: "icon-box", name: "Stop"});
|
||||
mockScope.domainObject = mockDomainObject;
|
||||
|
||||
testModel = {};
|
||||
@@ -120,6 +127,7 @@ define(
|
||||
mockWindow.requestAnimationFrame.mostRecentCall.args[0]();
|
||||
expect(controller.sign()).toEqual("");
|
||||
expect(controller.text()).toEqual("");
|
||||
expect(controller.stopButtonText()).toEqual("");
|
||||
});
|
||||
|
||||
it("formats time to display relative to target", function () {
|
||||
@@ -150,22 +158,43 @@ define(
|
||||
expect(controller.buttonText()).toEqual("Start");
|
||||
|
||||
testModel.timestamp = 12321;
|
||||
testModel.timerState = 'started';
|
||||
invokeWatch('model.modified', 1);
|
||||
expect(controller.buttonCssClass()).toEqual("icon-pause");
|
||||
expect(controller.buttonText()).toEqual("Pause");
|
||||
});
|
||||
|
||||
it("performs correct start/pause action on click", function () {
|
||||
it("shows cssclass & name for the stop action", function () {
|
||||
invokeWatch('domainObject', mockDomainObject);
|
||||
expect(controller.stopButtonCssClass()).toEqual("");
|
||||
expect(controller.stopButtonText()).toEqual("");
|
||||
|
||||
testModel.timestamp = 12321;
|
||||
testModel.timerState = 'started';
|
||||
invokeWatch('model.modified', 1);
|
||||
expect(controller.stopButtonCssClass()).toEqual("icon-box");
|
||||
expect(controller.stopButtonText()).toEqual("Stop");
|
||||
});
|
||||
|
||||
it("performs correct start/pause/stop action on click", function () {
|
||||
//test start
|
||||
invokeWatch('domainObject', mockDomainObject);
|
||||
expect(mockStart.perform).not.toHaveBeenCalled();
|
||||
controller.clickButton();
|
||||
expect(mockStart.perform).toHaveBeenCalled();
|
||||
|
||||
//test pause
|
||||
testModel.timestamp = 12321;
|
||||
testModel.timerState = 'started';
|
||||
invokeWatch('model.modified', 1);
|
||||
expect(mockPause.perform).not.toHaveBeenCalled();
|
||||
controller.clickButton();
|
||||
expect(mockPause.perform).toHaveBeenCalled();
|
||||
|
||||
//test stop
|
||||
expect(mockStop.perform).not.toHaveBeenCalled();
|
||||
controller.clickStopButton();
|
||||
expect(mockStop.perform).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("stops requesting animation frames when destroyed", function () {
|
||||
|
||||
Reference in New Issue
Block a user