mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Use select instead of an input for cds
This commit is contained in:
@@ -31,68 +31,45 @@ describe('Settings Controller', function() {
|
||||
sandbox.stub(window, 'alert');
|
||||
});
|
||||
|
||||
context('failures', function() {
|
||||
var tests = {
|
||||
'blank': '',
|
||||
'not a whole number': 5.3,
|
||||
'not a number': 'foo',
|
||||
'less than 0': -5,
|
||||
'more than 24': 25
|
||||
};
|
||||
it('opens the day start modal', function() {
|
||||
scope.openDayStartModal(5);
|
||||
|
||||
for (var test in tests) {
|
||||
it('returns with an alert if number is ' + test, function() {
|
||||
scope.openDayStartModal(tests[test]);
|
||||
|
||||
expect(rootScope.openModal).to.not.be.called;
|
||||
expect(window.alert).to.be.calledOnce;
|
||||
expect(window.alert).to.be.calledWith(env.t('enterNumber'));
|
||||
});
|
||||
}
|
||||
expect(rootScope.openModal).to.be.calledOnce;
|
||||
expect(rootScope.openModal).to.be.calledWith('change-day-start', {scope: scope});
|
||||
});
|
||||
|
||||
context('success', function() {
|
||||
it('opens the day start modal', function() {
|
||||
scope.openDayStartModal(5);
|
||||
it('sets nextCron variable', function() {
|
||||
expect(scope.nextCron).to.not.exist;
|
||||
|
||||
expect(rootScope.openModal).to.be.calledOnce;
|
||||
expect(rootScope.openModal).to.be.calledWith('change-day-start', {scope: scope});
|
||||
});
|
||||
scope.openDayStartModal(5);
|
||||
|
||||
it('sets nextCron variable', function() {
|
||||
expect(scope.nextCron).to.not.exist;
|
||||
expect(scope.nextCron).to.exist;
|
||||
});
|
||||
|
||||
scope.openDayStartModal(5);
|
||||
it('calculates the next time cron will run', function() {
|
||||
var fakeCurrentTime = new Date(2013, 3, 1, 3, 12).getTime();
|
||||
var expectedTime = new Date(2013, 3, 1, 5, 0, 0).getTime();
|
||||
sandbox.useFakeTimers(fakeCurrentTime);
|
||||
|
||||
expect(scope.nextCron).to.exist;
|
||||
});
|
||||
scope.openDayStartModal(5);
|
||||
|
||||
it('calculates the next time cron will run', function() {
|
||||
var fakeCurrentTime = new Date(2013, 3, 1, 3, 12).getTime();
|
||||
var expectedTime = new Date(2013, 3, 1, 5, 0, 0).getTime();
|
||||
sandbox.useFakeTimers(fakeCurrentTime);
|
||||
expect(scope.nextCron).to.eq(expectedTime);
|
||||
});
|
||||
|
||||
scope.openDayStartModal(5);
|
||||
it('calculates the next time cron will run and adds a day if cron would have already passed', function() {
|
||||
var fakeCurrentTime = new Date(2013, 3, 1, 8, 12).getTime();
|
||||
var expectedTime = new Date(2013, 3, 2, 5, 0, 0).getTime();
|
||||
sandbox.useFakeTimers(fakeCurrentTime);
|
||||
|
||||
expect(scope.nextCron).to.eq(expectedTime);
|
||||
});
|
||||
scope.openDayStartModal(5);
|
||||
|
||||
it('calculates the next time cron will run and adds a day if cron would have already passed', function() {
|
||||
var fakeCurrentTime = new Date(2013, 3, 1, 8, 12).getTime();
|
||||
var expectedTime = new Date(2013, 3, 2, 5, 0, 0).getTime();
|
||||
sandbox.useFakeTimers(fakeCurrentTime);
|
||||
|
||||
scope.openDayStartModal(5);
|
||||
|
||||
expect(scope.nextCron).to.eq(expectedTime);
|
||||
});
|
||||
expect(scope.nextCron).to.eq(expectedTime);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#saveDayStart', function() {
|
||||
|
||||
it('updates user\'s custom day start and last cron', function() {
|
||||
|
||||
var fakeCurrentTime = new Date(2013, 3, 1, 8, 12).getTime();
|
||||
var expectedTime = fakeCurrentTime;
|
||||
sandbox.useFakeTimers(fakeCurrentTime);
|
||||
|
||||
@@ -66,12 +66,6 @@ habitrpg.controller('SettingsCtrl',
|
||||
|
||||
$scope.openDayStartModal = function(dayStart) {
|
||||
$scope.dayStart = +dayStart;
|
||||
var flooredDayStart = Math.floor($scope.dayStart);
|
||||
|
||||
if ($scope.dayStart !== flooredDayStart || $scope.dayStart < 0 || $scope.dayStart > 24 ) {
|
||||
return alert(window.env.t('enterNumber'));
|
||||
}
|
||||
|
||||
$scope.nextCron = _calculateNextCron();
|
||||
|
||||
$rootScope.openModal('change-day-start', { scope: $scope });
|
||||
|
||||
@@ -97,9 +97,10 @@ script(type='text/ng-template', id='partials/options.settings.settings.html')
|
||||
select.form-control(ng-model='dayStart')
|
||||
- var number = 0
|
||||
while number < 24
|
||||
- var hour = number++ % 12
|
||||
- var value = number
|
||||
- var meridian = number < 12 ? 'AM' : 'PM'
|
||||
option(value=number) #{hour ? hour : 12}:00 #{meridian}
|
||||
- var hour = number++ % 12
|
||||
option(value=value) #{hour ? hour : 12}:00 #{meridian}
|
||||
|
||||
.col-sm-5
|
||||
br.visible-xs
|
||||
|
||||
Reference in New Issue
Block a user