<commit_before>module.exports = function(grunt) {
    'use strict';

    var jsdom = require('jsdom');
    var path = require('path');
    var fs = require('fs');
    var request = require('request');
    var async = require('async');
    var pluginName = 'referencejs';
    var cachedRequests = path.resolve('./.grunt/' + pluginName + '/cachedRequests.js');

    var scripts = [
        '//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js',
        '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.1/underscore-min.js'
    ];

    var documentToSource = function(document) {
        return document.doctype.toString() + document.innerHTML;
    };

    grunt.registerMultiTask('renderReferencePage', function() {
        var done = this.async();

        var filePath = '/mnt/Windows/nbsoftsolutions/_site/blog/reference-track-sheet.html';
        jsdom.env(filePath, scripts, function(errors, window) {
            var $ = window.$;
            var _ = window._;

            var contents = fs.readFileSync(cachedRequests);
            contents = JSON.parse(contents);

            // Extracts all the books from all the posts and groups them by
            // their id.  Then creates an object that simplifies properties.
            // Orders the array such that most cited books are first.
            contents = _.chain(contents)
            .pluck('data')
            .flatten()
            .filter(function(val) { return !val.periodical && !val.website; })
            .groupBy(function(val) { return val.requestResult.id; })
            .map(function(val) {
                return {
                    count: val.length,
                    title: val[0].requestResult.volumeInfo.title,
                    authors: val[0].requestResult.volumeInfo.authors,
                    description: val[0].requestResult.volumeInfo.description,
                    publishedDate: val[0].requestResult.volumeInfo.publishedDate,
                    publisher: val[0].requestResult.volumeInfo.publisher,
                    image: val[0].requestResult.volumeInfo.imageLinks.thumbnail
                };
            })
            .sortBy(function(val) { return val.count; })
            .value()
            .reverse();

            var templ = _.template($('#referencePageTmpl').html());

            $('div.Product').append($('<div>').html(templ({ references: contents })));

            // jsdom appends script elements that are passed into it with a
            // script tag of jsdom class. Remove these.
            $('script.jsdom').remove();

            fs.writeFileSync(filePath, documentToSource(window.document));
            done();
        });
    });

    grunt.registerMultiTask('reference', function() {
        var task = this;
        var done = this.async();
        var files = this.filesSrc;

        // Finds all the citable elements from a given DOM and maps them to an
        // intermediate object that houses information about how further
        // information should be retrieved.  Returns these intermediate
        // objects.
        var getCitableReferences = function(window) {
            var $ = window.$;
            var _ = window._;

            var referenceElements = $('[cite], cite');

            return _.map(referenceElements, function(val, ind, arr) {
                var citation = $.trim(val.getAttribute('cite') || $(val).text());

                var split = citation.split(' ');
                var lookup = split[0];
                var pageReference = split[1];

                return {
                    element: val,
                    elementIndex: ind,
                    page: parseInt(pageReference, 10) || 0,
                    periodical: lookup.indexOf('/') !== -1 && lookup.indexOf('http') === -1,
                    website: lookup.indexOf('http') !== -1,
                    lookup: lookup
                };
            });
        };

        // ayncronously requests data for a citation.  Depending on how the
        // citation is formatted, the requests will be sent to a different
        // source.
        var processDOM = function(window, options, callback) {
            var $ = window.$;
            var _ = window._;
            var requests = getCitableReferences(window);

            async.each(requests, function(newCitation, lookupComplete) {
                var lookup = newCitation.lookup;
                if (newCitation.website) {
                    newCitation.requestResult = { id: lookup, authors: [] };
                    lookupComplete();
                }
                else if (newCitation.periodical) {
                    var urlP = 'http://api.altmetric.com/v1/doi/' + lookup;
                    request.get(urlP, function(error, response, body) {
                        body = JSON.parse(body);
                        newCitation.requestResult = body;
                        newCitation.requestResult.publishedDate = new Date(body.published_on * 1000);
                        newCitation.requestResult.id = newCitation.requestResult.doi;
                        newCitation.requestResult.authors = [];
                        lookupComplete();
                    });
                }
                else {
                    var urlG = 'https://www.googleapis.com/books/v1/volumes?q=isbn:' + lookup;
                    request.get(urlG, function(error, response, body) {
                        body = JSON.parse(body);
                        newCitation.requestResult = body.items[0];
                        newCitation.requestResult.volumeInfo.publishedDate = new Date(Date.parse(newCitation.requestResult.volumeInfo.publishedDate));
                        lookupComplete();
                    });
                }
            }, function(err) {
                callback(window, requests, options);
            });
        };

        // Finds any equivalencies between the found data
        var mapIbids = function(arr) {

            // An ibid occurs whenever the citation immediately prior has the
            // same id.
            for (var i = 1; i < arr.length; i++) {
                arr[i].ibid = arr[i].requestResult.id === arr[i-1].requestResult.id;
            }
        };

        // Modify the DOM with the found data and overwrite the old file
        var domRequestsCompleted = function(window, data, options) {
            var $ = window.$;
            var _ = window._;

            mapIbids(data);

            var container = $('#' + options.referenceContainer);
            var elementTemplate = _.template($('#' + options.elementTemplateId).html());
            var containerTemplate = _.template($('#' + options.referenceTemplateId).html());

            // Render the template which is inserted after each citation element
            data.forEach(function(val, ind) {
                $(val.element).after(elementTemplate({ i: ind }));
            });

            // Render the template which holds all of the page's references
            container.html(containerTemplate({ references: data }));

            // jsdom appends script elements that are passed into it with a
            // script tag of jsdom class. Remove these.
            $('script.jsdom').remove();

            fs.writeFileSync(window.location.pathname, documentToSource(window.document));
        };

        // If we've already aggregated the data into a file, we should re-use
        // that data instead issuing additional requests.  This also avoids
        // the problem that google throttles usage above a certain threshold
        if (fs.existsSync(cachedRequests)) {
            var contents = fs.readFileSync(cachedRequests);
            contents = JSON.parse(contents);
        }

        var fileJSON = [];
        async.each(files, function(f, callback) {
            jsdom.env(path.resolve(f), scripts, function(errors, window) {

                // If we have already calculated the citations for this file
                // use them instead of sending new requests.
                if (!errors && contents) {
                    var _ = window._;

                    // Have to re-figure out citable elements because they
                    // could not be saved due to their cyclical nature
                    var requests = getCitableReferences(window);
                    var doc = _.find(contents, function(val) {
                        return val.path === window.location.pathname;
                    });

                    // If the page had citations...
                    if (doc !== undefined) {
                        doc.data.forEach(function(val, ind) {
                            val.elementIndex = ind;
                            val.element = requests[ind].element;

                            // JSON dates are a pain to extract
                            if (val.requestResult.publishedDate !== undefined) {
                                val.requestResult.publishedDate =
                                    new Date(Date.parse(val.requestResult.publishedDate));
                            }
                            else if (!val.website && !val.periodical &&
                                val.requestResult.volumeInfo.publishedDate !== undefined) {
                                val.requestResult.volumeInfo.publishedDate =
                                    new Date(Date.parse(val.requestResult.volumeInfo.publishedDate));
                            }
                        });

                        domRequestsCompleted(window, doc.data, task.options());
                    }
                    callback();
                }
                else if (!errors) {
                    processDOM(window, task.options(), function(window, data, options) {

                        // If citable elements were found in the page...
                        if (data.length !== 0) {
                            domRequestsCompleted(window, data, options);

                            // Delete element because of its cyclical nature.
                            // JSON can't encode DOM elements
                            data.forEach(function(val, ind) {
                                delete val.element;
                                delete val.elementIndex;
                            });

                            var newFile = {
                                title: window.document.title,
                                path: window.location.pathname,
                                data: data
                            };

                            fileJSON.push(newFile);
                        }
                        callback();
                    });
                }
                else {
                    grunt.log.writeln('error');
                    callback();
                }
            });
        }, function(error) {
            if (!contents) {
                fs.writeFileSync(cachedRequests, JSON.stringify(fileJSON, null, '\t'));
            }
            done();
        });
    });
};
<commit_msg>Fix #4: Required configurations<commit_after>module.exports = function(grunt) {
    'use strict';

    var jsdom = require('jsdom');
    var path = require('path');
    var fs = require('fs');
    var request = require('request');
    var async = require('async');
    var pluginName = 'referencejs';
    var cachedRequests = path.resolve('./.grunt/' + pluginName + '/cachedRequests.js');

    var scripts = [
        '//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js',
        '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.1/underscore-min.js'
    ];

    var documentToSource = function(document) {
        return document.doctype.toString() + document.innerHTML;
    };

    var parseRequired = function(task, arr) {
        var options = {};
        arr.forEach(function(val) {
            if (task.data[val] === undefined) {
                grunt.fail.fatal('Must provide ' + val + ' option');
            }
            else {
                options[val] = task.data[val];
            }
        });

        return options;
    };

    grunt.registerMultiTask('renderReferencePage', function() {
        var done = this.async();

        var filePath = '/mnt/Windows/nbsoftsolutions/_site/blog/reference-track-sheet.html';
        jsdom.env(filePath, scripts, function(errors, window) {
            var $ = window.$;
            var _ = window._;

            var contents = fs.readFileSync(cachedRequests);
            contents = JSON.parse(contents);

            // Extracts all the books from all the posts and groups them by
            // their id.  Then creates an object that simplifies properties.
            // Orders the array such that most cited books are first.
            contents = _.chain(contents)
            .pluck('data')
            .flatten()
            .filter(function(val) { return !val.periodical && !val.website; })
            .groupBy(function(val) { return val.requestResult.id; })
            .map(function(val) {
                return {
                    count: val.length,
                    title: val[0].requestResult.volumeInfo.title,
                    authors: val[0].requestResult.volumeInfo.authors,
                    description: val[0].requestResult.volumeInfo.description,
                    publishedDate: val[0].requestResult.volumeInfo.publishedDate,
                    publisher: val[0].requestResult.volumeInfo.publisher,
                    image: val[0].requestResult.volumeInfo.imageLinks.thumbnail
                };
            })
            .sortBy(function(val) { return val.count; })
            .value()
            .reverse();

            var templ = _.template($('#referencePageTmpl').html());

            $('div.Product').append($('<div>').html(templ({ references: contents })));

            // jsdom appends script elements that are passed into it with a
            // script tag of jsdom class. Remove these.
            $('script.jsdom').remove();

            fs.writeFileSync(filePath, documentToSource(window.document));
            done();
        });
    });

    grunt.registerMultiTask('reference', function() {
        var task = this;
        var done = this.async();
        var files = this.filesSrc;

        // Finds all the citable elements from a given DOM and maps them to an
        // intermediate object that houses information about how further
        // information should be retrieved.  Returns these intermediate
        // objects.
        var getCitableReferences = function(window) {
            var $ = window.$;
            var _ = window._;

            var referenceElements = $('[cite], cite');

            return _.map(referenceElements, function(val, ind, arr) {
                var citation = $.trim(val.getAttribute('cite') || $(val).text());

                var split = citation.split(' ');
                var lookup = split[0];
                var pageReference = split[1];

                return {
                    element: val,
                    elementIndex: ind,
                    page: parseInt(pageReference, 10) || 0,
                    periodical: lookup.indexOf('/') !== -1 && lookup.indexOf('http') === -1,
                    website: lookup.indexOf('http') !== -1,
                    lookup: lookup
                };
            });
        };

        // ayncronously requests data for a citation.  Depending on how the
        // citation is formatted, the requests will be sent to a different
        // source.
        var processDOM = function(window, options, callback) {
            var $ = window.$;
            var _ = window._;
            var requests = getCitableReferences(window);

            async.each(requests, function(newCitation, lookupComplete) {
                var lookup = newCitation.lookup;
                if (newCitation.website) {
                    newCitation.requestResult = { id: lookup, authors: [] };
                    lookupComplete();
                }
                else if (newCitation.periodical) {
                    var urlP = 'http://api.altmetric.com/v1/doi/' + lookup;
                    request.get(urlP, function(error, response, body) {
                        body = JSON.parse(body);
                        newCitation.requestResult = body;
                        newCitation.requestResult.publishedDate = new Date(body.published_on * 1000);
                        newCitation.requestResult.id = newCitation.requestResult.doi;
                        newCitation.requestResult.authors = [];
                        lookupComplete();
                    });
                }
                else {
                    var urlG = 'https://www.googleapis.com/books/v1/volumes?q=isbn:' + lookup;
                    request.get(urlG, function(error, response, body) {
                        body = JSON.parse(body);
                        newCitation.requestResult = body.items[0];
                        newCitation.requestResult.volumeInfo.publishedDate = new Date(Date.parse(newCitation.requestResult.volumeInfo.publishedDate));
                        lookupComplete();
                    });
                }
            }, function(err) {
                callback(window, requests, options);
            });
        };

        // Finds any equivalencies between the found data
        var mapIbids = function(arr) {

            // An ibid occurs whenever the citation immediately prior has the
            // same id.
            for (var i = 1; i < arr.length; i++) {
                arr[i].ibid = arr[i].requestResult.id === arr[i-1].requestResult.id;
            }
        };

        // Modify the DOM with the found data and overwrite the old file
        var domRequestsCompleted = function(window, data, options) {
            var $ = window.$;
            var _ = window._;

            mapIbids(data);

            var container = $('#' + options.referenceContainerId);
            var elementTemplate = _.template($('#' + options.elementTemplateId).html());
            var containerTemplate = _.template($('#' + options.referenceTemplateId).html());

            // Render the template which is inserted after each citation element
            data.forEach(function(val, ind) {
                $(val.element).after(elementTemplate({ i: ind }));
            });

            // Render the template which holds all of the page's references
            container.html(containerTemplate({ references: data }));

            // jsdom appends script elements that are passed into it with a
            // script tag of jsdom class. Remove these.
            $('script.jsdom').remove();

            fs.writeFileSync(window.location.pathname, documentToSource(window.document));
        };

        var requiredConfig = ['referenceContainerId', 'elementTemplateId', 'referenceTemplateId'];
        var options = parseRequired(task, requiredConfig);

        // If we've already aggregated the data into a file, we should re-use
        // that data instead issuing additional requests.  This also avoids
        // the problem that google throttles usage above a certain threshold
        if (fs.existsSync(cachedRequests)) {
            var contents = fs.readFileSync(cachedRequests);
            contents = JSON.parse(contents);
        }

        var fileJSON = [];
        async.each(files, function(f, callback) {
            jsdom.env(path.resolve(f), scripts, function(errors, window) {

                // If we have already calculated the citations for this file
                // use them instead of sending new requests.
                if (!errors && contents) {
                    var _ = window._;

                    // Have to re-figure out citable elements because they
                    // could not be saved due to their cyclical nature
                    var requests = getCitableReferences(window);
                    var doc = _.find(contents, function(val) {
                        return val.path === window.location.pathname;
                    });

                    // If the page had citations...
                    if (doc !== undefined) {
                        doc.data.forEach(function(val, ind) {
                            val.elementIndex = ind;
                            val.element = requests[ind].element;

                            // JSON dates are a pain to extract
                            if (val.requestResult.publishedDate !== undefined) {
                                val.requestResult.publishedDate =
                                    new Date(Date.parse(val.requestResult.publishedDate));
                            }
                            else if (!val.website && !val.periodical &&
                                val.requestResult.volumeInfo.publishedDate !== undefined) {
                                val.requestResult.volumeInfo.publishedDate =
                                    new Date(Date.parse(val.requestResult.volumeInfo.publishedDate));
                            }
                        });

                        domRequestsCompleted(window, doc.data, options);
                    }
                    callback();
                }
                else if (!errors) {
                    processDOM(window, options, function(window, data, options) {

                        // If citable elements were found in the page...
                        if (data.length !== 0) {
                            domRequestsCompleted(window, data, options);

                            // Delete element because of its cyclical nature.
                            // JSON can't encode DOM elements
                            data.forEach(function(val, ind) {
                                delete val.element;
                                delete val.elementIndex;
                            });

                            var newFile = {
                                title: window.document.title,
                                path: window.location.pathname,
                                data: data
                            };

                            fileJSON.push(newFile);
                        }
                        callback();
                    });
                }
                else {
                    grunt.log.writeln('error');
                    callback();
                }
            });
        }, function(error) {
            if (!contents) {
                fs.writeFileSync(cachedRequests, JSON.stringify(fileJSON, null, '\t'));
            }
            done();
        });
    });
};
<|endoftext|>


