1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
const ArticleModel = imports.models.article_model;
let mockJsonData = {
title: 'Article Title',
url: 'file:///',
categories: [
'Category One',
'Category Two'
]
};
function _assertCategoryListHasIds(categoryList, idList) {
assertEquals(idList.length, categoryList.length);
idList.forEach(function (id) {
assertTrue(categoryList.some(function (actualId) {
return actualId == id;
}));
});
}
function testNewModelFromJson() {
let model = ArticleModel.newFromJson(mockJsonData);
assertTrue(model instanceof ArticleModel.ArticleModel);
assertEquals('Article Title', model.title);
assertEquals('file:///', model.uri);
_assertCategoryListHasIds(model.getCategories(),
['Category One', 'Category Two']);
}
function testNewWithProperties() {
let model = new ArticleModel.ArticleModel({
title: 'Article Title',
uri: 'file:///'
});
assertEquals('Article Title', model.title);
assertEquals('file:///', model.uri);
assertEquals(0, model.getCategories().length);
}
function testSetAndGetCategories() {
let model = new ArticleModel.ArticleModel();
let expectedCategories = ['One', 'Two', 'Three'];
model.setCategories(expectedCategories);
_assertCategoryListHasIds(model.getCategories(), expectedCategories);
}
function testSetCategoriesWipesPreviousCategories() {
let model = new ArticleModel.ArticleModel();
let firstCategories = ['One', 'Two', 'Three'];
model.setCategories(firstCategories);
let expectedCategories = ['A', 'B', 'C', 'D'];
model.setCategories(expectedCategories);
_assertCategoryListHasIds(model.getCategories(), expectedCategories);
}
function testAddAndGetCategories() {
let model = new ArticleModel.ArticleModel();
model.addCategory('One');
model.addCategory('Two');
model.addCategory('Three');
_assertCategoryListHasIds(model.getCategories(), ['One', 'Two', 'Three']);
}
function testHasCategories() {
let model = new ArticleModel.ArticleModel();
let expectedCategories = ['One', 'Two', 'Three'];
model.setCategories(expectedCategories);
expectedCategories.forEach(function (id) {
assertTrue(model.hasCategory(id));
});
}
|