notes_spec.js 1.77 KB
Newer Older
1 2 3 4 5 6 7
define([
    'js/spec/edxnotes/helpers', 'js/edxnotes/collections/notes'
], function(Helpers, NotesCollection) {
    'use strict';
    describe('EdxNotes NotesCollection', function() {
        var notes = Helpers.getDefaultNotes();

8
        beforeEach(function() {
9
            this.collection = new NotesCollection(notes, {perPage: 10, parse: true});
10 11
        });

12
        it('can return correct course structure', function() {
13 14 15 16 17 18 19 20 21 22 23 24 25
            var structure = this.collection.getCourseStructure();

            expect(structure.chapters).toEqual([
                Helpers.getChapter('First Chapter', 1, 0, [2]),
                Helpers.getChapter('Second Chapter', 0, 1, [1, 'w_n', 0])
            ]);

            expect(structure.sections).toEqual({
                'i4x://section/0': Helpers.getSection('Third Section', 0, ['w_n', 1, 0]),
                'i4x://section/1': Helpers.getSection('Second Section', 1, [2]),
                'i4x://section/2': Helpers.getSection('First Section', 2, [3])
            });

26
            var compareUnits = function(structureUnits, collectionUnits) {
27
                expect(structureUnits.length === collectionUnits.length).toBeTruthy();
28
                for (var i = 0; i < structureUnits.length; i++) {
29 30 31 32 33
                    expect(structureUnits[i].attributes).toEqual(collectionUnits[i].attributes);
                }
            };

            var units = {
34 35 36 37
                'i4x://unit/0': [this.collection.at(0), this.collection.at(1)],
                'i4x://unit/1': [this.collection.at(2)],
                'i4x://unit/2': [this.collection.at(3)],
                'i4x://unit/3': [this.collection.at(4)]
38 39
            };

40
            _.each(units, function(value, key) {
41
                compareUnits(structure.units[key], value);
42 43 44 45
            });
        });
    });
});