<commit_before>/**
 * Question Options Configuration
 */

var questions_all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27];
var questions_eboard = [15];
var questions_rtps = [12, 14];

$(document).ready(function () {

    $.ajax({
        type: "GET",
        url: "/voted",
        success: function (data) {
            if (data.voted) {
                $("#spinnerContainer").fadeOut('slow', function () {
                    $("#thankYouContainer").slideDown('slow');
                });
            } else {
                update_options();
            }
        },
        error: function (data) {
            notify("error", "Unable to retrieve voting status.");
        }
    })

});

/* Form Submission */
$("#submitBtn").click(function (event) {
    // Disable modal buttons and show spinner
    $("#submitConfirmModal button").attr('disabled', 'disabled');
    $("#submitConfirmModal .modal-body p").fadeOut('slow', function () {
        $("#submitConfirmModal .modal-body .spinner").fadeIn('slow', function () {
            if ($("#quote").val() == "" || $("#memory").val() == "") {
                notify("error", "All fields are required. Please try again.");

                // Reset dialog
                $("#submitConfirmModal button").removeAttr('disabled');
                $("#submitConfirmModal .modal-body .spinner").hide();
                $("#submitConfirmModal .modal-body p").show();
                $("#submitConfirmModal").modal('hide');
            } else {
                $.ajax({
                    type: "POST",
                    url: '/submit',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: JSON.stringify({
                        "quote": $("#quote").val(),
                        "history": $("#memory").val(),
                        "answers": {
                            superlative_0: $("#superlative_0").val(),
                            superlative_1: $("#superlative_1").val(),
                            superlative_2: $("#superlative_2").val(),
                            superlative_3: $("#superlative_3").val(),
                            superlative_4: $("#superlative_4").val(),
                            superlative_5: $("#superlative_5").val(),
                            superlative_6: $("#superlative_6").val(),
                            superlative_7: $("#superlative_7").val(),
                            superlative_8: $("#superlative_8").val(),
                            superlative_9: $("#superlative_9").val(),
                            superlative_10: $("#superlative_10").val(),
                            superlative_11: $("#superlative_11").val(),
                            superlative_12: $("#superlative_12").val(),
                            superlative_13: $("#superlative_13").val(),
                            superlative_14: $("#superlative_14").val(),
                            superlative_15: $("#superlative_15").val(),
                            superlative_16: $("#superlative_16").val(),
                            superlative_17: $("#superlative_17").val(),
                            superlative_18: $("#superlative_18").val(),
                            superlative_19: $("#superlative_19").val(),
                            superlative_20: $("#superlative_20").val(),
                            superlative_21: $("#superlative_21").val(),
                            superlative_22: $("#superlative_22").val(),
                            superlative_23: $("#superlative_23").val(),
                            superlative_24: $("#superlative_24").val(),
                            superlative_25: $("#superlative_25").val(),
                            superlative_26: $("#superlative_26").val(),
                            superlative_27: $("#superlative_27").val(),
                            superlative_28: $("#superlative_28").val()
                        }
                    }),
                    success: function (data) {
                        notify("success", "Thank you for submitting!");
                        location.reload();
                    },
                    error: function (data) {
                        notify("error", "Failed to submit! Please try again later.")

                        // Reset dialog
                        $("#submitConfirmModal button").removeAttr('disabled');
                        $("#submitConfirmModal .modal-body .spinner").hide();
                        $("#submitConfirmModal .modal-body p").show();
                        $("#submitConfirmModal").modal('hide');
                    }
                });
            }

            return false;
        });
    });
});

