Skip to content

Commit

Permalink
Added test case for Progress <(‵▽′)>
Browse files Browse the repository at this point in the history
  • Loading branch information
ye11ow committed Sep 7, 2015
1 parent e214b84 commit 6b08d8e
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 11 deletions.
23 changes: 13 additions & 10 deletions js/stores/ProgressStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,49 +92,52 @@ function updateProgress(id, current) {
var ProgressStore = Object.assign({}, EventEmitter.prototype, {

init(ids) {
create(
var pIds = [];
pIds.push(create(
i18n.getMessage("sampleAnime1Title"),
3,
12,
ids[0],
null,
i18n.getMessage("sampleAnime1Desc")
);
create(
));
pIds.push(create(
i18n.getMessage("sampleAnime2Title"),
25,
25,
ids[0],
null,
i18n.getMessage("sampleAnime2Desc")
);
create(
));
pIds.push(create(
i18n.getMessage("sampleBook1Title"),
350,
600,
ids[1],
null,
i18n.getMessage("sampleBook1Desc")
);
create(
));
pIds.push(create(
i18n.getMessage("sampleBook2Title"),
300,
500,
ids[1],
null,
i18n.getMessage("sampleBook2Desc")
);
create(
));
pIds.push(create(
i18n.getMessage("sampleOther1Title"),
1,
10,
ids[2],
null,
i18n.getMessage("sampleOther1Desc")
);
));

ProgressStore.persist();
ProgressStore.emitChange();

return pIds;
},

loadProgresses(progresses) {
Expand Down
1 change: 0 additions & 1 deletion test/CategoryStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,4 @@ describe('CategoryStore', function() {
});
});


})
127 changes: 127 additions & 0 deletions test/ProgressStoreTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
var assert = require("assert");
var sinon = require("sinon");

/**
* Test cases for ProgressStore and ProgressActions
*/
describe('ProgressStore', function() {

var ProgressStore = require("../js/stores/ProgressStore"),
ProgressActions = require("../js/actions/ProgressActions"),
ProgressConstants = require('../js/constants/ProgressConstants');

before(function () {
});

const CATEGORY_IDS = [1, 2, 3];

describe('#init()', function() {
var persist = sinon.stub(ProgressStore, "persist");
var clear = sinon.stub(ProgressStore, "clear");

it('should return some ids', function(){
var ids = ProgressStore.init(CATEGORY_IDS);

sinon.assert.called(persist)

assert.equal(ids.length, 5);
});
});

describe('#getAll()', function() {
it('should return all the progresses', function() {
var progresses = ProgressStore.getAll();

assert.equal(Object.keys(progresses).length, 5);
});
});

describe('#loadProgresses()', function() {
it('should load some progresses', function() {
var progressesBak = ProgressStore.getAll();

ProgressStore.loadProgresses([]);
var progresses = ProgressStore.getAll();

assert.equal(Object.keys(progresses).length, 0);

ProgressStore.loadProgresses(progressesBak);
progresses = ProgressStore.getAll();

assert.equal(Object.keys(progresses).length, 5);
});
});

describe('#getEditing() & #Action::setEditing', function() {
it('should set/get current editing progress', function() {
var editing = ProgressStore.getEditing();

assert.equal(editing, null);

ProgressActions.setEditing("1");

assert.equal(ProgressStore.getEditing(), "1");
});
});

describe('#getLengthByCategory()', function() {
it('should return the progress count of a specific category', function() {
var progressCount = ProgressStore.getLengthByCategory(CATEGORY_IDS[0]);

assert.equal(progressCount, 2);
});

it('should return zero if the the category is missing', function() {
var progressCount = ProgressStore.getLengthByCategory("WRONG CATEGORY");

assert.equal(progressCount, 0);
});
});

describe('#getCompleted()', function() {
it('should return the count of completed progresses', function() {
var completed = ProgressStore.getCompleted();

assert.equal(completed, 1);
});
});

describe('#Action::create', function() {
it('should create a new progress', function() {
var prevCount = Object.keys(ProgressStore.getAll()).length;
ProgressActions.create("TITLE", 1, 2, CATEGORY_IDS[0], null, "");

assert.equal(Object.keys(ProgressStore.getAll()).length, prevCount + 1);
});

it('should failed when title is empty', function() {
var prevCount = Object.keys(ProgressStore.getAll()).length;
ProgressActions.create("", 1, 2, CATEGORY_IDS[0], null, "");

assert.equal(Object.keys(ProgressStore.getAll()).length, prevCount);
});
});

describe('#Action::destroy', function() {
it('should destroy a progress', function() {
var id = Object.keys(ProgressStore.getAll())[0];
var prevCount = Object.keys(ProgressStore.getAll()).length;

ProgressActions.destroy(id);

assert.equal(Object.keys(ProgressStore.getAll()).length, prevCount - 1);
assert.notEqual(Object.keys(ProgressStore.getAll())[0], id);
});
});

describe('#Action::destroyProgressByCategory', function() {
it('should destroy all progresses belongs to a specific category', function() {
assert.notEqual(ProgressStore.getLengthByCategory(CATEGORY_IDS[1]), 0);

ProgressActions.destroyProgressByCategory(CATEGORY_IDS[1]);

assert.equal(ProgressStore.getLengthByCategory(CATEGORY_IDS[1]), 0);
});
});

})

0 comments on commit 6b08d8e

Please sign in to comment.