forked from udacity/frontend-nanodegree-feedreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedreader.js
122 lines (108 loc) · 4.37 KB
/
feedreader.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* feedreader.js
*
* This is the spec file that Jasmine will read and contains
* all of the tests that will be run against your application.
*/
/* We're placing all of our tests within the $() function,
* since some of these tests may require DOM elements. We want
* to ensure they don't run until the DOM is ready.
*/
$(function() {
/* This is our first test suite - a test suite just contains
* a related set of tests. This suite is all about the RSS
* feeds definitions, the allFeeds variable in our application.
*/
describe('RSS Feeds', function() {
/* This is our first test - it tests to make sure that the
* allFeeds variable has been defined and that it is not
* empty. Experiment with this before you get started on
* the rest of this project. What happens when you change
* allFeeds in app.js to be an empty array and refresh the
* page?
*/
it('are defined', function() {
expect(allFeeds).toBeDefined();
expect(allFeeds.length).not.toBe(0);
});
/* TODO: Write a test that loops through each feed
* in the allFeeds object and ensures it has a URL defined
* and that the URL is not empty.
*/
it('are urls', function () {
for (var i = 0; i < allFeeds.length; i++) {
expect(allFeeds[i].url).toBeDefined();
expect(allFeeds[i].url.length).not.toBe(0);
}
});
/* TODO: Write a test that loops through each feed
* in the allFeeds object and ensures it has a name defined
* and that the name is not empty.
*/
it('are names', function () {
for (var i = 0; i < allFeeds.length; i++) {
expect(allFeeds[i].name).toBeDefined();
expect(allFeeds[i].name.length).not.toBe(0);
}
});
});
/* TODO: Write a new test suite named "The menu" */
describe('The menu', function () {
/* TODO: Write a test that ensures the menu element is
* hidden by default. You'll have to analyze the HTML and
* the CSS to determine how we're performing the
* hiding/showing of the menu element.
*/
it('is hidden', function () {
expect($('body').hasClass('menu-hidden')).toBe(true);
});
/* TODO: Write a test that ensures the menu changes
* visibility when the menu icon is clicked. This test
* should have two expectations: does the menu display when
* clicked and does it hide when clicked again.
*/
it('toggles', function () {
var menuButton = $('.menu-icon-link');
var body = $('body');
menuButton.trigger('click');
expect(body.hasClass('menu-hidden')).toBe(false);
menuButton.trigger('click');
expect(body.hasClass('menu-hidden')).toBe(true);
});
});
/* TODO: Write a new test suite named "Initial Entries" */
describe('Initial Entries', function () {
/* TODO: Write a test that ensures when the loadFeed
* function is called and completes its work, there is at least
* a single .entry element within the .feed container.
* Remember, loadFeed() is asynchronous so this test will require
* the use of Jasmine's beforeEach and asynchronous done() function.
*/
it('loads feed', function (done) {
loadFeed(0, function () {
expect($('.feed .entry').length).toBeGreaterThan(0);
done();
});
});
});
/* TODO: Write a new test suite named "New Feed Selection" */
describe('New Feed Selection', function () {
var initialTitle = '';
/* TODO: Write a test that ensures when a new feed is loaded
* by the loadFeed function that the content actually changes.
* Remember, loadFeed() is asynchronous.
*/
beforeEach(function (done) {
loadFeed(0, function () {
initialTitle = $('.feed .entry:first').find('h2').html();
done();
});
});
it('changes feeds', function (done) {
loadFeed(1, function () {
var nextTitle = $('.feed .entry:first').find('h2').html();
expect(nextTitle).not.toBe(initialTitle);
done();
})
});
});
}());