Best JavaScript code snippet using wpt
contextMenus.js
Source:contextMenus.js
2{3/*------------- MODULE newsletter ----------------*/4 $('span.newsletter_rootfolder').contextMenu('newsletter_rootfolder', {5 bindings: {6 'createNewsletter': function(t) {createDocument('Newsletter', t.id);},7 'createFolder': function(t) {createDocument('Folder', t.id);}8 }9 });10 $('span.newsletter_folder').contextMenu('newsletter_folder', {11 bindings: {12 'createMailinglist': function(t) {createDocument('Mailinglist', t.id);},13 'deleteDocument': function(t) {deleteDocument(t.id);},14 'editDocument': function(t) {editDocument('Folder', t.id);},15 'orderDocumentUp': function(t) {orderDocument(t.id,true);},16 'orderDocumentDown': function(t) {orderDocument(t.id,false);}17 }18 });19 $('span.newsletter_mailinglist').contextMenu('newsletter_mailinglist', {20 bindings: {21 'createSubscriber': function(t) {createDocument('Subscriber', t.id);},22 'deleteDocument': function(t) {deleteDocument(t.id);},23 'editDocument': function(t) {editDocument('Mailinglist', t.id);},24 'orderDocumentUp': function(t) {orderDocument(t.id,true);},25 'orderDocumentDown': function(t) {orderDocument(t.id,false);}26 }27 });28 $('span.newsletter_newsletter').contextMenu('newsletter_newsletter', {29 bindings: {30 'deleteDocument': function(t) {deleteDocument(t.id);},31 'editDocument': function(t) {editDocument('Newsletter', t.id);},32 'orderDocumentUp': function(t) {orderDocument(t.id,true);},33 'orderDocumentDown': function(t) {orderDocument(t.id,false);}34 }35 });36 $('span.newsletter_subscriber').contextMenu('newsletter_subscriber', {37 bindings: {38 'deleteDocument': function(t) {deleteDocument(t.id);},39 'editDocument': function(t) {editDocument('Subscriber', t.id);},40 'orderDocumentUp': function(t) {orderDocument(t.id,true);},41 'orderDocumentDown': function(t) {orderDocument(t.id,false);}42 }43 });44/*------------- MODULE website ----------------*/45 $('span.website_rootfolder').contextMenu('website_rootfolder', {46 bindings: {47 'createWebsite': function(t) {createDocument('Website', t.id);}48 }49 });50 $('span.website_website').contextMenu('website_website', {51 bindings: {52 'createMenu': function(t) {createDocument('Menu', t.id);},53 'createTopic': function(t) {createDocument('Topic', t.id);},54 'createPage': function(t) {createDocument('Page', t.id);},55 'deleteDocument': function(t) {deleteDocument(t.id);},56 'editDocument': function(t) {editDocument('Website', t.id);},57 'orderDocumentUp': function(t) {orderDocument(t.id,true);},58 'orderDocumentDown': function(t) {orderDocument(t.id,false);}59 }60 });61 $('span.website_menu').contextMenu('website_menu', {62 bindings: {63 'createTopic': function(t) {createDocument('Topic', t.id);},64 'createPage': function(t) {createDocument('Page', t.id);},65 'deleteDocument': function(t) {deleteDocument(t.id);},66 'editDocument': function(t) {editDocument('Menu', t.id);},67 'orderDocumentUp': function(t) {orderDocument(t.id,true);},68 'orderDocumentDown': function(t) {orderDocument(t.id,false);}69 }70 });71 $('span.website_topic').contextMenu('website_topic', {72 bindings: {73 'createTopicI18n': function(t) {createDocument('TopicI18n', t.id);},74 'createTopic': function(t) {createDocument('Topic', t.id);},75 'createPage': function(t) {createDocument('Page', t.id);},76 'deleteDocument': function(t) {deleteDocument(t.id);},77 'editDocument': function(t) {editDocument('Topic', t.id);},78 'orderDocumentUp': function(t) {orderDocument(t.id,true);},79 'orderDocumentDown': function(t) {orderDocument(t.id,false);}80 }81 });82 $('span.website_page').contextMenu('website_page', {83 bindings: {84 'createPageI18n': function(t) {createDocument('PageI18n', t.id);},85 'deleteDocument': function(t) {deleteDocument(t.id);},86 'editDocument': function(t) {editDocument('Page', t.id);},87 'orderDocumentUp': function(t) {orderDocument(t.id,true);},88 'orderDocumentDown': function(t) {orderDocument(t.id,false);}89 }90 });91 $('span.website_pagei18n').contextMenu('website_pagei18n', {92 bindings: {93 'deleteDocument': function(t) {deleteDocument(t.id);},94 'editDocument': function(t) {editDocument('PageI18n', t.id);}95 }96 });97 $('span.website_folder').contextMenu('website_folder', {98 bindings: {99 'deleteDocument': function(t) {deleteDocument(t.id);},100 'editDocument': function(t) {editDocument('Folder', t.id);},101 'orderDocumentUp': function(t) {orderDocument(t.id,true);},102 'orderDocumentDown': function(t) {orderDocument(t.id,false);}103 }104 });105/*------------- MODULE tag ----------------*/106 $('span.tag_rootfolder').contextMenu('tag_rootfolder', {107 bindings: {108 'createFolder': function(t) {createDocument('Folder', t.id);},109 'createTag': function(t) {createDocument('Tag', t.id);}110 }111 });112 $('span.tag_folder').contextMenu('tag_folder', {113 bindings: {114 'createFolder': function(t) {createDocument('Folder', t.id);},115 'createTag': function(t) {createDocument('Tag', t.id);},116 'deleteDocument': function(t) {deleteDocument(t.id);},117 'editDocument': function(t) {editDocument('Folder', t.id);},118 'orderDocumentUp': function(t) {orderDocument(t.id,true);},119 'orderDocumentDown': function(t) {orderDocument(t.id,false);}120 }121 });122 $('span.tag_tag').contextMenu('tag_tag', {123 bindings: {124 'deleteDocument': function(t) {deleteDocument(t.id);},125 'editDocument': function(t) {editDocument('Tag', t.id);},126 'orderDocumentUp': function(t) {orderDocument(t.id,true);},127 'orderDocumentDown': function(t) {orderDocument(t.id,false);}128 }129 });130 $('span.tag_user').contextMenu('tag_user', {131 bindings: {132 'deleteDocument': function(t) {deleteDocument(t.id);},133 'editDocument': function(t) {editDocument('User', t.id);},134 'orderDocumentUp': function(t) {orderDocument(t.id,true);},135 'orderDocumentDown': function(t) {orderDocument(t.id,false);}136 }137 });138/*------------- MODULE products ----------------*/139 $('span.products_rootfolder').contextMenu('products_rootfolder', {140 bindings: {141 'createCategory': function(t) {createDocument('Category', t.id);}142 }143 });144 $('span.products_category').contextMenu('products_category', {145 bindings: {146 'createProduct': function(t) {createDocument('Product', t.id);},147 'createCategoryI18n': function(t) {createDocument('CategoryI18n', t.id);},148 'deleteDocument': function(t) {deleteDocument(t.id);},149 'editDocument': function(t) {editDocument('Category', t.id);},150 'orderDocumentUp': function(t) {orderDocument(t.id,true);},151 'orderDocumentDown': function(t) {orderDocument(t.id,false);}152 }153 });154 $('span.products_product').contextMenu('products_product', {155 bindings: {156 'createProductI18n': function(t) {createDocument('ProductI18n', t.id);},157 'deleteDocument': function(t) {deleteDocument(t.id);},158 'editDocument': function(t) {editDocument('Product', t.id);},159 'orderDocumentUp': function(t) {orderDocument(t.id,true);},160 'orderDocumentDown': function(t) {orderDocument(t.id,false);}161 }162 });163/*------------- MODULE services ----------------*/164 $('span.services_rootfolder').contextMenu('services_rootfolder', {165 bindings: {166 'createServiceCategory': function(t) {createDocument('ServiceCategory', t.id);}167 }168 });169 $('span.services_servicecategory').contextMenu('services_servicecategory', {170 bindings: {171 'createService': function(t) {createDocument('Service', t.id);},172 'deleteDocument': function(t) {deleteDocument(t.id);},173 'editDocument': function(t) {editDocument('ServiceCategory', t.id);},174 'orderDocumentUp': function(t) {orderDocument(t.id,true);},175 'orderDocumentDown': function(t) {orderDocument(t.id,false);}176 }177 });178 $('span.services_service').contextMenu('services_service', {179 bindings: {180 'deleteDocument': function(t) {deleteDocument(t.id);},181 'editDocument': function(t) {editDocument('Service', t.id);},182 'orderDocumentUp': function(t) {orderDocument(t.id,true);},183 'orderDocumentDown': function(t) {orderDocument(t.id,false);}184 }185 });186/*------------- MODULE keywords ----------------*/187 $('span.keywords_rootfolder').contextMenu('keywords_rootfolder', {188 bindings: {189 'createKeyword': function(t) {createDocument('Keyword', t.id);}190 }191 });192 $('span.keywords_keyword').contextMenu('keywords_keyword', {193 bindings: {194 'deleteDocument': function(t) {deleteDocument(t.id);},195 'editDocument': function(t) {editDocument('Keyword', t.id);},196 'orderDocumentUp': function(t) {orderDocument(t.id,true);},197 'orderDocumentDown': function(t) {orderDocument(t.id,false);}198 }199 });200/*------------- MODULE user ----------------*/201 $('span.user_rootfolder').contextMenu('user_rootfolder', {202 bindings: {203 'createFolder': function(t) {createDocument('Folder', t.id);},204 'createUser': function(t) {createDocument('User', t.id);}205 }206 });207 $('span.user_folder').contextMenu('user_folder', {208 bindings: {209 'createFolder': function(t) {createDocument('Folder', t.id);},210 'createUser': function(t) {createDocument('User', t.id);},211 'deleteDocument': function(t) {deleteDocument(t.id);},212 'editDocument': function(t) {editDocument('Folder', t.id);},213 'orderDocumentUp': function(t) {orderDocument(t.id,true);},214 'orderDocumentDown': function(t) {orderDocument(t.id,false);}215 }216 });217 $('span.user_user').contextMenu('user_user', {218 bindings: {219 'createWishList': function(t) {createDocument('WishList', t.id);},220 'deleteDocument': function(t) {deleteDocument(t.id);},221 'editDocument': function(t) {editDocument('User', t.id);},222 'orderDocumentUp': function(t) {orderDocument(t.id,true);},223 'orderDocumentDown': function(t) {orderDocument(t.id,false);}224 }225 });226 $('span.user_wishlist').contextMenu('user_wishlist', {227 bindings: {228 'deleteDocument': function(t) {deleteDocument(t.id);},229 'editDocument': function(t) {editDocument('WishList', t.id);},230 'orderDocumentUp': function(t) {orderDocument(t.id,true);},231 'orderDocumentDown': function(t) {orderDocument(t.id,false);}232 }233 });234/*------------- MODULE media ----------------*/235 $('span.media_rootfolder').contextMenu('media_rootfolder', {236 bindings: {237 'createFolder': function(t) {createDocument('Folder', t.id);},238 'createMedia': function(t) {createDocument('Media', t.id);}239 }240 });241 $('span.media_folder').contextMenu('media_folder', {242 bindings: {243 'createFolder': function(t) {createDocument('Folder', t.id);},244 'createMedia': function(t) {createDocument('Media', t.id);},245 'deleteDocument': function(t) {deleteDocument(t.id);},246 'editDocument': function(t) {editDocument('Folder', t.id);},247 'orderDocumentUp': function(t) {orderDocument(t.id,true);},248 'orderDocumentDown': function(t) {orderDocument(t.id,false);}249 }250 });251 $('span.media_media').contextMenu('media_media', {252 bindings: {253 'deleteDocument': function(t) {deleteDocument(t.id);},254 'editDocument': function(t) {editDocument('Media', t.id);},255 'orderDocumentUp': function(t) {orderDocument(t.id,true);},256 'orderDocumentDown': function(t) {orderDocument(t.id,false);}257 }258 });259/*------------- MODULE news ----------------*/260 $('span.news_rootfolder').contextMenu('news_rootfolder', {261 bindings: {262 'createFolder': function(t) {createDocument('Folder', t.id);},263 'createNews': function(t) {createDocument('News', t.id);}264 }265 });266 $('span.news_folder').contextMenu('news_folder', {267 bindings: {268 'createFolder': function(t) {createDocument('Folder', t.id);},269 'createNews': function(t) {createDocument('News', t.id);},270 'deleteDocument': function(t) {deleteDocument(t.id);},271 'editDocument': function(t) {editDocument('Folder', t.id);},272 'orderDocumentUp': function(t) {orderDocument(t.id,true);},273 'orderDocumentDown': function(t) {orderDocument(t.id,false);}274 }275 });276 $('span.news_news').contextMenu('news_news', {277 bindings: {278 'createNewsI18n': function(t) {createDocument('NewsI18n', t.id);},279 'deleteDocument': function(t) {deleteDocument(t.id);},280 'editDocument': function(t) {editDocument('News', t.id);},281 'orderDocumentUp': function(t) {orderDocument(t.id,true);},282 'orderDocumentDown': function(t) {orderDocument(t.id,false);}283 }284 });285/*------------- MODULE lists ----------------*/286 $('span.lists_rootfolder').contextMenu('lists_rootfolder', {287 bindings: {288 'createLists': function(t) {createDocument('Lists', t.id);}289 }290 });291 $('span.lists_lists').contextMenu('lists_lists', {292 bindings: {293 'createListitem': function(t) {createDocument('Listitem', t.id);},294 'deleteDocument': function(t) {deleteDocument(t.id);},295 'editDocument': function(t) {editDocument('Lists', t.id);},296 'orderDocumentUp': function(t) {orderDocument(t.id,true);},297 'orderDocumentDown': function(t) {orderDocument(t.id,false);}298 }299 });300 $('span.lists_listitem').contextMenu('lists_listitem', {301 bindings: {302 'createListitemI18n': function(t) {createDocument('ListitemI18n', t.id);},303 'deleteDocument': function(t) {deleteDocument(t.id);},304 'editDocument': function(t) {editDocument('Listitem', t.id);},305 'orderDocumentUp': function(t) {orderDocument(t.id,true);},306 'orderDocumentDown': function(t) {orderDocument(t.id,false);}307 }308 });309 $('span.lists_listitemi18n').contextMenu('lists_listitemi18n', {310 bindings: {311 'deleteDocument': function(t) {deleteDocument(t.id);},312 'editDocument': function(t) {editDocument('ListitemI18n', t.id);},313 'orderDocumentUp': function(t) {orderDocument(t.id,true);},314 'orderDocumentDown': function(t) {orderDocument(t.id,false);}315 }316 });...
create-document.js
Source:create-document.js
1var H5P = H5P || {};2H5P.DocumentExportPage = H5P.DocumentExportPage || {};3/**4 * Create Document module5 * @external {jQuery} $ H5P.jQuery6 */7H5P.DocumentExportPage.CreateDocument = (function ($, ExportPage, EventDispatcher) {8 /**9 * Initialize module.10 * @param {Array} inputFields Array of input strings that should be exported11 * @returns {Object} CreateDocument CreateDocument instance12 */13 function CreateDocument(params, title, submitEnabled, inputFields, inputGoals, template) {14 EventDispatcher.call(this);15 this.inputFields = inputFields;16 this.inputGoals = inputGoals;17 this.template = template;18 this.params = params;19 this.title = title;20 this.submitEnabled = submitEnabled;21 }22 // Setting up inheritance23 CreateDocument.prototype = Object.create(EventDispatcher.prototype);24 CreateDocument.prototype.constructor = CreateDocument;25 /**26 * Attach function called by H5P framework to insert H5P content into page.27 *28 * @param {jQuery} $container The container which will be appended to.29 */30 CreateDocument.prototype.attach = function ($container) {31 var self = this;32 var exportString = this.getExportString();33 exportString += this.createGoalsOutput() || '';34 var exportObject = this.getExportObject();35 var exportPage = new ExportPage(this.title,36 exportString,37 this.submitEnabled,38 this.params.submitTextLabel,39 this.params.submitSuccessTextLabel,40 this.params.selectAllTextLabel,41 this.params.exportTextLabel,42 this.template,43 exportObject44 );45 exportPage.getElement().prependTo($container);46 exportPage.focus();47 exportPage.on('closed', function () {48 self.trigger('export-page-closed');49 });50 exportPage.on('submitted', function (event) {51 self.trigger('submitted', event.data);52 });53 };54 /**55 * Generate export object that will be applied to the export template56 * @returns {Object} exportObject Exportable content for filling template57 */58 CreateDocument.prototype.getExportObject = function () {59 var sortedGoalsList = [];60 this.inputGoals.inputArray.forEach(function (inputGoalPage) {61 inputGoalPage.forEach(function (inputGoal) {62 // Do not include unassessed goals63 if (inputGoal.goalAnswer() === -1) {64 return;65 }66 var goalCategoryExists = false;67 var listIndex = -1;68 sortedGoalsList.forEach(function (sortedGoalEntry, entryIndex) {69 if (inputGoal.goalAnswer() === sortedGoalEntry.goalAnswer) {70 listIndex = entryIndex;71 goalCategoryExists = true;72 }73 });74 if (!goalCategoryExists) {75 sortedGoalsList.push({label: '', goalArray: [], goalAnswer: inputGoal.goalAnswer()});76 listIndex = sortedGoalsList.length - 1;77 if (inputGoal.getTextualAnswer().length) {78 sortedGoalsList[listIndex].label = inputGoal.getTextualAnswer();79 }80 }81 if (inputGoal.goalText().length && inputGoal.getTextualAnswer().length) {82 sortedGoalsList[listIndex].goalArray.push({text: inputGoal.goalText()});83 }84 });85 });86 var flatInputsList = [];87 this.inputFields.forEach(function (inputFieldPage) {88 if (inputFieldPage.inputArray && inputFieldPage.inputArray.length) {89 var standardPage = {title: '', inputArray: []};90 if (inputFieldPage.title) {91 standardPage.title = inputFieldPage.title;92 }93 inputFieldPage.inputArray.forEach(function (inputField) {94 standardPage.inputArray.push({description: inputField.description, value: inputField.value});95 });96 flatInputsList.push(standardPage);97 }98 });99 var exportObject = {100 title: this.title,101 goalsTitle: this.inputGoals.title,102 flatInputList: flatInputsList,103 sortedGoalsList: sortedGoalsList104 };105 return exportObject;106 };107 /**108 * Generate complete html string for export109 * @returns {string} exportString Html string for export110 */111 CreateDocument.prototype.getExportString = function () {112 var self = this;113 var exportString = self.getInputBlocksString();114 return exportString;115 };116 /**117 * Generates html string for input fields118 * @returns {string} inputBlocksString Html string from input fields119 */120 CreateDocument.prototype.getInputBlocksString = function () {121 var inputBlocksString = '<div class="textfields-output">';122 this.inputFields.forEach(function (inputPage) {123 if (inputPage.inputArray && inputPage.inputArray.length && inputPage.title.length) {124 inputBlocksString +=125 '<h2>' + inputPage.title + '</h2>';126 }127 if (inputPage.inputArray && inputPage.inputArray.length) {128 inputPage.inputArray.forEach(function (inputInstance) {129 if (inputInstance) {130 // remove paragraph tags131 inputBlocksString +=132 '<p>' +133 (inputInstance.description ? '<strong>' + inputInstance.description + '</strong>\n' : '') +134 inputInstance.value +135 '</p>';136 }137 });138 }139 });140 inputBlocksString += '</div>';141 return inputBlocksString;142 };143 /**144 * Generates html string for all goals145 * @returns {string} goalsOutputString Html string from all goals146 */147 CreateDocument.prototype.createGoalsOutput = function () {148 var goalsOutputString = '<div class="goals-output">';149 if (this.inputGoals === undefined || !this.inputGoals.inputArray || this.inputGoals.inputArray.length === 0) {150 return;151 }152 if (this.inputGoals.title.length) {153 goalsOutputString +=154 '<h2>' + this.inputGoals.title + '</h2>';155 }156 this.inputGoals.inputArray.forEach(function (inputGoalPage) {157 var goalOutputArray = [];158 inputGoalPage.forEach(function (inputGoalInstance) {159 if (inputGoalInstance !== undefined && inputGoalInstance.goalAnswer() > -1) {160 // Sort goals on answer161 var htmlString = '';162 if (goalOutputArray[inputGoalInstance.goalAnswer()] === undefined) {163 goalOutputArray[inputGoalInstance.goalAnswer()] = [];164 var answerStringTitle = '<p class="category"><strong>' + inputGoalInstance.getTextualAnswer() + ':</strong></p><ul>';165 goalOutputArray[inputGoalInstance.goalAnswer()].push(answerStringTitle);166 }167 htmlString += '<li>' + inputGoalInstance.text + '</li>';168 goalOutputArray[inputGoalInstance.goalAnswer()].push(htmlString);169 }170 });171 goalOutputArray.forEach(function (goalOutput) {172 goalOutput.forEach(function (goalString) {173 goalsOutputString += goalString;174 });175 if (goalOutput.length) {176 goalsOutputString += '</ul>';177 }178 });179 });180 goalsOutputString += '</div>';181 return goalsOutputString;182 };183 return CreateDocument;...
CreateDocument-test.js
Source:CreateDocument-test.js
1(function() {2 'use strict';3 var expect = require('chai').expect;4 var enzyme = require('enzyme');5 var sinon = require('sinon');6 var DocumentStore = require('../../../../app/scripts/stores/DocumentStore');7 var DocumentActions = require('../../../../app/scripts/actions/DocumentActions');8 var React = require('react');9 var CreateDocument = require('../../../../app/scripts/components/DocumentCreate/CreateDocument.jsx');10 var browserHistory = require('react-router').browserHistory;11 describe('CreateDocument component', function() {12 window.Materialize = {};13 before(function() {14 window.Materialize.toast = sinon.spy();15 // var storage = sinon.stub(localStorage, 'removeItem');16 // storage.withArgs('user').returns(true);17 // storage.withArgs('x-access-token').returns(true);18 });19 it('renders the CreateDocument component', function() {20 // Render CreateDocument component in the document21 var createDocument = enzyme.shallow(<CreateDocument />);22 // Test the orgs state23 expect(createDocument.state().document.title).to.eql(null);24 expect(createDocument.state().document.genre).to.eql(null);25 expect(createDocument.state().user).to.eql(false);26 expect(createDocument.state().staff).to.eql(false);27 });28 it('renders the correct content', function() {29 var createDocument = enzyme.mount(<CreateDocument />);30 expect(createDocument.text()).to.have.string('Title');31 expect(createDocument.text()).to.have.string('Genre');32 expect(createDocument.text()).to.have.string('Content');33 expect(createDocument.text()).to.have.string('Create Document');34 });35 it('renders the correct component', function() {36 expect(enzyme.mount(<CreateDocument />).find('.teal-text').length).to.eql(3);37 expect(enzyme.mount(<CreateDocument />).find('form').length).to.eql(1);38 });39 it('calls componentDidMount', function() {40 sinon.spy(CreateDocument.prototype, 'componentDidMount');41 enzyme.mount(<CreateDocument />); // Mount the component42 expect(CreateDocument.prototype.componentDidMount.calledOnce).to.eql(true);43 CreateDocument.prototype.componentDidMount.restore();44 });45 it('calls componentWillUnmount', function() {46 sinon.spy(CreateDocument.prototype, 'componentWillUnmount');47 var createDocument = enzyme.mount(<CreateDocument />); // Mount the component48 createDocument.unmount();49 expect(CreateDocument.prototype.componentWillUnmount.calledOnce).to.eql(true);50 CreateDocument.prototype.componentWillUnmount.restore();51 });52 it('calls registered callbacks on mount', function() {53 sinon.spy(DocumentStore, 'addChangeListener');54 enzyme.mount(<CreateDocument />); // Mount the component55 expect(DocumentStore.addChangeListener.callCount).to.eql(1);56 DocumentStore.addChangeListener.restore();57 });58 it('should correctly handle field change', function() {59 var createDocument = enzyme.mount(<CreateDocument />);60 var event = {61 target: {62 name: 'genre',63 value: 'katniss'64 },65 preventDefault: function() {}66 };67 var instance = createDocument.instance();68 sinon.spy(instance, 'handleFieldChange');69 instance.handleFieldChange(event);70 expect(createDocument.state().document[event.target.name]).to.eql(event.target.value);71 instance.handleFieldChange.restore();72 });73 it('should correctly handles role select', function() {74 var createDocument = enzyme.mount(<CreateDocument />);75 var event = {76 target: {77 name: 'user'78 },79 };80 var instance = createDocument.instance();81 sinon.spy(instance, 'handleRoleSelect');82 instance.handleRoleSelect(event);83 expect(createDocument.state().user).to.eql(true);84 instance.handleRoleSelect.restore();85 });86 it('calls the document change listener', function() {87 sinon.spy(DocumentStore, 'getCreatedDocument');88 sinon.stub(browserHistory, 'push').returns(true);89 enzyme.mount(<CreateDocument />); // Mount the component90 // Trigger a change in the DocumentStore91 DocumentStore.setCreatedDocument({92 message: 'Document created successfully.',93 doc: {_id: 1} });94 // The getCreatedDocument function should be called95 expect(DocumentStore.getCreatedDocument.called).to.eql(true);96 DocumentStore.getCreatedDocument.restore();97 browserHistory.push.restore();98 });99 it('responds correctly if the document was created successfully', function() {100 sinon.stub(browserHistory, 'push').returns(true);101 var createDocument = enzyme.mount(<CreateDocument />);102 // Trigger a change in the DocumentStore103 DocumentStore.setCreatedDocument({104 message: 'Document created successfully.',105 doc: {_id: 1} });106 expect(DocumentStore.getCreatedDocument()).to.be.an('object');107 expect(createDocument.state().result).to.be.a('string');108 expect(createDocument.state().result).to.eql('Success!');109 browserHistory.push.restore();110 });111 it('responds correctly if the response has an error', function() {112 var createDocument = enzyme.mount(<CreateDocument />);113 // Trigger a change in the DocumentStore114 createDocument.setState({ title: 'title' })115 DocumentStore.setCreatedDocument({116 code: 11000,117 errmsg: 'Duplicate title'118 });119 expect(DocumentStore.getCreatedDocument()).to.be.an('object');120 expect(createDocument.state().result).to.be.a('string');121 expect(createDocument.state().result).to.eql('Failed!');122 });123 it('should call the create document action on click', function() {124 var mockEvent = {125 preventDefault: function() {}126 };127 sinon.stub(DocumentActions, 'createDocument').returns(true);128 sinon.spy(mockEvent, 'preventDefault');129 var createDocument = enzyme.mount(<CreateDocument />);130 createDocument.setState({131 document: {132 title: 'A time to kill',133 genre: 'crime',134 content: 'There was a lot of murder'135 },136 user: true,137 staff: true,138 })139 var inst = createDocument.instance();140 sinon.spy(inst, 'onSubmit');141 createDocument.find('#submit').simulate('click', mockEvent);142 expect(mockEvent.preventDefault.called).to.eql(true);143 expect(DocumentActions.createDocument.called).to.eql(true);144 });145 });...
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.createDocument(function(err, doc) {4 if(err) {5 console.log(err);6 } else {7 console.log(doc);8 }9});10var wptools = require('wptools');11var page = wptools.page('Albert Einstein');12page.createDocument(function(err, doc) {13 if(err) {14 console.log(err);15 } else {16 console.log(doc);17 }18});19var wptools = require('wptools');20var page = wptools.page('Albert Einstein');21page.createDocument(function(err, doc) {22 if(err) {23 console.log(err);24 } else {25 console.log(doc);26 }27});28var wptools = require('wptools');29var page = wptools.page('Albert Einstein');30page.createDocument(function(err, doc) {31 if(err) {32 console.log(err);33 } else {34 console.log(doc);35 }36});37var wptools = require('wptools');38var page = wptools.page('Albert Einstein');39page.createDocument(function(err, doc) {40 if(err) {41 console.log(err);42 } else {43 console.log(doc);44 }45});46var wptools = require('wptools');47var page = wptools.page('Albert Einstein');48page.createDocument(function(err, doc) {49 if(err) {50 console.log(err);51 } else {52 console.log(doc);53 }54});55var wptools = require('wptools');56var page = wptools.page('Albert Einstein');57page.createDocument(function(err, doc) {58 if(err) {59 console.log(err);60 } else {61 console.log(doc);62 }63});
Using AI Code Generation
1var wptools = require('wptools');2wp.get(function(err, data) {3 console.log(data);4});5{6 "content": "Barack Hussein Obama II (born August 4, 1961) is an American politician who served as the 44th President of the United States from 2009 to 2017. A member of the Democratic Party, he was the first African-American president of the United States. He previously served as a United States Senator from Illinois from 2005 to 2008 and served as an Illinois state senator from 1997 to 2004. Obama is a graduate of Columbia University and Harvard Law School, where he was the first black president of the Harvard Law Review. He was a community organizer in Chicago before earning his law degree. He worked as a civil rights attorney and taught constitutional law at the University of Chicago Law School from 1992 to 2004. He served three terms representing the 13th District in the Illinois Senate from 1997 to 2004, when he ran for the United States Senate. He was elected to the Senate in 2004, winning 70 percent of the vote. He was re-elected in 2010 with 70 percent of the vote and in 2016 with 73 percent of the vote. He is married to Michelle Obama and has two daughters.",
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Wikipedia');4page.createDocument(function(err, doc){5 if(err){6 console.log(err);7 }8 else{9 console.log(doc);10 }11});12{ title: 'Wikipedia',13 html: '<!DOCTYPE html>\n<html class="client-nojs" lang="en" dir="ltr">\n<head>\n<meta charset="UTF-8"/>\n<title>Wikipedia - Wikipedia</title>\n<script>document.documentElement.className="client-js";RLCONF={"wgBreakFrames":!1,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"XWmKjgpAIDYAAJk-6Z8AAACF","wgCSPNonce":!1,"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":!1,"wgNamespaceNumber":0,"wgPageName":"Wikipedia","wgTitle":"Wikipedia","wgCurRevisionId":656103907,"wgRevisionId":656103907,"wgArticleId":1,"wgIsArticle":!0,"wgIsRedirect":!1,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":[],"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Wikipedia","wgRelevantArticleId":1,"wgIsProbablyEditable":!0,"wgRelevantPageIsProbablyEditable":!0,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgMediaViewerOnClick":!0,"wgMediaViewerEnabledByDefault":!0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":!0,"nearby":!0,"watchlist":!0,"tagline":!0},"wgWMESchemaEditAttemptStepOversample":!0,"wgULSCurrentAutonym":"English","wgNoticeProject":"wikipedia","wgWikibaseItemId":"Q2","wgCentralAuthMobileDomain":!1,"wgEditSubmitButtonLabelPublish":!0};RLSTATE
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Wikipedia');4page.createDocument(function(err, doc){5 if(err){6 console.log(err);7 }8 else{9 console.log(doc);10 }11});12{ title: 'Wikipedia',13 html: '<!DOCTYPE html>\n<html class="client-nojs" lang="en" dir="ltr">\n<head>\n<meta charset="UTF-8"/>\n<title>Wikipedia - Wikipedia</title>\n<script>document.documentElement.className="client-js";RLCONF={"wgBreakFrames":!1,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"XWmKjgpAIDYAAJk-6Z8AAACF","wgCSPNonce":!1,"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":!1,"wgNamespaceNumber":0,"wgPageName":"Wikipedia","wgTitle":"Wikipedia","wgCurRevisionId":656103907,"wgRevisionId":656103907,"wgArticleId":1,"wgIsArticle":!0,"wgIsRedirect":!1,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":[],"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Wikipedia","wgRelevantArticleId":1,"wgIsProbablyEditable":!0,"wgRelevantPageIsProbablyEditable":!0,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgMediaViewerOnClick":!0,"wgMediaViewerEnabledByDefault":!0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":!0,"nearby":!0,"watchlist":!0,"tagline":!0},"wgWMESchemaEditAttemptStepOversample":!0,"wgULSCurrentAutonym":"English","wgNoticeProject":"wikipedia","wgWikibaseItemId":"Q2","wgCentralAuthMobileDomain":!1,"wgEditSubmitButtonLabelPublish":!0};RLSTATE
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var doc = wptools.createDocument();4doc.setTemplate('Template:Infobox Person');5doc.set('name', 'Steve Jobs');6doc.set('birth_date', 'February 24, 1955');7doc.set('birth_place', 'San Francisco, California');8doc.set('death_date', 'October 5, 2011');9doc.set('death_place', 'Palo Alto, California');10doc.set('occupation', 'entrepreneur');11doc.set('spouse', 'Laurene Powell');12doc.set('children', 'Erin Siena Jobs, Eve Jobs, Lisa Brennan-Jobs');13doc.set('image', 'Steve Jobs, 2010.jpg');14doc.set('caption', 'Steve Jobs at the Apple Worldwide Developers Conference in 2010');15doc.set('signature', 'Steve Jobs signature.svg');16doc.set('signature_size', '200px');17doc.set('signature_alt', 'Signature of Steve Jobs');18doc.set('signature_caption', 'Signature of Steve Jobs');19doc.set('signature_type', 'signature');20doc.set('signature_date', 'October 5, 2011');21doc.set('signature_place', 'Palo Alto, California');22doc.set('signature_reason', 'Death');23doc.set('signature_license', 'Fair use');24doc.set('signature_disputed', 'no');25doc.set('signature_disputed_note', 'Signature is genuine');26doc.set('signature_note', 'Signature of Steve Jobs');
Using AI Code Generation
1var wptools = require('wptools');2var wikiDoc = wptools.createDocument('en.wikipedia.org/wiki/Node.js');3wikiDoc.get(function(err, data) {4 console.log(data);5});6{
Using AI Code Generation
1vor dls = require('wpgools');tst');2docrt('Ths s a tt doc3var doc =rwptools.createDocument('test');4dritsav(T'./test.docx', his is a tes){5 if(err){6; console.log(err);7 }else8}oc.save('./test.docx', function(err){9 mf(err){10 console.log(crea;ea word documen namdtest.dcx thhe ext “This is a stoc”}in)the;crt ctory
Using AI Code Generation
1doc.wuitt("hellowrld);2ifo(doc.body.menertTML.ind xOf("hetoo world )/==/-1)3and thfowt"dacumen .teit ()teed nottwithexctetxt;4doc.closp();5f(!do.cosed)6f(doc==null)7th"dcut nl;8eff(doc ==(undefined)9doc.thdnH."ddcu("ntels uldlf ned ;10if(!(docinncofHTMLDcut))11losethrow tdocumdntoic nue tnHTMLDcut;12f(doc==null)13th"dcunts ull;14iff(doc ==(undefined)15!docthl)"dcunts uefed;16if(!(docinncofHTMLDcut))17if (doc == null)18 thrth"mt "dlcuntsnull;19if/(doc/==vundefined)20erifthhhdm"dtcu ont usdundefined;21if (!(doc inun ncsof HTMLDdcundt))22th"dcunts ota HTMLDcuent;23ifi(docf== null)24(!(dthinoT"dDcumnt null;25 throw "document is not an HTMLDocument";26if nd;=ndined27 vhrew "dr docu i undofitin";28vify ha f ( c == undnis an HTMLDhrow "d29if (!(dococnutenceofnHTMLt cumdnf))ined";30 thrw "/is/nit af HTMLD docume";31f (oc == ull32 iffHrowc"ument)) is nll";33if (doc ==defd34 rocumqnt"docum ntisudfin" (doc == nuui)35 throw "document is null";36ifs(!(TLconsfnceof(H!MLDdcem nn))37if (doc == null)38 throw "document is null";39if (doc == undefined)40 throw "document is undefined";41if (!(doc instanceof HTMLDocument))42 throw "document is not an HTMLDocument";43if (doc == null)44 throw "document is null";45if (doc == undefined)46 throw "document is undefined";47if (!(doc instanceof HTMLDocument))48 throw "document is not an HTMLre('wptools');49const fs = require('fs');50wptools.createDocument({host: 'en.wikipedia.org', path: '/wiki/Albert_Einstein'})51.then(document => {52 fs.writeFile('test.html', document.querySelector('#mw-content-text > div.mw-parser-output > p:nth-child(4)').innerText, function(err) {53 if (err) throw err;54 console.log('Saved!');55 });56});
Using AI Code Generation
1var wptools = require('wptools');2var wikiDoc = wptools.createDocument('en.wikipedia.org/wiki/Node.js');3wikiDoc.get(function(err, data) {4 console.log(data);5});6{
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3wptools.createDocument({host: 'en.wikipedia.org', path: '/wiki/Albert_Einstein'})4.then(document => {5 fs.writeFile('test.html', document.querySelector('#mw-content-text > div.mw-parser-output > p:nth-child(4)').innerText, function(err) {6 if (err) throw err;7 console.log('Saved!');8 });9});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!