diff options
Diffstat (limited to 'test/wikipedia')
-rw-r--r-- | test/wikipedia/models/testArticleModel.js | 110 | ||||
-rw-r--r-- | test/wikipedia/models/testCategoryModel.js | 180 | ||||
-rw-r--r-- | test/wikipedia/models/testDomainWikiModel.js | 208 |
3 files changed, 0 insertions, 498 deletions
diff --git a/test/wikipedia/models/testArticleModel.js b/test/wikipedia/models/testArticleModel.js deleted file mode 100644 index f916369..0000000 --- a/test/wikipedia/models/testArticleModel.js +++ /dev/null @@ -1,110 +0,0 @@ -const ArticleModel = imports.wikipedia.models.article_model; - -describe("Wikipedia article model", function() { - let mockJsonData = { - title: 'Article Title', - url: 'file:///', - source: 'Mock data', - categories: [ - 'Category One', - 'Category Two' - ] - }; - - describe("from JSON", function() { - let model; - - beforeEach(function() { - model = ArticleModel.newFromJson(mockJsonData); - }); - - it("has an article title", function() { - expect(model.title).toEqual(mockJsonData.title); - }); - - it("has a uri", function() { - expect(model.uri).toEqual(mockJsonData.url); - }); - - it("has a list of categories", function() { - expect(model.getCategories()).toEqual(mockJsonData.categories); - }); - }); - - describe("from properties", function() { - let model; - beforeEach(function() { - model = new ArticleModel.ArticleModel({ - title: 'Article Title', - uri: 'file://' - }); - }); - - it("is an instance of an ArticleModel", function() { - expect(model instanceof ArticleModel.ArticleModel).toBeTruthy(); - }); - - it("has a title", function() { - expect(model.title).toEqual('Article Title'); - }); - - it("has a URI", function() { - expect(model.uri).toEqual('file://'); - }); - - it("has no categories", function() { - expect(model.getCategories().length).toEqual(0); - }); - }); - - describe("setCategories method", function() { - let model; - - beforeEach(function() { - model = new ArticleModel.ArticleModel(); - }); - - it("adds categories", function() { - let expectedCategories = ['One', 'Two', 'Three']; - model.setCategories(expectedCategories); - expect(model.getCategories()).toEqual(expectedCategories); - }); - - it("replaces existing categories", function() { - model.setCategories(['One', 'Two']); - let expectedCategories = ['One', 'Two', 'Three']; - model.setCategories(expectedCategories); - expect(model.getCategories()).toEqual(expectedCategories); - }); - }); - - it("appends new categories on addCategory", function() { - let model = new ArticleModel.ArticleModel(); - - model.addCategory('One'); - model.addCategory('Two'); - model.addCategory('Three'); - expect(model.getCategories()).toEqual(['One', 'Two', 'Three']); - }); - describe("hasCategory method", function() { - let model; - let expectedCategories = ['One', 'Two', 'Three']; - - beforeEach(function() { - model = new ArticleModel.ArticleModel; - model.setCategories(expectedCategories); - }); - - expectedCategories.forEach(function(category) { - (function(categoryName) { - it("returns true for category named " + categoryName, function() { - expect(model.hasCategory(categoryName)).toBeTruthy(); - }); - }); - }); - - it("returns false for an unexpected category", function() { - expect(model.hasCategory('unexpected')).toBeFalsy(); - }); - }); -}); diff --git a/test/wikipedia/models/testCategoryModel.js b/test/wikipedia/models/testCategoryModel.js deleted file mode 100644 index 4ffc1a0..0000000 --- a/test/wikipedia/models/testCategoryModel.js +++ /dev/null @@ -1,180 +0,0 @@ -const CategoryModel = imports.wikipedia.models.category_model; - -describe("Category Model", function() { - let mockJsonData = { - category_name: 'Category Name', - content_text: 'Lorem Ipsum', - image_file: 'file:///image.jpg', - image_thumb_uri: 'file:///thumb.jpg', - is_main_category: false, - subcategories: [ 'Category Two' ] - }; - describe("from JSON", function() { - - let model; - beforeEach(function() { - model = CategoryModel.newFromJson(mockJsonData); - }); - - it("is a CategoryModel", function() { - expect(model instanceof CategoryModel.CategoryModel).toBeTruthy(); - }); - - it("has an id", function() { - expect(model.id).toEqual(mockJsonData.category_name); - }); - - it("has no subcategories", function() { - expect(model.getSubcategories().length).toEqual(0); - }); - }); - - describe("from properties", function() { - let model; - - beforeEach(function() { - model = new CategoryModel.CategoryModel({ - id: 'id', - title: 'title', - description: 'description', - image_uri: 'image-uri', - image_thumbnail_uri: 'image-thumbnail-uri', - is_main_category: true, - has_articles: true - }); - }); - - it("has an id", function() { - expect(model.id).toEqual('id'); - }); - - it("has a title", function() { - expect(model.title).toEqual('title'); - }); - - it("has a description", function() { - expect(model.description).toEqual('description'); - }); - - it("has an image uri", function() { - expect(model.image_uri).toEqual('image-uri'); - }); - - it("has an image thumbnail uri", function() { - expect(model.image_thumbnail_uri).toEqual('image-thumbnail-uri'); - }); - - it("is a main category", function() { - expect(model.is_main_category).toBeTruthy(); - }); - - it("has articles", function() { - expect(model.has_articles).toBeTruthy(); - }); - - // FIXME: This seems to be a fairly useless test. Does it actually - // test anything? - it("does not have articles once the flag is unset", function() { - model.has_articles = false; - expect(model.has_articles).toBeFalsy(); - }); - }); - - it("starts with no subcategories", function() { - let model = new CategoryModel.CategoryModel(); - - expect(model.getSubcategories().length).toEqual(0); - }); - - describe("in a tree-like structure", function() { - let parent; - - beforeEach(function() { - jasmine.addMatchers({ - toContainCategoriesWithNames: function() { - return { - compare: function(actual, names) { - let result = { - pass: (function() { - let outer_pass = true; - names.forEach(function (id) { - let categories = actual.getSubcategories(); - if (!categories.some(function(category) { - return category.id == id; - })) { - outer_pass = false; - } - }); - return outer_pass; - })(), - - message: (function() { - let msg = "Expected categories with the following names\n"; - names.forEach(function(name) { - msg += " " + name + "\n"; - }); - msg += "Object actually has the following categories\n"; - actual.getSubcategories().forEach(function(category) { - msg += " " + category.id + "\n"; - }); - return msg; - })() - } - - return result; - } - } - }, - toHaveOnlyTheFollowingCategoriesInOrder: function() { - return { - compare: function(actual, names) { - let result = { - pass: (function() { - let categories = actual.getSubcategories(); - if (categories.length != names.length) - return false; - - for (let i = 0; i < categories.length; i++) { - if (categories[i].id != names[i]) - return false; - } - - return true; - })(), - - message: (function() { - let msg = "Expected exactly the following category names\n"; - names.forEach(function(name) { - msg += " " + name + "\n"; - }); - - msg += "Actually had the following category names\n"; - actual.getSubcategories().forEach(function(category) { - msg += " " + category.id + "\n"; - }); - - return msg; - })() - } - - return result; - } - } - } - }); - - parent = new CategoryModel.CategoryModel({ id: 'Category One' }); - parent.addSubcategory(new CategoryModel.CategoryModel({ id: 'Category Two' })); - parent.addSubcategory(new CategoryModel.CategoryModel({ id: 'Category Three' })); - }); - - it("has subcategories", function() { - expect(parent).toContainCategoriesWithNames(['Category Two', 'Category Three']); - }); - - it("silently does not add duplicates", function() { - parent.addSubcategory(new CategoryModel.CategoryModel({ id: 'Category Two' })); - expect(parent).toHaveOnlyTheFollowingCategoriesInOrder(['Category Two', 'Category Three']); - }); - }); -}); diff --git a/test/wikipedia/models/testDomainWikiModel.js b/test/wikipedia/models/testDomainWikiModel.js deleted file mode 100644 index f30d1bd..0000000 --- a/test/wikipedia/models/testDomainWikiModel.js +++ /dev/null @@ -1,208 +0,0 @@ -const DomainWikiModel = imports.wikipedia.models.domain_wiki_model; - -describe('Domain Wiki Model', function () { - const mockJsonData = { - categories: [ - { - category_name: 'Main Category', - content_text: 'Lorem Ipsum', - image_file: 'file:///image.jpg', - image_thumb_uri: 'file:///image_thumb.jpg', - is_main_category: true, - subcategories: [ - 'Category One', - 'Category Two' - ] - }, - { - category_name: 'Category One', - content_text: 'Lorem Ipsum', - image_file: 'file:///image.jpg', - image_thumb_uri: 'file:///image_thumb.jpg', - is_main_category: false, - subcategories: [] - }, - { - category_name: 'Category Two', - content_text: 'Lorem Ipsum', - image_file: 'file:///image.jpg', - image_thumb_uri: 'file:///image_thumb.jpg', - is_main_category: false, - subcategories: [ - 'Category Three' - ] - }, - { - category_name: 'Category Three', - content_text: 'Lorem Ipsum', - image_file: 'file:///image.jpg', - image_thumb_uri: 'file:///image_thumb.jpg', - is_main_category: false, - subcategories: [] - } - ], - articles: [ - { - title: 'Article One', - url: 'file:///article1.html', - source: 'Mock data', - categories: [ - 'Category One' - ] - }, - { - title: 'Article Two', - url: 'file:///article2.html', - source: 'Mock data', - categories: [ - 'Category One', - 'Category Two' - ] - }, - { - title: 'Article Three', - url: 'file:///article3.html', - source: 'Mock data', - categories: [ - 'Category Two' - ] - } - ] - }; - beforeEach(function () { - let model = new DomainWikiModel.DomainWikiModel(); - - jasmine.addMatchers({ - toHaveObjectsContainingProperties: function () { - return { - compare: function (actual, propertyMap) { - let result = { - pass: (function () { - for (let property in propertyMap) { - let allValuesListedHaveAMatchForObject = actual.some(function (object) { - if (object[property] == 'undefined') { - return false; - } - - let propertyValueMatchedForObject = - propertyMap[property].some(function (value) { - return object[property] == value; - }); - - return propertyValueMatchedForObject; - }); - - if (!allValuesListedHaveAMatchForObject) - return false; - } - - return true; - })(), - - message: (function () { - let msg = 'Expected objects to have the following values for the following properties \n'; - for (let property in propertyMap) { - msg += ' - Property: ' + property + '\n'; - for (let value in propertyMap[property]) { - msg += ' * Value: ' + propertyMap[property][value].toString() + '\n'; - } - } - - msg += 'Object actually has the following toplevel properties\n'; - - for (let i = 0; i < actual.length; i++) { - let object = actual[i]; - msg += ' Object in position ' + i + '\n'; - for (let property in object) { - msg += ' - ' + property + ' : ' + object[property] + '\n'; - } - } - - return msg; - })() - }; - - return result; - } - }; - } - }); - }); - - describe('when loaded from some mock JSON data', function () { - let model; - beforeEach(function () { - model = new DomainWikiModel.DomainWikiModel(); - model.loadFromJson(mockJsonData); - }); - - it('returns all articles when getting articles', function () { - let articles = model.getArticles(); - expect(articles).toHaveObjectsContainingProperties({ - title: [ 'Article One', 'Article Two', 'Article Three' ] - }); - }); - - it('can get articles for a category', function () { - let articles = model.getArticlesForCategory('Category One'); - expect(articles).toHaveObjectsContainingProperties({ - title: [ 'Article One', 'Article Two' ] - }); - }); - - it('has no articles on a category that does not have articles', function () { - let articles = model.getArticlesForCategory('Main Category'); - expect(articles.length).toEqual(0); - }); - - it('has no articles for a category that does not exist', function () { - let articles = model.getArticlesForCategory('Nonexistent'); - expect(articles.length).toEqual(0); - }); - - it('can check whether or not a category has articles', function () { - expect(model._getCategoryHasArticles('Category Two')).toBeTruthy(); - }); - - it('can check whether or not a category does not have articles', function () { - expect(model._getCategoryHasArticles('Category Three')).toBeFalsy(); - }); - - it('verifies that a category that does not exist has no articles', function () { - expect(model._getCategoryHasArticles('Nonexistent')).toBeFalsy(); - }); - - describe('category fetch', function () { - let category; - - beforeEach(function () { - category = model.getCategory('Category One'); - }); - - it('actually returns a category', function () { - expect(category.__name__).toEqual('CategoryModel'); - }); - - it('returns the right category', function () { - expect(category.title).toEqual('Category One'); - }); - }); - - it("returns an undefined value if we try to get a category that doesn't exist", function () { - expect(model.getCategory('Nonexistent')).toBeUndefined(); - }); - - it("returns 'Main Category' when getting the main category", function () { - let category = model.getMainCategory(); - - expect(category).toEqual(new jasmine.ObjectContaining({ - 'title' : 'Main Category' - })); - }); - }); - - it('returns null when the Main Category is unset', function () { - let model = new DomainWikiModel.DomainWikiModel(); - expect(model.getMainCategory()).toBeNull(); - }); -}); |