<commit_before>/*global define*/
/*global describe, it, expect*/
/*global jasmine*/
/*global beforeEach, afterEach*/
/*jslint white: true*/
define([
    'jquery',
    'kbaseNarrativeOutputCell',
    'base/js/namespace',
    'kbaseNarrative',
    'common/runtime',
    'narrativeConfig'
], function(
    $,
    Widget,
    Jupyter,
    Narrative,
    Runtime,
    Config
) {
    'use strict';
    describe('Test the kbaseNarrativeOutputCell widget', function() {
        var currentWsId = 10,
            testWidget = 'kbaseDefaultNarrativeOutput',
            testUpas = {
                'test': '3/4/5',
                'testList': ['1/2/3', '6/7/8']
            },
            serialUpas = {
                'test': '[3]/4/5',
                'testList': ['[1]/2/3', '[6]/7/8']
            },
            deserialUpas = {
                'test': '10/4/5',
                'testList': ['10/2/3', '10/7/8']
            },
            testData = { 'foo': 'bar', 'baz': [1, 2, 3] },
            $target = $('<div>'),
            cellId = 'a-cell-id',
            myWidget = null;

        var validateUpas = function(source, comparison) {
            Object.keys(comparison).forEach(function(upaKey) {
                if (typeof comparison[upaKey] === 'string') {
                    expect(source[upaKey]).toEqual(comparison[upaKey]);
                }
                else { // it better be a list
                    comparison[upaKey].forEach(function(upa) {
                        expect(source[upaKey].indexOf(upa)).toBeGreaterThan(-1);
                    });
                }
            });
        };

        beforeEach(function() {
            // beforeEach(function () {
            history.pushState(null, null, '/narrative/ws.10.obj.1');
            Config.config.workspaceId = 10;
            // });
            Jupyter.narrative = new Narrative();
            $('body').append($('<div id="notebook-container">').append($target));
            myWidget = new Widget($target, {
                widget: testWidget,
                data: testData,
                type: 'viewer',
                upas: testUpas
            });
            myWidget.cell = {};
            myWidget.metadata = myWidget.initMetadata();
        });

        afterEach(function() {
            $('body').empty();
            $target = $('<div>');
        });

        it('Should load properly with a dummy UPA', function() {
            expect(myWidget).not.toBeNull();
        });

        it('Should serialize UPA info properly', function() {
            myWidget.handleUpas();
            var serialized = myWidget.cell.metadata.kbase.dataCell.upas;
            validateUpas(serialUpas, serialized);
        });

        // skip until we get better notebook support.
        xit('Should attach a widget using a pre-existing cell id', function() {
            var $newDiv = $('<div id="' + cellId  + '">');
            $('#notebook-container').append($newDiv);<commit_msg>remove extra "beforeEach" lines<commit_after>/*global define*/
/*global describe, it, expect*/
/*global jasmine*/
/*global beforeEach, afterEach*/
/*jslint white: true*/
define([
    'jquery',
    'kbaseNarrativeOutputCell',
    'base/js/namespace',
    'kbaseNarrative',
    'common/runtime',
    'narrativeConfig'
], function(
    $,
    Widget,
    Jupyter,
    Narrative,
    Runtime,
    Config
) {
    'use strict';
    describe('Test the kbaseNarrativeOutputCell widget', function() {
        var currentWsId = 10,
            testWidget = 'kbaseDefaultNarrativeOutput',
            testUpas = {
                'test': '3/4/5',
                'testList': ['1/2/3', '6/7/8']
            },
            serialUpas = {
                'test': '[3]/4/5',
                'testList': ['[1]/2/3', '[6]/7/8']
            },
            deserialUpas = {
                'test': '10/4/5',
                'testList': ['10/2/3', '10/7/8']
            },
            testData = { 'foo': 'bar', 'baz': [1, 2, 3] },
            $target = $('<div>'),
            cellId = 'a-cell-id',
            myWidget = null;

        var validateUpas = function(source, comparison) {
            Object.keys(comparison).forEach(function(upaKey) {
                if (typeof comparison[upaKey] === 'string') {
                    expect(source[upaKey]).toEqual(comparison[upaKey]);
                }
                else { // it better be a list
                    comparison[upaKey].forEach(function(upa) {
                        expect(source[upaKey].indexOf(upa)).toBeGreaterThan(-1);
                    });
                }
            });
        };

        beforeEach(function() {
            history.pushState(null, null, '/narrative/ws.10.obj.1');
            Config.config.workspaceId = 10;
            Jupyter.narrative = new Narrative();
            $('body').append($('<div id="notebook-container">').append($target));
            myWidget = new Widget($target, {
                widget: testWidget,
                data: testData,
                type: 'viewer',
                upas: testUpas
            });
            myWidget.cell = {};
            myWidget.metadata = myWidget.initMetadata();
        });

        afterEach(function() {
            $('body').empty();
            $target = $('<div>');
        });

        it('Should load properly with a dummy UPA', function() {
            expect(myWidget).not.toBeNull();
        });

        it('Should serialize UPA info properly', function() {
            myWidget.handleUpas();
            var serialized = myWidget.cell.metadata.kbase.dataCell.upas;
            validateUpas(serialUpas, serialized);
        });

        // skip until we get better notebook support.
        xit('Should attach a widget using a pre-existing cell id', function() {
            var $newDiv = $('<div id="' + cellId  + '">');
            $('#notebook-container').append($newDiv);
{'fraction_non_alphanumeric': 0.15469519443029378, 'fraction_numerical': 0.013924265579894719, 'mean_word_length': 1.5992939099735217, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4229212', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1663, 'n_words': 325}