Skip to content

Commit

Permalink
add static methods tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0n committed Dec 14, 2015
1 parent b6dce3c commit 5f87aea
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.1",
"devDependencies": {
"autoprefixer": "^6.1.0",
"chai": "^3.4.1",
"gulp": "^3.9.0",
"gulp-clone": "^1.0.0",
"gulp-concat": "^2.6.0",
Expand All @@ -15,6 +16,7 @@
"gulp-sass": "^2.0.4",
"gulp-uglify": "^1.2.0",
"gulp-watch": "^4.3.5",
"jade": "^1.11.0"
"jade": "^1.11.0",
"mocha": "^2.3.4"
}
}
24 changes: 24 additions & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Air Datepicker tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"/>
<script type="text/javascript" src="../bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="../dist/js/datepicker.min.js"></script>

<script type="text/javascript" src="../node_modules/mocha/mocha.js"></script>
<script type="text/javascript" src="../node_modules/chai/chai.js"></script>
<script type="text/javascript">
mocha.setup('bdd');
</script>

<script type="text/javascript" src="specs/static-methods.js"></script>
</head>
<body>
<div id="mocha"></div>
<script type="text/javascript">
mocha.run();
</script>
</body>
</html>
110 changes: 110 additions & 0 deletions tests/specs/static-methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
var assert = chai.assert,
expect = chai.expect;

describe('Datepicker', function () {
describe('getDaysCount', function () {
it('should return 31 days in December', function () {
assert.equal(Datepicker.getDaysCount(new Date(2015, 11)), 31)
});
it('should return 30 days in September', function () {
assert.equal(Datepicker.getDaysCount(new Date(2015, 8)), 30)
});
it('should return 28 days in February', function () {
assert.equal(Datepicker.getDaysCount(new Date(2015, 1)), 28)
})
});

describe('getParsedDate', function () {
var currentDate = new Date(),
date = Datepicker.getParsedDate(currentDate);

it('should return object with detailed date fields', function () {
expect(date).to.have.all.keys(['year','month','fullMonth','date', 'fullDate', 'day']);
});

describe('.year', function () {
it('`year` must be equal to current year', function () {
assert.equal(currentDate.getFullYear(), date.year);
})
});
describe('.month', function () {
it('`month` must be equal to current month', function () {
assert.equal(currentDate.getMonth(), date.month);
})
});
describe('.fullMonth', function () {
it('`fullMonth` must be equal to current month + 1 with leading zero', function () {
assert.equal(currentDate.getMonth() < 10 ? '0' + (currentDate.getMonth()) + 1 : currentDate.getMonth() + 1 , date.fullMonth);
})
});
describe('.date', function () {
it('`date` must be equal to current date', function () {
assert.equal(currentDate.getDate() , date.date);
})
});
describe('.fullDate', function () {
it('`fullDate` must be equal to current date with leading zero', function () {
assert.equal(currentDate.getDate() < 10 ? '0' + currentDate.getDate() : currentDate.getDate() , date.fullDate);
})
});
describe('.day', function () {
it('`day` must be equal to current day', function () {
assert.equal(currentDate.getDay(), date.day);
})
})
})

describe('getDecade', function () {
it('should return array with first and last years in decade', function () {
var decade = Datepicker.getDecade(new Date(2015, 1));

expect(decade).to.be.an('array');
assert.equal(decade[0], 2010)
assert.equal(decade[1], 2019)
})
})

describe('template', function () {
it('should return string with replaced #{} signs', function () {
var template = 'Hello #{who}';
assert.equal(Datepicker.template(template, {who:'World!'}), 'Hello World!')
})
})

describe('isSame', function () {
var date1 = new Date(2015, 11, 14),
date2 = new Date(2015, 11, 14),
date3 = new Date(2015, 10, 14),
date4 = new Date(2016, 11, 14);

it('should return true if dates are equal', function () {
assert(Datepicker.isSame(date1,date2))
})
it('should return false when checking dates with different months', function () {
assert.isFalse(Datepicker.isSame(date1,date3))
})
it('should return false when checking dates with different years', function () {
assert.isFalse(Datepicker.isSame(date1,date4))
})
it('should return true when comparing months', function () {
assert(Datepicker.isSame(date1, date2,'month'))
})
it('should return false when comparing months from different years', function () {
assert.isFalse(Datepicker.isSame(date1, date4, 'month'))
})
it('should return true when comparing years', function () {
assert(Datepicker.isSame(date1, date2, 'year'))
})
})

describe('less(date2, date1)', function () {
it('should return true if date2 less then date1', function () {
assert(Datepicker.less(new Date(2015, 11, 14), new Date(2015, 11, 13)))
})
})
describe('bigger(date2, date1)', function () {
it('should return true if date2 bigger then date1', function () {
assert(Datepicker.bigger(new Date(2015, 11, 14), new Date(2015, 11, 15)))
})
})
});

0 comments on commit 5f87aea

Please sign in to comment.