/**
 * Fetch people lists from the API
 */

function update_options() {
    $.ajax({
        type: "GET",
        url: "/people",
        success: function (data) {
            $.each(data.people, function (key, value) {
                questions_all.forEach(function (currentValue, index, array) {
                    $('#superlative_' + array[index]).append($("<option></option>").attr("value", value.id).text(value.name));
                });
            });

            $.ajax({
                type: "GET",
                url: "/rtps",
                success: function (data) {
                    $.each(data.people, function (key, value) {
                        questions_rtps.forEach(function (currentValue, index, array) {
                            $('#superlative_' + array[index]).append($("<option></option>").attr("value", value.id).text(value.name));
                        });
                    });

                    $.ajax({
                        type: "GET",
                        url: "/eboard",
                        success: function (data) {
                            $.each(data.people, function (key, value) {
                                questions_eboard.forEach(function (currentValue, index, array) {
                                    $('#superlative_' + array[index]).append($("<option></option>").attr("value", value.id).text(value.name));
                                });
                            });

                            $("#spinnerContainer").fadeOut('slow', function () {
                                $("#formContainer").slideDown('slow');
                            });
                        },
                        error: function (data) {
                            notify("error", "Unable to retrieve eboard list.");
                        }
                    });
                },
                error: function (data) {
                    notify("error", "Unable to retrieve RTP list.");
                }
            });
        },
        error: function (data) {
            notify("error", "Unable to retrieve user list.");
        }
    });
}

/**
 * Add a notification event to the view
 * Params:
 *  - type - alert type (see Noty Docs)
 *  - message - message to display
 **/
function notify(type, message) {
    var layoutType = "bottomRight";

    // Set layout type by display size
    if ($(window).width() < 768) {
        layoutType = "bottom";
    }

    if (type == "success") {
        noty({
            layout: layoutType,
            theme: 'csh',
            text: message,
            type: 'success',
            animation: {
                open: 'animated fadeInUp',
                close: 'animated fadeOutDown',
            },
            maxVisible: 1,
            killer: true
        });
    }
    else if (type == "error") {
        noty({
            layout: layoutType,
            theme: 'csh',
            text: message,
            type: 'error',
            animation: {
                open: 'animated fadeInUp',
                close: 'animated fadeOutDown',
            },
            maxVisible: 1,
            killer: true
        });
    } else if (type == "warning") {
        noty({
            layout: layoutType,
            theme: 'csh',
            text: message,
            type: 'warning',
            animation: {
                open: 'animated fadeInUp',
                close: 'animated fadeOutDown',
            },
            maxVisible: 1,
            killer: true
        });
    }
    else {
        noty({
            layout: layoutType,
            theme: 'csh',
            text: message,
            type: 'information',
            animation: {
                open: 'animated fadeInUp',
                close: 'animated fadeOutDown',
            },
            maxVisible: 1,
            killer: true
        });
    }
    setTimeout(function () {
        $('.animated').removeClass("fadeIn");
        $('.animated').addClass("fadeOutDown");
    }, 3000);

    setTimeout(function () {
        $('.animated').remove();
    }, 3500);

}<commit_msg>List of answers instead of dictionary<commit_after>/**
 * Question Options Configuration
 */

var questions_all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27];
var questions_eboard = [15];
var questions_rtps = [12, 14];

$(document).ready(function () {

    $.ajax({
        type: "GET",
        url: "/voted",
        success: function (data) {
            if (data.voted) {
                $("#spinnerContainer").fadeOut('slow', function () {
                    $("#thankYouContainer").slideDown('slow');
                });
            } else {
                update_options();
            }
        },
        error: function (data) {
            notify("error", "Unable to retrieve voting status.");
        }
    })

});

/* Form Submission */
$("#submitBtn").click(function (event) {
    // Disable modal buttons and show spinner
    $("#submitConfirmModal button").attr('disabled', 'disabled');
    $("#submitConfirmModal .modal-body p").fadeOut('slow', function () {
        $("#submitConfirmModal .modal-body .spinner").fadeIn('slow', function () {
            if ($("#quote").val() == "" || $("#memory").val() == "") {
                notify("error", "All fields are required. Please try again.");

                // Reset dialog
                $("#submitConfirmModal button").removeAttr('disabled');
                $("#submitConfirmModal .modal-body .spinner").hide();
                $("#submitConfirmModal .modal-body p").show();
                $("#submitConfirmModal").modal('hide');
            } else {
                $.ajax({
                    type: "POST",
                    url: '/submit',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: JSON.stringify({
                        "quote": $("#quote").val(),
                        "history": $("#memory").val(),
                        "answers": [
                            $("#superlative_0").val(),
                            $("#superlative_1").val(),
                            $("#superlative_2").val(),
                            $("#superlative_3").val(),
                            $("#superlative_4").val(),
                            $("#superlative_5").val(),
                            $("#superlative_6").val(),
                            $("#superlative_7").val(),
                            $("#superlative_8").val(),
                            $("#superlative_9").val(),
                            $("#superlative_10").val(),
                            $("#superlative_11").val(),
                            $("#superlative_12").val(),
                            $("#superlative_13").val(),
                            $("#superlative_14").val(),
                            $("#superlative_15").val(),
                            $("#superlative_16").val(),
                            $("#superlative_17").val(),
                            $("#superlative_18").val(),
                            $("#superlative_19").val(),
                            $("#superlative_20").val(),
                            $("#superlative_21").val(),
                            $("#superlative_22").val(),
                            $("#superlative_23").val(),
                            $("#superlative_24").val(),
                            $("#superlative_25").val(),
                            $("#superlative_26").val(),
                            $("#superlative_27").val(),
                            $("#superlative_28").val()
                        ]
                    }),
                    success: function (data) {
                        notify("success", "Thank you for submitting!");
                        location.reload();
                    },
                    error: function (data) {
                        notify("error", "Failed to submit! Please try again later.")

                        // Reset dialog
                        $("#submitConfirmModal button").removeAttr('disabled');
                        $("#submitConfirmModal .modal-body .spinner").hide();
                        $("#submitConfirmModal .modal-body p").show();
                        $("#submitConfirmModal").modal('hide');
                    }
                });
            }

            return false;
        });
    });
});

/**
 * Fetch people lists from the API
 */

function update_options() {
    $.ajax({
        type: "GET",
        url: "/people",
        success: function (data) {
            $.each(data.people, function (key, value) {
                questions_all.forEach(function (currentValue, index, array) {
                    $('#superlative_' + array[index]).append($("<option></option>").attr("value", value.id).text(value.name));
                });
            });

            $.ajax({
                type: "GET",
                url: "/rtps",
                success: function (data) {
                    $.each(data.people, function (key, value) {
                        questions_rtps.forEach(function (currentValue, index, array) {
                            $('#superlative_' + array[index]).append($("<option></option>").attr("value", value.id).text(value.name));
                        });
                    });

                    $.ajax({
                        type: "GET",
                        url: "/eboard",
                        success: function (data) {
                            $.each(data.people, function (key, value) {
                                questions_eboard.forEach(function (currentValue, index, array) {
                                    $('#superlative_' + array[index]).append($("<option></option>").attr("value", value.id).text(value.name));
                                });
                            });

                            $("#spinnerContainer").fadeOut('slow', function () {
                                $("#formContainer").slideDown('slow');
                            });
                        },
                        error: function (data) {
                            notify("error", "Unable to retrieve eboard list.");
                        }
                    });
                },
                error: function (data) {
                    notify("error", "Unable to retrieve RTP list.");
                }
            });
        },
        error: function (data) {
            notify("error", "Unable to retrieve user list.");
        }
    });
}

/**
 * Add a notification event to the view
 * Params:
 *  - type - alert type (see Noty Docs)
 *  - message - message to display
 **/
function notify(type, message) {
    var layoutType = "bottomRight";

    // Set layout type by display size
    if ($(window).width() < 768) {
        layoutType = "bottom";
    }

    if (type == "success") {
        noty({
            layout: layoutType,
            theme: 'csh',
            text: message,
            type: 'success',
            animation: {
                open: 'animated fadeInUp',
                close: 'animated fadeOutDown',
            },
            maxVisible: 1,
            killer: true
        });
    }
    else if (type == "error") {
        noty({
            layout: layoutType,
            theme: 'csh',
            text: message,
            type: 'error',
            animation: {
                open: 'animated fadeInUp',
                close: 'animated fadeOutDown',
            },
            maxVisible: 1,
            killer: true
        });
    } else if (type == "warning") {
        noty({
            layout: layoutType,
            theme: 'csh',
            text: message,
            type: 'warning',
            animation: {
                open: 'animated fadeInUp',
                close: 'animated fadeOutDown',
            },
            maxVisible: 1,
            killer: true
        });
    }
    else {
        noty({
            layout: layoutType,
            theme: 'csh',
            text: message,
            type: 'information',
            animation: {
                open: 'animated fadeInUp',
                close: 'animated fadeOutDown',
            },
            maxVisible: 1,
            killer: true
        });
    }
    setTimeout(function () {
        $('.animated').removeClass("fadeIn");
        $('.animated').addClass("fadeOutDown");
    }, 3000);

    setTimeout(function () {
        $('.animated').remove();
    }, 3500);

}<|endoftext|>


<commit_before>
(function(){

var emailPattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-     9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var pwdPattern = /[a-zA-Z0-9_]{8,}/;

angular.module('fgSubscriber', ['ngResource'])
  .factory('Subscriber', function($resource) {
    var _x_access_token, _ops;
    _x_access_token = '';
    _ops = $resource('/api/subscriber/:op', {
        op: '@op'
      }, {
        'register': { method: 'POST', params: { op: 'register' } },
        'verify':   { method: 'POST', params: { op: 'verify' } },
        'forgot':   { method: 'POST', params: { op: 'forgot' } },
        'login':    { method: 'POST', params: { op: 'login' } },
        'logout':   { method: 'POST', params: { op: 'logout' },
                      headers: { 'x-access-token': _x_access_token }
        },
        'update':   { method: 'POST', params: { op: 'update' },
                      headers: { 'x-access-token': _x_access_token }
        }
      });
    return {
      x_access_token: _x_access_token,
      ops: _ops
    };
  })
  .controller('fgSubAuth', function($scope, Subscriber) {

    $scope.logout = function() {
      Subscriber.ops.logout({}, function(data) {
        Subscriber.x_access_token = '';
        if(data.error) {
        } else {
        }
      });
    };

    $scope.update = function() {
      if(!pwdPattern.test($scope.oldPassword)) {
      } else if(!pwdPattern.test($scope.newPassword1) {
      } else if($scope.newPassword1 !== $scope.newPassword2) {
      } else {
        Subscriber.ops.update({
          oldPassword: $scope.oldPassword,
          newPassword: $scope.newPassword1
        }, function(data) {
          if(data.error) {
          } else {
          }
        });
      };
    }

  })
  .controller('fgSubLogin', function($scope, Subscriber) {

    $scope.login = function() {
      if(!emailPattern.test($scope.email) {
         $scope.emailError = true;
         $scope.emailMsg = 'Invalid email address';
      } else if(!pwdPattern.test($scope.password) {
         $scope.pwdError = true;
         $scope.pwdMsg = 'Bad password';
      } else {
        Subscriber.ops.login({
          email: $scope.email,
          password: $scope.password
        }, function(data) {
          if(data.error) {
          } else {
            Subscriber.x_access_token = data.token;
          }
        });
      }
    };

    $scope.forgot = function() {
      if(!emailPattern.test($scope.email) {
        $scope.emailError = true;
        $scope.emailMsg = 'Invalid email address';
      } else {
        Subscriber.ops.forgot({
          email: $scope.email
        }, function(data) {
          if(data.error) {
          } else {
          }
        });
      }
    };

  })
  .controller('fgSubRegister', function($scope, Subscriber) {

    $scope.email     = '';
    $scope.password1 = '';
    $scope.password2 = '';

    $scope.success = false;
    $scope.failure = false;

    function reset() {
      $scope.emailError = false;
      $scope.emailMsg = '';

      $scope.pwd1Error = false;
      $scope.pwd1Msg = '';

      $scope.pwd2Error = false;
      $scope.pwd2Msg = '';
    }

    $scope.register = function() {
      // Reset any existing error indications
      reset();
      // Test the input for validity
      if(!emailPattern.test($scope.email)) {
        $scope.emailError = true;
        $scope.emailMsg = 'Invalid email address';
      } else if(!pwdPattern.test($scope.password1)) {
        $scope.pwd1Error = true;
        $scope.pwd1Msg = 'Bad password';
      } else if($scope.password1 !== $scope.password2) {
        $scope.pwd2Error = true;
        $scope.pwd2Msg = 'Passwords do not match';
      } else {
        // Create a new subscriber
        Subscriber.ops.register({
          email:    $scope.email,
          password: $scope.password1
        }, function(data) {
          if(data.error) {
            console.log(data.error);
            $scope.failure = true;
          } else {
            console.log(data.value);
            $scope.success = true;
          }
        });

        /*
        var subscriber = new Subscriber({
          email:    $scope.emailAddr,
          password: $scope.pwd1
        });
        subscriber.$register().then(function(data) {
          if(data.error) {
            console.log(data.error);
            $scope.failure = true;
          } else {
            console.log(data.value);
            $scope.success = true;
          }
        });
        */
      }
    };
});

})();
<commit_msg>latest<commit_after>
(function(){

var emailPattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var pwdPattern = /[a-zA-Z0-9_]{8,}/;

angular.module('fgSubscriber', ['ngResource'])
  .factory('Subscriber', function($resource) {
    var _x_access_token, _ops;
    _x_access_token = '';
    _ops = $resource('/api/subscriber/:op', {
        op: '@op'
      }, {
        'register': { method: 'POST', params: { op: 'register' } },
        'verify':   { method: 'POST', params: { op: 'verify' } },
        'forgot':   { method: 'POST', params: { op: 'forgot' } },
        'login':    { method: 'POST', params: { op: 'login' } },
        'logout':   { method: 'POST', params: { op: 'logout' },
                      headers: { 'x-access-token': _x_access_token }
        },
        'update':   { method: 'POST', params: { op: 'update' },
                      headers: { 'x-access-token': _x_access_token }
        }
      });
    return {
      x_access_token: _x_access_token,
      ops: _ops
    };
  })
  .controller('fgSubAuth', function($scope, Subscriber) {

    $scope.logout = function() {
      Subscriber.ops.logout({}, function(data) {
        Subscriber.x_access_token = '';
        if(data.error) {
        } else {
        }
      });
    };

    $scope.update = function() {
      if(!pwdPattern.test($scope.oldPassword)) {
         $scope.pwdError = true;
          $scope.pwdMsg = 'Bad password';
      } else if(!pwdPattern.test($scope.newPassword1)) {
         $scope.pwdError = true;
         $scope.pwdMsg = 'Bad password';
      } else if($scope.newPassword1 !== $scope.newPassword2) {
         $scope.pwdError = true;
         $scope.pwdMsg = 'Bad password';
      } else {
        Subscriber.ops.update({
          oldPassword: $scope.oldPassword,
          newPassword: $scope.newPassword1
        }, function(data) {
          if(data.error) {
          } else {
          }
        });
      }
    };

  })
  .controller('fgSubLogin', function($scope, Subscriber) {

    $scope.login = function() {
      if(!emailPattern.test($scope.email)) {
         $scope.emailError = true;
         $scope.emailMsg = 'Invalid email address';
      } else if(!pwdPattern.test($scope.password)) {
         $scope.pwdError = true;
         $scope.pwdMsg = 'Bad password';
      } else {
        Subscriber.ops.login({
          email: $scope.email,
          password: $scope.password
        }, function(data) {
          if(data.error) {
          } else {
            Subscriber.x_access_token = data.token;
          }
        });
      }
    };

    $scope.forgot = function() {
      if(!emailPattern.test($scope.email)) {
        $scope.emailError = true;
        $scope.emailMsg = 'Invalid email address';
      } else {
        Subscriber.ops.forgot({
          email: $scope.email
        }, function(data) {
          if(data.error) {
          } else {
          }
        });
      }
    };

  })
  .controller('fgSubRegister', function($scope, Subscriber) {

    $scope.email     = '';
    $scope.password1 = '';
    $scope.password2 = '';

    $scope.success = false;
    $scope.failure = false;

    function reset() {
      $scope.emailError = false;
      $scope.emailMsg = '';

      $scope.pwd1Error = false;
      $scope.pwd1Msg = '';

      $scope.pwd2Error = false;
      $scope.pwd2Msg = '';
    }

    $scope.register = function() {
      // Reset any existing error indications
      reset();
      // Test the input for validity
      if(!emailPattern.test($scope.email)) {
        $scope.emailError = true;
        $scope.emailMsg = 'Invalid email address';
      } else if(!pwdPattern.test($scope.password1)) {
        $scope.pwd1Error = true;
        $scope.pwd1Msg = 'Bad password';
      } else if($scope.password1 !== $scope.password2) {
        $scope.pwd2Error = true;
        $scope.pwd2Msg = 'Passwords do not match';
      } else {
        // Create a new subscriber
        Subscriber.ops.register({
          email:    $scope.email,
          password: $scope.password1
        }, function(data) {
          if(data.error) {
            console.log(data.error);
            $scope.failure = true;
          } else {
            console.log(data.value);
            $scope.success = true;
          }
        });

        /*
        var subscriber = new Subscriber({
          email:    $scope.emailAddr,
          password: $scope.pwd1
        });
        subscriber.$register().then(function(data) {
          if(data.error) {
            console.log(data.error);
            $scope.failure = true;
          } else {
            console.log(data.value);
            $scope.success = true;
          }
        });
        */
      }
    };
});

})();
<|endoftext|>


<commit_before>/*
* Name :  LineChart.js
* Module : UnitTest
* Location : /frontend/test/unit/Model
*
* History :
* Version       Date        Programmer                  Description
* =================================================================================================
* 0.3.0			2015-05-18	Francesco Rossetto			Restructured test
*
* 0.2.3         2015-05-17  Maria Giovanna Chinellato   Fix code
*
* 0.2.2			2015-05-15	Maria Giovanna Chinellato	Fix test of Model::LineChart.js
*
* 0.2.1			2015-05-15	Maria Giovanna Chinellato	Fix methods test
*
* 0.2.0			2015-05-15	Maria Giovanna Chinellato	Add test: all the methods of LineChart classes
*
* 0.1.0			2015-05-15	Francesco Rossetto			Add test of Model::LineChart.js
*
* 0.0.1			2015-05-15	Francesco Rossetto			Initial code
* =================================================================================================
*
*/

describe('LineChart', function(){
	'use strict';

	var LineChart;
	var Graph;
	var Axis;
	var ViewFinder;
	var LineChartFlow;

	beforeEach(angular.mock.module('app'));

	beforeEach(inject(function(_LineChart_, $injector){
		LineChart = _LineChart_;
		Graph = $injector.get('Graph');
		Axis = $injector.get('Axis');
		ViewFinder = $injector.get('Legend');
		LineChartFlow = $injector.get('LineChartFlow');
	}));

	describe('Constructor', function(){

		var json = {
			'title' : 'fottutissimografico',
			'url' : 'localhost/page1/grafico1'
		};

		beforeEach(function(){
			LineChart = new LineChart(json);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('LineChart created', function(){
			expect(LineChart).toBeDefined();
		});
		it('graph Constructor called', function(){
			expect(LineChart.getTitle()).toEqual('fottutissimografico');
		});
		it('graph Constructor called', function(){
			expect(LineChart.getUrl()).toEqual('localhost/page1/grafico1');
		});
		it('graph created with the correct legendOnPoint', function(){
			expect(LineChart.getLegendOnPoint()).toEqual(false);
		});
		it('graph created with the correct axisX', function(){
			expect(LineChart.getX()).toEqual({});
		});
		it('graph created with the correct axisY', function(){
			expect(LineChart.getY()).toEqual({});
		});
		it('graph created with the correct viewFinder', function(){
			expect(LineChart.getViewFinder()).toEqual(false);
		});
		it('graph created with the correct background', function(){
			expect(LineChart.getBackground()).toEqual('#FFF');
		});

	});

	/*describe('split', function(){
		var res;
		var json = {};
		var json1 = json;
		json = json1;
		json = {
			'title' : 'grafico',
			'height' : 300,
			'width' : 300,
			'enabledLegend' : true,
			'legend' : {},
			'horizontalGrid' : true,
			'verticalGrid' : true,
			'axisX' : {},
			'axisY' : {},
			'enabledViewFinder' : true,
			'viewFinder' : {},
			'background' : '#FFF'
		};
		var g = {
			'title' : 'grafico',
			'height' : 300,
			'width' : 300,
			'enabledLegend' : true,
			'legend' : {},
			'horizontalGrid' : true,
			'verticalGrid' : true
		};
		var l = {
			'axisX' : {},
			'axisY' : {},
			'enabledViewFinder' : true,
			'viewFinder' : {},
			'background' : '#FFF'
		};

		beforeEach(function(){
			res = LineChart.prototype.test('split(json)');
		});

		it('json splitted in the correct way', function(){
			expect(res.graphJson).toEqual(g);
			expect(res.lineJson).toEqual(l);
		});

	});*/

	describe('updateParameters', function(){
		var json = {
			'title' : 'graficonuovo',
			'height' : 400,
			'width' : 400,
			'enabledLegend' : false,
			'horizontalGrid' : false,
			'verticalGrid' : false,
			'legendOnPoint' : true,
			'viewFinder' : true,
			'axisX' : {},
			'axisY' : {},
			'backgroundColor' : '#000',
			'flows' : [{},{},{}]
		};

		beforeEach(function(){
			LineChart = new LineChart();
			LineChart.updateParameters(json);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('graph updated with the correct legendOnPoint', function(){
			expect(LineChart.getLegendOnPoint()).toEqual(true);
		});
		it('graph updated with the correct axisX', function(){
			expect(LineChart.getX()).toEqual(null);
		});
		it('graph updated with the correct axisY', function(){
			expect(LineChart.getY()).toEqual(null);
		});
		it('graph updated with the correct viewFinder', function(){
			expect(LineChart.getViewFinder()).toEqual(true);
		});
		it('graph updated with the correct background', function(){
			expect(LineChart.getBackground()).toEqual('#000');
		});
		it('graph updated with the correct flow', function(){
			expect(LineChart.getFlowList().length).toEqual(3);
		});

	});

	describe('addFlow', function(){
		var json = {
			'ID' : 	'flusso1',
		};

		var fJson = {
			'name' : 'flusso1',
			'flowColor' : '#000',
			'marker' : 'none',
			'interpolation' : 'linear',
			'area' : '#FFF',
			'maxItem' : '5'
		};

		var newFlow;

		beforeEach(function(){
			newFlow = new LineChartFlow(fJson);
			LineChart = new LineChart();
			LineChart.addFlow(json.ID, newFlow);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('graph addFlow called with the correct parameters', function(){
			expect(LineChart.getFlowList().length).toEqual(1);
		});

	});

	describe('inizializeData', function(){

		var data = [
			{
				'ID' : '1',
				'records' : [{ 'NorrisRecordID' : '234321', 'value' : [0,1]},{}]
			}
		];

		var newFlow;

		beforeEach(function(){
			newFlow = new LineChartFlow();
			LineChart = new LineChart();
			LineChart.addFlow(data[0].ID, newFlow);
			LineChart.initializeData(data);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('LineChartFlow inizializeData called in the right way', function(){
			expect(LineChart.getFlowList()[0].flow.getData().length).toEqual(2);
		});

	});

	describe('inPlaceUpdate', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];
		var data1 = 	{
			'ID' : '2',
			'NorrisRecordID' : 'record2',
			'value' : [4,4]
		};
		var newFlow;

		beforeEach(function(){
			newFlow = new LineChartFlow();
			LineChart = new LineChart();
			LineChart.addFlow(data[0].ID, newFlow);
			LineChart.initializeData(data);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('LineChartFlow inPlaceUpdate called in the right way', function(){
			expect(LineChart.getFlowList()[0].flow.getData()[0].value[0]).toEqual(3);
			LineChart.inPlaceUpdate(data1);
			expect(LineChart.getFlowList()[0].flow.getData()[0].value[0]).toEqual(4);
		});

	});

	describe('streamUpdate', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];
		var data1 = 	{
			'ID' : '2',
			'records' : [{
				'NorrisRecordID' : 'record2',
				'value' : [4,4]
			}]
		};
		var newFlow;

		beforeEach(function(){
			newFlow = new LineChartFlow();
			LineChart = new LineChart();
			LineChart.addFlow(data[0].ID, newFlow);
			LineChart.initializeData(data);

		});

		afterEach(function(){
			LineChart = null;
		});

		it('LineChartFlow streamUpdate called in the right way', function(){
			expect(LineChart.getFlowList()[0].flow.getData().length).toEqual(1);
			LineChart.streamUpdate(data1);
			expect(LineChart.getFlowList()[0].flow.getData().length).toEqual(2);
		});

	});

});<commit_msg>fix line chart test<commit_after>/*
* Name :  LineChart.js
* Module : UnitTest
* Location : /frontend/test/unit/Model
*
* History :
* Version       Date        Programmer                  Description
* =================================================================================================
* 0.3.0			2015-05-18	Francesco Rossetto			Restructured test
*
* 0.2.3         2015-05-17  Maria Giovanna Chinellato   Fix code
*
* 0.2.2			2015-05-15	Maria Giovanna Chinellato	Fix test of Model::LineChart.js
*
* 0.2.1			2015-05-15	Maria Giovanna Chinellato	Fix methods test
*
* 0.2.0			2015-05-15	Maria Giovanna Chinellato	Add test: all the methods of LineChart classes
*
* 0.1.0			2015-05-15	Francesco Rossetto			Add test of Model::LineChart.js
*
* 0.0.1			2015-05-15	Francesco Rossetto			Initial code
* =================================================================================================
*
*/

describe('LineChart', function(){
	'use strict';

	var LineChart;
	var Graph;
	var Axis;
	var ViewFinder;
	var LineChartFlow;

	beforeEach(angular.mock.module('app'));

	beforeEach(inject(function(_LineChart_, $injector){
		LineChart = _LineChart_;
		Graph = $injector.get('Graph');
		Axis = $injector.get('Axis');
		ViewFinder = $injector.get('Legend');
		LineChartFlow = $injector.get('LineChartFlow');
	}));

	describe('Constructor', function(){

		var json = {
			'title' : 'fottutissimografico',
			'url' : 'localhost/page1/grafico1'
		};

		beforeEach(function(){
			LineChart = new LineChart(json);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('LineChart created', function(){
			expect(LineChart).toBeDefined();
		});
		it('graph Constructor called', function(){
			expect(LineChart.getTitle()).toEqual('fottutissimografico');
		});
		it('graph Constructor called', function(){
			expect(LineChart.getUrl()).toEqual('localhost/page1/grafico1');
		});
		it('graph created with the correct legendOnPoint', function(){
			expect(LineChart.getLegendOnPoint()).toEqual(false);
		});
		it('graph created with the correct axisX', function(){
			expect(LineChart.getX()).toEqual(null);
		});
		it('graph created with the correct axisY', function(){
			expect(LineChart.getY()).toEqual(null);
		});
		it('graph created with the correct viewFinder', function(){
			expect(LineChart.getViewFinder()).toEqual(false);
		});
		it('graph created with the correct background', function(){
			expect(LineChart.getBackground()).toEqual('#FFF');
		});

	});

	/*describe('split', function(){
		var res;
		var json = {};
		var json1 = json;
		json = json1;
		json = {
			'title' : 'grafico',
			'height' : 300,
			'width' : 300,
			'enabledLegend' : true,
			'legend' : {},
			'horizontalGrid' : true,
			'verticalGrid' : true,
			'axisX' : {},
			'axisY' : {},
			'enabledViewFinder' : true,
			'viewFinder' : {},
			'background' : '#FFF'
		};
		var g = {
			'title' : 'grafico',
			'height' : 300,
			'width' : 300,
			'enabledLegend' : true,
			'legend' : {},
			'horizontalGrid' : true,
			'verticalGrid' : true
		};
		var l = {
			'axisX' : {},
			'axisY' : {},
			'enabledViewFinder' : true,
			'viewFinder' : {},
			'background' : '#FFF'
		};

		beforeEach(function(){
			res = LineChart.prototype.test('split(json)');
		});

		it('json splitted in the correct way', function(){
			expect(res.graphJson).toEqual(g);
			expect(res.lineJson).toEqual(l);
		});

	});*/

	describe('updateParameters', function(){
		var json = {
			'title' : 'graficonuovo',
			'height' : 400,
			'width' : 400,
			'enabledLegend' : false,
			'horizontalGrid' : false,
			'verticalGrid' : false,
			'legendOnPoint' : true,
			'viewFinder' : true,
			'axisX' : {},
			'axisY' : {},
			'backgroundColor' : '#000',
			'flows' : [{},{},{}]
		};

		beforeEach(function(){
			LineChart = new LineChart();
			LineChart.updateParameters(json);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('graph updated with the correct legendOnPoint', function(){
			expect(LineChart.getLegendOnPoint()).toEqual(true);
		});
		it('graph updated with the correct axisX', function(){
			expect(LineChart.getX()).toEqual({});
		});
		it('graph updated with the correct axisY', function(){
			expect(LineChart.getY()).toEqual({});
		});
		it('graph updated with the correct viewFinder', function(){
			expect(LineChart.getViewFinder()).toEqual(true);
		});
		it('graph updated with the correct background', function(){
			expect(LineChart.getBackground()).toEqual('#000');
		});
		it('graph updated with the correct flow', function(){
			expect(LineChart.getFlowList().length).toEqual(3);
		});

	});

	describe('addFlow', function(){
		var json = {
			'ID' : 	'flusso1',
		};

		var fJson = {
			'name' : 'flusso1',
			'flowColor' : '#000',
			'marker' : 'none',
			'interpolation' : 'linear',
			'area' : '#FFF',
			'maxItem' : '5'
		};

		var newFlow;

		beforeEach(function(){
			newFlow = new LineChartFlow(fJson);
			LineChart = new LineChart();
			LineChart.addFlow(json.ID, newFlow);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('graph addFlow called with the correct parameters', function(){
			expect(LineChart.getFlowList().length).toEqual(1);
		});

	});

	describe('inizializeData', function(){

		var data = [
			{
				'ID' : '1',
				'records' : [{ 'NorrisRecordID' : '234321', 'value' : [0,1]},{}]
			}
		];

		var newFlow;

		beforeEach(function(){
			newFlow = new LineChartFlow();
			LineChart = new LineChart();
			LineChart.addFlow(data[0].ID, newFlow);
			LineChart.initializeData(data);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('LineChartFlow inizializeData called in the right way', function(){
			expect(LineChart.getFlowList()[0].flow.getData().length).toEqual(2);
		});

	});

	describe('inPlaceUpdate', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];
		var data1 = 	{
			'ID' : '2',
			'NorrisRecordID' : 'record2',
			'value' : [4,4]
		};
		var newFlow;

		beforeEach(function(){
			newFlow = new LineChartFlow();
			LineChart = new LineChart();
			LineChart.addFlow(data[0].ID, newFlow);
			LineChart.initializeData(data);
		});

		afterEach(function(){
			LineChart = null;
		});

		it('LineChartFlow inPlaceUpdate called in the right way', function(){
			expect(LineChart.getFlowList()[0].flow.getData()[0].value[0]).toEqual(3);
			LineChart.inPlaceUpdate(data1);
			expect(LineChart.getFlowList()[0].flow.getData()[0].value[0]).toEqual(4);
		});

	});

	describe('streamUpdate', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];
		var data1 = 	{
			'ID' : '2',
			'records' : [{
				'NorrisRecordID' : 'record2',
				'value' : [4,4]
			}]
		};
		var newFlow;

		beforeEach(function(){
			newFlow = new LineChartFlow();
			LineChart = new LineChart();
			LineChart.addFlow(data[0].ID, newFlow);
			LineChart.initializeData(data);

		});

		afterEach(function(){
			LineChart = null;
		});

		it('LineChartFlow streamUpdate called in the right way', function(){
			expect(LineChart.getFlowList()[0].flow.getData().length).toEqual(1);
			LineChart.streamUpdate(data1);
			expect(LineChart.getFlowList()[0].flow.getData().length).toEqual(2);
		});

	});

});<|endoftext|>


<commit_before>/*
* Name :  LineChart.js
* Module : UnitTest
* Location : /frontend/test/unit/Model
*
* History :
* Version       Date        Programmer                  Description
* =================================================================================================
* 0.2.2         2015-05-17  Maria Giovanna Chinellato   Fix code
*
* 0.2.1			2015-05-15	Maria Giovanna Chinellato	Fix test of Model::Table
*
* 0.2.0			2015-05-15	Maria Giovanna Chinellato	Add test of all the methods of LineChart classes
*
* 0.1.0			2015-05-15	Maria Giovanna Chinellato	Add test of Model::Table.js
*
* 0.0.1			2015-05-15	Maria Giovanna Chinellato	Initial code
* =================================================================================================
*
*/

describe('TableFactory', function(){
	'use strict';

	var TableFactory;
	var TableFlowFactory;

	beforeEach(angular.mock.module('norris-nrti'));

	beforeEach(inject(function(_TableFactory_, $injector){
		TableFactory = _TableFactory_;
		TableFlowFactory = $injector.get('TableFlowFactory');
	}));

	describe('Constructor', function(){

		var json = {
			'title' : 'fottutissimografico',
			'socketURL' : 'localhost/page1/grafico1'
		};
		var Table;

		beforeEach(function(){
			Table = TableFactory.build(json);
		});

		afterEach(function(){
			Table = null;
		});

		it('Table created', function(){
			expect(Table).toBeDefined();
		});
		it('graph Constructor called', function(){
			expect(Table.getTitle()).toEqual('fottutissimografico');
		});
		it('graph Constructor called', function(){
			expect(Table.getUrl()).toEqual('localhost/page1/grafico1');
		});
		it('graph created with the correct headers', function(){
			expect(Table.getHeaders()).toEqual([]);
		});
		it('graph created with the correct item displayed per page', function(){
			expect(Table.getMaxItemsPage()).toEqual(20);
		});
		it('graph created with the correct add data position', function(){
			expect(Table.getAddRowOn()).toEqual('top');
		});
		it('graph created with the correct sortable', function(){
			expect(Table.getSortable()).toEqual(true);
		});
		it('graph created with the correct sort', function(){
			expect(Table.getSort()).toEqual(null);
		});
		it('graph created with the correct appearance', function(){
			expect(Table.getAppearance()).toEqual(null);
		});

	});

	/*describe('split', function(){
		var res;
		var json = {};
		var json1 = json;
		json = json1;
		json = {
			'title' : 'grafico',
			'height' : 300,
			'width' : 300,
			'enabledLegend' : true,
			'legend' : {},
			'horizontalGrid' : true,
			'verticalGrid' : true,
			'row' : 5,
			'colunms' : 8,
			'headers' : {},
			'cells' : {},
			'itemDisplayedPerPage' : 4,
			'addDataPosition' : '',
			'sortable' : true
		};
		var g = {
			'title' : 'grafico',
			'height' : 300,
			'width' : 300,
			'enabledLegend' : true,
			'legend' : {},
			'horizontalGrid' : true,
			'verticalGrid' : true
		};
		var t = {
			'row' : 5,
			'colunms' : 8,
			'headers' : {},
			'cells' : {},
			'itemDisplayedPerPage' : 4,
			'addDataPosition' : 'down',
			'sortable' : true
		};

		beforeEach(function(){
			res = Table.Test('split(json)');
		});

		it('json splitted in the correct way', function(){
			expect(res.graphJson).toEqual(g);
			expect(res.tableJson).toEqual(t);
		});

	});*/

	describe('updateParameters', function(){
		var json = {
			'title' : 'graficonuovo',
			'height' : 400,
			'width' : 400,
			'enabledLegend' : false,
			'horizontalGrid' : false,
			'verticalGrid' : false,
			'rows' : 6,
			'colunms' : 9,
			'headers' : ['ciao','amici'],
			'itemDisplayedPerPage' : 5,
			'addRowOn' : 'top',
			'sortable' : false,
			'appearance' : {
				border: {
					color: '#000000',
					width: 1
				},
				rowEven: {
					textColor: ['#000000', '#000000'],
					backgroundColor: ['#FFFFFF', '#FFFFFF']
				},
				rowOdd: {
					textColor: ['#000000', '#000000'],
					backgroundColor: ['#FFFFFF', '#FFFFFF']
				},
				headers: {
					textColor: ['#000000', '#000000'],
					backgroundColor: ['#FFFFFF', '#FFFFFF']
				}
			},
			'flows' : [{'ID' : 'f1'},{'ID' : 'f2'},{'ID' : 'f3'}]
		};
		var Table;

		beforeEach(function(){
			Table = TableFactory.build();
			Table.updateParameters(json);
		});

		afterEach(function(){
			Table = null;
		});

		it('Table created', function(){
			expect(Table).toBeDefined();
		});

		it('graph updated with the correct headers', function(){
			expect(Table.getHeaders().length).toEqual(2);
		});
		it('graph updated with the correct item displayed per page', function(){
			expect(Table.getMaxItemsPage()).toEqual(20);
		});
		it('graph updated with the correct add data position', function(){
			expect(Table.getAddRowOn()).toEqual('top');
		});
		it('graph updated with the correct sortable', function(){
			expect(Table.getSortable()).toEqual(false);
		});
		it('graph updated with the correct sort', function(){
			expect(Table.getSort()).toEqual(null);
		});
		it('graph updated with the correct appearance', function(){
			expect(Table.getAppearance().border.color).toEqual('#000000');
		});
		it('graph updated with the correct flow', function(){
			expect(Table.getFlowList().length).toEqual(3);
		});

	});

	describe('addFlow', function(){

		var json = {
			'ID' : 	'flusso1',
		};

		var fJson = {
			'name' : 'flusso1',
			'maxItem' : '5'
		};

		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build(fJson);
			Table = TableFactory.build();
			Table.addFlow(json.ID, newFlow);
		});

		afterEach(function(){
			Table = null;
		});

		it('graph addFlow called with the correct parameters', function(){
			expect(Table.getFlowList().length).toEqual(1);
		});

	});

	describe('deleteFlow', function(){

		var json1 = {
			'ID' : 	'flusso1',
			'name' : 'sonda 1'
		};

		var json2 = {
			'ID' : 	'flusso2',
			'name' : 'sonda 2'
		};
		var Table, Flow1, Flow2;

		beforeEach(function(){
			Flow1 = TableFlowFactory.build();
			Flow2 = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(json1.ID, Flow1);
			Table.addFlow(json2.ID, Flow2);
			Table.deleteFlow('flusso1');
		});

		afterEach(function(){
			Flow1 = null;
			Flow2 = null;
			Table = null;
		});

		it('delete flow from graph', function(){
			expect(Table.getFlowList().length).toEqual(1);
		});

	});

	describe('replaceData', function(){

		var json1 = {
			'ID' : 	'flusso1',
			'name' : 'sonda 1',
			'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }, {'NorrisRecordID' : 'record3', 'value' : [4,4] }]
		};

		var json = {
			'ID' : 'flusso1',
			'records' :	[{'NorrisRecordID' : 'record4', 'value' : [5,5] }, {'NorrisRecordID' : 'record5', 'value' : [6,6] }]
		};

		var Table, Flow;

		beforeEach(function(){
			Flow = TableFlowFactory.build();
			Flow.initializeData(json1,'bottom');
			Table = TableFactory.build();
			Table.addFlow(json1.ID, Flow);
			Table.replaceData(json);
		});

		afterEach(function(){
			Flow = null;
			Table = null;
		});

		it('delete flow from graph', function(){
			expect(Table.getFlowList()[0].flow.getData()[0].value[0]).toEqual(5);
			expect(Table.getFlowList()[0].flow.getData()[1].value[0]).toEqual(6);
		});

	});

	describe('inizializeData', function(){

		var data = [
			{
				'ID' : '1',
				'records' : [{ 'NorrisRecordID' : '234321', 'value' : [0,1]},{}]
			}
		];

		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(data[0].ID, newFlow);
			Table.initializeData(data);
		});

		afterEach(function(){
			Table = null;
		});

		it('TableFlow inizializeData called in the right way', function(){
			expect(Table.getFlowList()[0].flow.getData().length).toEqual(2);
		});
	});

	describe('inPlaceUpdate', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];
		var data1 = 	{
			'ID' : '2',
			'NorrisRecordID' : 'record2',
			'value' : [4,4]
		};
		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(data[0].ID, newFlow);
			Table.initializeData(data);
		});

		afterEach(function(){
			Table = null;
		});

		it('TableFlow inPlaceUpdate called in the right way', function(){
			expect(Table.getFlowList()[0].flow.getData()[0].value[0]).toEqual(3);
			Table.inPlaceUpdate(data1);
			expect(Table.getFlowList()[0].flow.getData()[0].value[0]).toEqual(4);
		});
	});

	describe('streamUpdate', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];
		var data1 = 	{
			'ID' : '2',
			'records' : [{
				'NorrisRecordID' : 'record2',
				'value' : [4,4]
			}]
		};
		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(data[0].ID, newFlow);
			Table.initializeData(data);
		});

		afterEach(function(){
			Table = null;
		});

		it('inizialize flowList', function(){
			expect(Table.getFlowList()[0].flow.getData().length).toEqual(1);
			Table.streamUpdate(data1);
			expect(Table.getFlowList()[0].flow.getData().length).toEqual(2);
		});
	});

	describe('deleteData', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];

		var delData = {
			'ID' : '2',
			'NorrisRecordID' : 'record2'
		};

		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(data[0].ID, newFlow);
			Table.initializeData(data, 'bottom');
			Table.deleteData(delData);
		});

		afterEach(function(){
			Table = null;
		});

		it('deleteData in the correct way', function(){
			expect(Table.getFlowList()[0].flow.getData().length).toEqual(0);
		});
	});

});<commit_msg>fix table test<commit_after>/*
* Name :  LineChart.js
* Module : UnitTest
* Location : /frontend/test/unit/Model
*
* History :
* Version       Date        Programmer                  Description
* =================================================================================================
* 0.2.2         2015-05-17  Maria Giovanna Chinellato   Fix code
*
* 0.2.1			2015-05-15	Maria Giovanna Chinellato	Fix test of Model::Table
*
* 0.2.0			2015-05-15	Maria Giovanna Chinellato	Add test of all the methods of LineChart classes
*
* 0.1.0			2015-05-15	Maria Giovanna Chinellato	Add test of Model::Table.js
*
* 0.0.1			2015-05-15	Maria Giovanna Chinellato	Initial code
* =================================================================================================
*
*/

describe('TableFactory', function(){
	'use strict';

	var TableFactory;
	var TableFlowFactory;

	beforeEach(angular.mock.module('norris-nrti'));

	beforeEach(inject(function(_TableFactory_, $injector){
		TableFactory = _TableFactory_;
		TableFlowFactory = $injector.get('TableFlowFactory');
	}));

	describe('Constructor', function(){

		var json = {
			'title' : 'fottutissimografico',
			'socketURL' : 'localhost/page1/grafico1'
		};
		var Table;

		beforeEach(function(){
			Table = TableFactory.build(json);
		});

		afterEach(function(){
			Table = null;
		});

		it('Table created', function(){
			expect(Table).toBeDefined();
		});
		it('graph Constructor called', function(){
			expect(Table.getTitle()).toEqual('fottutissimografico');
		});
		it('graph Constructor called', function(){
			expect(Table.getUrl()).toEqual('localhost/page1/grafico1');
		});
		it('graph created with the correct headers', function(){
			expect(Table.getHeaders()).toEqual([]);
		});
		it('graph created with the correct item displayed per page', function(){
			expect(Table.getMaxItemsPage()).toEqual(20);
		});
		it('graph created with the correct add data position', function(){
			expect(Table.getAddRowOn()).toEqual('top');
		});
		it('graph created with the correct sortable', function(){
			expect(Table.getSortable()).toEqual(true);
		});
		it('graph created with the correct sort', function(){
			expect(Table.getSort()).toEqual(null);
		});
		it('graph created with the correct appearance', function(){
			expect(Table.getAppearance()).toEqual(null);
		});

	});

	/*describe('split', function(){
		var res;
		var json = {};
		var json1 = json;
		json = json1;
		json = {
			'title' : 'grafico',
			'height' : 300,
			'width' : 300,
			'enabledLegend' : true,
			'legend' : {},
			'horizontalGrid' : true,
			'verticalGrid' : true,
			'row' : 5,
			'colunms' : 8,
			'headers' : {},
			'cells' : {},
			'itemDisplayedPerPage' : 4,
			'addDataPosition' : '',
			'sortable' : true
		};
		var g = {
			'title' : 'grafico',
			'height' : 300,
			'width' : 300,
			'enabledLegend' : true,
			'legend' : {},
			'horizontalGrid' : true,
			'verticalGrid' : true
		};
		var t = {
			'row' : 5,
			'colunms' : 8,
			'headers' : {},
			'cells' : {},
			'itemDisplayedPerPage' : 4,
			'addDataPosition' : 'down',
			'sortable' : true
		};

		beforeEach(function(){
			res = Table.Test('split(json)');
		});

		it('json splitted in the correct way', function(){
			expect(res.graphJson).toEqual(g);
			expect(res.tableJson).toEqual(t);
		});

	});*/

	describe('updateParameters', function(){
		var json = {
			'title' : 'graficonuovo',
			'height' : 400,
			'width' : 400,
			'enabledLegend' : false,
			'horizontalGrid' : false,
			'verticalGrid' : false,
			'rows' : 6,
			'colunms' : 9,
			'headers' : ['ciao','amici'],
			'itemDisplayedPerPage' : 5,
			'addRowOn' : 'top',
			'sortable' : false,
			'appearance' : {
				border: {
					color: '#000000',
					width: 1
				},
				rowEven: {
					textColor: ['#000000', '#000000'],
					backgroundColor: ['#FFFFFF', '#FFFFFF']
				},
				rowOdd: {
					textColor: ['#000000', '#000000'],
					backgroundColor: ['#FFFFFF', '#FFFFFF']
				},
				headers: {
					textColor: ['#000000', '#000000'],
					backgroundColor: ['#FFFFFF', '#FFFFFF']
				}
			},
			'flows' : [{'ID' : 'f1'},{'ID' : 'f2'},{'ID' : 'f3'}]
		};
		var Table;

		beforeEach(function(){
			Table = TableFactory.build();
			Table.updateParameters(json);
		});

		afterEach(function(){
			Table = null;
		});

		it('Table created', function(){
			expect(Table).toBeDefined();
		});

		it('graph updated with the correct headers', function(){
			expect(Table.getHeaders().length).toEqual(2);
		});
		it('graph updated with the correct item displayed per page', function(){
			expect(Table.getMaxItemsPage()).toEqual(20);
		});
		it('graph updated with the correct add data position', function(){
			expect(Table.getAddRowOn()).toEqual('top');
		});
		it('graph updated with the correct sortable', function(){
			expect(Table.getSortable()).toEqual(false);
		});
		it('graph updated with the correct sort', function(){
			expect(Table.getSort()).toEqual(null);
		});
		it('graph updated with the correct appearance', function(){
			expect(Table.getAppearance().border.color).toEqual('#000000');
		});
		it('graph updated with the correct flow', function(){
			expect(Table.getFlowList().length).toEqual(3);
		});

	});

	describe('addFlow', function(){

		var json = {
			'ID' : 	'flusso1',
		};

		var fJson = {
			'name' : 'flusso1',
			'maxItem' : '5'
		};

		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build(fJson);
			Table = TableFactory.build();
			Table.addFlow(json.ID, newFlow);
		});

		afterEach(function(){
			Table = null;
		});

		it('graph addFlow called with the correct parameters', function(){
			expect(Table.getFlowList().length).toEqual(1);
		});

	});

	describe('deleteFlow', function(){

		var json1 = {
			'ID' : 	'flusso1',
			'name' : 'sonda 1'
		};

		var json2 = {
			'ID' : 	'flusso2',
			'name' : 'sonda 2'
		};
		var Table, Flow1, Flow2;

		beforeEach(function(){
			Flow1 = TableFlowFactory.build();
			Flow2 = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(json1.ID, Flow1);
			Table.addFlow(json2.ID, Flow2);
			Table.deleteFlow('flusso1');
		});

		afterEach(function(){
			Flow1 = null;
			Flow2 = null;
			Table = null;
		});

		it('delete flow from graph', function(){
			expect(Table.getFlowList().length).toEqual(1);
		});

	});

	describe('replaceData', function(){

		var json1 = {
			'ID' : 	'flusso1',
			'name' : 'sonda 1',
			'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }, {'NorrisRecordID' : 'record3', 'value' : [4,4] }]
		};

		var json = {
			'ID' : 'flusso1',
			'records' :	[{'NorrisRecordID' : 'record4', 'value' : [5,5] }, {'NorrisRecordID' : 'record5', 'value' : [6,6] }]
		};

		var Table, Flow;

		beforeEach(function(){
			Flow = TableFlowFactory.build();
			Flow.initializeData(json1,'bottom');
			Table = TableFactory.build();
			Table.addFlow(json1.ID, Flow);
			Table.replaceData(json);
		});

		afterEach(function(){
			Flow = null;
			Table = null;
		});

		it('delete flow from graph', function(){
			expect(Table.getFlowList()[0].flow.getData()[0].value[0]).toEqual(6);
			expect(Table.getFlowList()[0].flow.getData()[1].value[0]).toEqual(5);
		});

	});

	describe('inizializeData', function(){

		var data = [
			{
				'ID' : '1',
				'records' : [{ 'NorrisRecordID' : '234321', 'value' : [0,1]},{}]
			}
		];

		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(data[0].ID, newFlow);
			Table.initializeData(data);
		});

		afterEach(function(){
			Table = null;
		});

		it('TableFlow inizializeData called in the right way', function(){
			expect(Table.getFlowList()[0].flow.getData().length).toEqual(2);
		});
	});

	describe('inPlaceUpdate', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];
		var data1 = 	{
			'ID' : '2',
			'NorrisRecordID' : 'record2',
			'value' : [4,4]
		};
		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(data[0].ID, newFlow);
			Table.initializeData(data);
		});

		afterEach(function(){
			Table = null;
		});

		it('TableFlow inPlaceUpdate called in the right way', function(){
			expect(Table.getFlowList()[0].flow.getData()[0].value[0]).toEqual(3);
			Table.inPlaceUpdate(data1);
			expect(Table.getFlowList()[0].flow.getData()[0].value[0]).toEqual(4);
		});
	});

	describe('streamUpdate', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];
		var data1 = 	{
			'ID' : '2',
			'records' : [{
				'NorrisRecordID' : 'record2',
				'value' : [4,4]
			}]
		};
		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(data[0].ID, newFlow);
			Table.initializeData(data);
		});

		afterEach(function(){
			Table = null;
		});

		it('inizialize flowList', function(){
			expect(Table.getFlowList()[0].flow.getData().length).toEqual(1);
			Table.streamUpdate(data1);
			expect(Table.getFlowList()[0].flow.getData().length).toEqual(2);
		});
	});

	describe('deleteData', function(){

		var data = [
			{
				'ID' : '2',
				'records' : [{'NorrisRecordID' : 'record2', 'value' : [3,3] }]
			}
		];

		var delData = {
			'ID' : '2',
			'NorrisRecordID' : 'record2'
		};

		var newFlow;
		var Table;

		beforeEach(function(){
			newFlow = TableFlowFactory.build();
			Table = TableFactory.build();
			Table.addFlow(data[0].ID, newFlow);
			Table.initializeData(data, 'bottom');
			Table.deleteData(delData);
		});

		afterEach(function(){
			Table = null;
		});

		it('deleteData in the correct way', function(){
			expect(Table.getFlowList()[0].flow.getData().length).toEqual(0);
		});
	});

});<|endoftext|>