Best JavaScript code snippet using ava
planactions.js
Source:planactions.js
1// This file is part of Moodle - http://moodle.org/2//3// Moodle is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// Moodle is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.12//13// You should have received a copy of the GNU General Public License14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.15/**16 * Plan actions via ajax.17 *18 * @module tool_lp/planactions19 * @package tool_lp20 * @copyright 2015 David Monllao21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later22 */23define(['jquery',24 'core/templates',25 'core/ajax',26 'core/notification',27 'core/str',28 'tool_lp/menubar',29 'tool_lp/dialogue'],30 function($, templates, ajax, notification, str, Menubar, Dialogue) {31 /**32 * PlanActions class.33 *34 * Note that presently this cannot be instantiated more than once per page.35 *36 * @param {String} type The type of page we're in.37 */38 var PlanActions = function(type) {39 this._type = type;40 if (type === 'plan') {41 // This is the page to view one plan.42 this._region = '[data-region="plan-page"]';43 this._planNode = '[data-region="plan-page"]';44 this._template = 'tool_lp/plan_page';45 this._contextMethod = 'tool_lp_data_for_plan_page';46 } else if (type === 'plans') {47 // This is the page to view a list of plans.48 this._region = '[data-region="plans"]';49 this._planNode = '[data-region="plan-node"]';50 this._template = 'tool_lp/plans_page';51 this._contextMethod = 'tool_lp_data_for_plans_page';52 } else {53 throw new TypeError('Unexpected type.');54 }55 };56 /** @type {String} Ajax method to fetch the page data from. */57 PlanActions.prototype._contextMethod = null;58 /** @type {String} Selector to find the node describing the plan. */59 PlanActions.prototype._planNode = null;60 /** @type {String} Selector mapping to the region to update. Usually similar to wrapper. */61 PlanActions.prototype._region = null;62 /** @type {String} Name of the template used to render the region. */63 PlanActions.prototype._template = null;64 /** @type {String} Type of page/region we're in. */65 PlanActions.prototype._type = null;66 /**67 * Resolve the arguments to refresh the region.68 *69 * @param {Object} planData Plan data from plan node.70 * @return {Object} List of arguments.71 */72 PlanActions.prototype._getContextArgs = function(planData) {73 var self = this,74 args = {};75 if (self._type === 'plan') {76 args = {77 planid: planData.id78 };79 } else if (self._type === 'plans') {80 args = {81 userid: planData.userid82 };83 }84 return args;85 };86 /**87 * Refresh the plan view.88 *89 * This is useful when you only want to refresh the view.90 *91 * @param {String} selector The node to search the plan data from.92 */93 PlanActions.prototype.refresh = function(selector) {94 var planData = this._findPlanData($(selector));95 this._callAndRefresh([], planData);96 };97 /**98 * Callback to render the region template.99 *100 * @param {Object} context The context for the template.101 */102 PlanActions.prototype._renderView = function(context) {103 var self = this;104 templates.render(self._template, context)105 .done(function(newhtml, newjs) {106 $(self._region).replaceWith(newhtml);107 templates.runTemplateJS(newjs);108 })109 .fail(notification.exception);110 };111 /**112 * Call multiple ajax methods, and refresh.113 *114 * @param {Array} calls List of Ajax calls.115 * @param {Object} planData Plan data from plan node.116 * @return {Promise}117 */118 PlanActions.prototype._callAndRefresh = function(calls, planData) {119 var self = this;120 calls.push({121 methodname: self._contextMethod,122 args: self._getContextArgs(planData)123 });124 // Apply all the promises, and refresh when the last one is resolved.125 return $.when.apply($.when, ajax.call(calls))126 .then(function() {127 self._renderView(arguments[arguments.length - 1]);128 })129 .fail(notification.exception);130 };131 /**132 * Delete a plan and reload the region.133 *134 * @param {Object} planData Plan data from plan node.135 */136 PlanActions.prototype._doDelete = function(planData) {137 var self = this,138 calls = [{139 methodname: 'core_competency_delete_plan',140 args: {id: planData.id}141 }];142 self._callAndRefresh(calls, planData);143 };144 /**145 * Delete a plan.146 *147 * @param {Object} planData Plan data from plan node.148 */149 PlanActions.prototype.deletePlan = function(planData) {150 var self = this,151 requests;152 requests = ajax.call([{153 methodname: 'core_competency_read_plan',154 args: {id: planData.id}155 }]);156 requests[0].done(function(plan) {157 str.get_strings([158 {key: 'confirm', component: 'moodle'},159 {key: 'deleteplan', component: 'tool_lp', param: plan.name},160 {key: 'delete', component: 'moodle'},161 {key: 'cancel', component: 'moodle'}162 ]).done(function(strings) {163 notification.confirm(164 strings[0], // Confirm.165 strings[1], // Delete plan X?166 strings[2], // Delete.167 strings[3], // Cancel.168 function() {169 self._doDelete(planData);170 }171 );172 }).fail(notification.exception);173 }).fail(notification.exception);174 };175 /**176 * Reopen plan and reload the region.177 *178 * @param {Object} planData Plan data from plan node.179 */180 PlanActions.prototype._doReopenPlan = function(planData) {181 var self = this,182 calls = [{183 methodname: 'core_competency_reopen_plan',184 args: {planid: planData.id}185 }];186 self._callAndRefresh(calls, planData);187 };188 /**189 * Reopen a plan.190 *191 * @param {Object} planData Plan data from plan node.192 */193 PlanActions.prototype.reopenPlan = function(planData) {194 var self = this,195 requests = ajax.call([{196 methodname: 'core_competency_read_plan',197 args: {id: planData.id}198 }]);199 requests[0].done(function(plan) {200 str.get_strings([201 {key: 'confirm', component: 'moodle'},202 {key: 'reopenplanconfirm', component: 'tool_lp', param: plan.name},203 {key: 'reopenplan', component: 'tool_lp'},204 {key: 'cancel', component: 'moodle'}205 ]).done(function(strings) {206 notification.confirm(207 strings[0], // Confirm.208 strings[1], // Reopen plan X?209 strings[2], // reopen.210 strings[3], // Cancel.211 function() {212 self._doReopenPlan(planData);213 }214 );215 }).fail(notification.exception);216 }).fail(notification.exception);217 };218 /**219 * Complete plan and reload the region.220 *221 * @param {Object} planData Plan data from plan node.222 */223 PlanActions.prototype._doCompletePlan = function(planData) {224 var self = this,225 calls = [{226 methodname: 'core_competency_complete_plan',227 args: {planid: planData.id}228 }];229 self._callAndRefresh(calls, planData);230 };231 /**232 * Complete a plan process.233 *234 * @param {Object} planData Plan data from plan node.235 */236 PlanActions.prototype.completePlan = function(planData) {237 var self = this,238 requests = ajax.call([{239 methodname: 'core_competency_read_plan',240 args: {id: planData.id}241 }]);242 requests[0].done(function(plan) {243 str.get_strings([244 {key: 'confirm', component: 'moodle'},245 {key: 'completeplanconfirm', component: 'tool_lp', param: plan.name},246 {key: 'completeplan', component: 'tool_lp'},247 {key: 'cancel', component: 'moodle'}248 ]).done(function(strings) {249 notification.confirm(250 strings[0], // Confirm.251 strings[1], // Complete plan X?252 strings[2], // Complete.253 strings[3], // Cancel.254 function() {255 self._doCompletePlan(planData);256 }257 );258 }).fail(notification.exception);259 }).fail(notification.exception);260 };261 /**262 * Unlink plan and reload the region.263 *264 * @param {Object} planData Plan data from plan node.265 */266 PlanActions.prototype._doUnlinkPlan = function(planData) {267 var self = this,268 calls = [{269 methodname: 'core_competency_unlink_plan_from_template',270 args: {planid: planData.id}271 }];272 self._callAndRefresh(calls, planData);273 };274 /**275 * Unlink a plan process.276 *277 * @param {Object} planData Plan data from plan node.278 */279 PlanActions.prototype.unlinkPlan = function(planData) {280 var self = this,281 requests = ajax.call([{282 methodname: 'core_competency_read_plan',283 args: {id: planData.id}284 }]);285 requests[0].done(function(plan) {286 str.get_strings([287 {key: 'confirm', component: 'moodle'},288 {key: 'unlinkplantemplateconfirm', component: 'tool_lp', param: plan.name},289 {key: 'unlinkplantemplate', component: 'tool_lp'},290 {key: 'cancel', component: 'moodle'}291 ]).done(function(strings) {292 notification.confirm(293 strings[0], // Confirm.294 strings[1], // Unlink plan X?295 strings[2], // Unlink.296 strings[3], // Cancel.297 function() {298 self._doUnlinkPlan(planData);299 }300 );301 }).fail(notification.exception);302 }).fail(notification.exception);303 };304 /**305 * Request review of a plan.306 *307 * @param {Object} planData Plan data from plan node.308 * @method _doRequestReview309 */310 PlanActions.prototype._doRequestReview = function(planData) {311 var calls = [{312 methodname: 'core_competency_plan_request_review',313 args: {314 id: planData.id315 }316 }];317 this._callAndRefresh(calls, planData);318 };319 /**320 * Request review of a plan.321 *322 * @param {Object} planData Plan data from plan node.323 * @method requestReview324 */325 PlanActions.prototype.requestReview = function(planData) {326 this._doRequestReview(planData);327 };328 /**329 * Cancel review request of a plan.330 *331 * @param {Object} planData Plan data from plan node.332 * @method _doCancelReviewRequest333 */334 PlanActions.prototype._doCancelReviewRequest = function(planData) {335 var calls = [{336 methodname: 'core_competency_plan_cancel_review_request',337 args: {338 id: planData.id339 }340 }];341 this._callAndRefresh(calls, planData);342 };343 /**344 * Cancel review request of a plan.345 *346 * @param {Object} planData Plan data from plan node.347 * @method cancelReviewRequest348 */349 PlanActions.prototype.cancelReviewRequest = function(planData) {350 this._doCancelReviewRequest(planData);351 };352 /**353 * Start review of a plan.354 *355 * @param {Object} planData Plan data from plan node.356 * @method _doStartReview357 */358 PlanActions.prototype._doStartReview = function(planData) {359 var calls = [{360 methodname: 'core_competency_plan_start_review',361 args: {362 id: planData.id363 }364 }];365 this._callAndRefresh(calls, planData);366 };367 /**368 * Start review of a plan.369 *370 * @param {Object} planData Plan data from plan node.371 * @method startReview372 */373 PlanActions.prototype.startReview = function(planData) {374 this._doStartReview(planData);375 };376 /**377 * Stop review of a plan.378 *379 * @param {Object} planData Plan data from plan node.380 * @method _doStopReview381 */382 PlanActions.prototype._doStopReview = function(planData) {383 var calls = [{384 methodname: 'core_competency_plan_stop_review',385 args: {386 id: planData.id387 }388 }];389 this._callAndRefresh(calls, planData);390 };391 /**392 * Stop review of a plan.393 *394 * @param {Object} planData Plan data from plan node.395 * @method stopReview396 */397 PlanActions.prototype.stopReview = function(planData) {398 this._doStopReview(planData);399 };400 /**401 * Approve a plan.402 *403 * @param {Object} planData Plan data from plan node.404 * @method _doApprove405 */406 PlanActions.prototype._doApprove = function(planData) {407 var calls = [{408 methodname: 'core_competency_approve_plan',409 args: {410 id: planData.id411 }412 }];413 this._callAndRefresh(calls, planData);414 };415 /**416 * Approve a plan.417 *418 * @param {Object} planData Plan data from plan node.419 * @method approve420 */421 PlanActions.prototype.approve = function(planData) {422 this._doApprove(planData);423 };424 /**425 * Unapprove a plan.426 *427 * @param {Object} planData Plan data from plan node.428 * @method _doUnapprove429 */430 PlanActions.prototype._doUnapprove = function(planData) {431 var calls = [{432 methodname: 'core_competency_unapprove_plan',433 args: {434 id: planData.id435 }436 }];437 this._callAndRefresh(calls, planData);438 };439 /**440 * Unapprove a plan.441 *442 * @param {Object} planData Plan data from plan node.443 * @method unapprove444 */445 PlanActions.prototype.unapprove = function(planData) {446 this._doUnapprove(planData);447 };448 /**449 * Display list of linked courses on a modal dialogue.450 *451 * @param {Event} e The event.452 */453 PlanActions.prototype._showLinkedCoursesHandler = function(e) {454 e.preventDefault();455 var competencyid = $(e.target).data('id');456 var requests = ajax.call([{457 methodname: 'tool_lp_list_courses_using_competency',458 args: {id: competencyid}459 }]);460 requests[0].done(function(courses) {461 var context = {462 courses: courses463 };464 templates.render('tool_lp/linked_courses_summary', context).done(function(html) {465 str.get_string('linkedcourses', 'tool_lp').done(function(linkedcourses) {466 new Dialogue(467 linkedcourses, // Title.468 html // The linked courses.469 );470 }).fail(notification.exception);471 }).fail(notification.exception);472 }).fail(notification.exception);473 };474 /**475 * Plan event handler.476 *477 * @param {String} method The method to call.478 * @param {Event} e The event.479 * @method _eventHandler480 */481 PlanActions.prototype._eventHandler = function(method, e) {482 e.preventDefault();483 var data = this._findPlanData($(e.target));484 this[method](data);485 };486 /**487 * Find the plan data from the plan node.488 *489 * @param {Node} node The node to search from.490 * @return {Object} Plan data.491 */492 PlanActions.prototype._findPlanData = function(node) {493 var parent = node.parentsUntil($(this._region).parent(), this._planNode),494 data;495 if (parent.length != 1) {496 throw new Error('The plan node was not located.');497 }498 data = parent.data();499 if (typeof data === 'undefined' || typeof data.id === 'undefined') {500 throw new Error('Plan data could not be found.');501 }502 return data;503 };504 /**505 * Enhance a menu bar.506 *507 * @param {String} selector Menubar selector.508 */509 PlanActions.prototype.enhanceMenubar = function(selector) {510 Menubar.enhance(selector, {511 '[data-action="plan-delete"]': this._eventHandler.bind(this, 'deletePlan'),512 '[data-action="plan-complete"]': this._eventHandler.bind(this, 'completePlan'),513 '[data-action="plan-reopen"]': this._eventHandler.bind(this, 'reopenPlan'),514 '[data-action="plan-unlink"]': this._eventHandler.bind(this, 'unlinkPlan'),515 '[data-action="plan-request-review"]': this._eventHandler.bind(this, 'requestReview'),516 '[data-action="plan-cancel-review-request"]': this._eventHandler.bind(this, 'cancelReviewRequest'),517 '[data-action="plan-start-review"]': this._eventHandler.bind(this, 'startReview'),518 '[data-action="plan-stop-review"]': this._eventHandler.bind(this, 'stopReview'),519 '[data-action="plan-approve"]': this._eventHandler.bind(this, 'approve'),520 '[data-action="plan-unapprove"]': this._eventHandler.bind(this, 'unapprove'),521 });522 };523 /**524 * Register the events in the region.525 *526 * At this stage this cannot be used with enhanceMenubar or multiple handlers527 * will be added to the same node.528 */529 PlanActions.prototype.registerEvents = function() {530 var wrapper = $(this._region);531 wrapper.find('[data-action="plan-delete"]').click(this._eventHandler.bind(this, 'deletePlan'));532 wrapper.find('[data-action="plan-complete"]').click(this._eventHandler.bind(this, 'completePlan'));533 wrapper.find('[data-action="plan-reopen"]').click(this._eventHandler.bind(this, 'reopenPlan'));534 wrapper.find('[data-action="plan-unlink"]').click(this._eventHandler.bind(this, 'unlinkPlan'));535 wrapper.find('[data-action="plan-request-review"]').click(this._eventHandler.bind(this, 'requestReview'));536 wrapper.find('[data-action="plan-cancel-review-request"]').click(this._eventHandler.bind(this, 'cancelReviewRequest'));537 wrapper.find('[data-action="plan-start-review"]').click(this._eventHandler.bind(this, 'startReview'));538 wrapper.find('[data-action="plan-stop-review"]').click(this._eventHandler.bind(this, 'stopReview'));539 wrapper.find('[data-action="plan-approve"]').click(this._eventHandler.bind(this, 'approve'));540 wrapper.find('[data-action="plan-unapprove"]').click(this._eventHandler.bind(this, 'unapprove'));541 wrapper.find('[data-action="find-courses-link"]').click(this._showLinkedCoursesHandler.bind(this));542 };543 return PlanActions;...
test_staffing_plan.py
Source:test_staffing_plan.py
...8from erpnext.hr.doctype.staffing_plan.staffing_plan import ParentCompanyError9from frappe.utils import nowdate, add_days10test_dependencies = ["Designation"]11class TestStaffingPlan(unittest.TestCase):12 def test_staffing_plan(self):13 _set_up()14 frappe.db.set_value("Company", "_Test Company", "is_group", 1)15 if frappe.db.exists("Staffing Plan", "Test"):16 return17 staffing_plan = frappe.new_doc("Staffing Plan")18 staffing_plan.company = "_Test Company 10"19 staffing_plan.name = "Test"20 staffing_plan.from_date = nowdate()21 staffing_plan.to_date = add_days(nowdate(), 10)22 staffing_plan.append("staffing_details", {23 "designation": "Designer",24 "vacancies": 6,25 "estimated_cost_per_position": 5000026 })27 staffing_plan.insert()28 staffing_plan.submit()29 self.assertEqual(staffing_plan.total_estimated_budget, 300000.00)30 def test_staffing_plan_subsidiary_company(self):31 self.test_staffing_plan()32 if frappe.db.exists("Staffing Plan", "Test 1"):33 return34 staffing_plan = frappe.new_doc("Staffing Plan")35 staffing_plan.company = "_Test Company"36 staffing_plan.name = "Test 1"37 staffing_plan.from_date = nowdate()38 staffing_plan.to_date = add_days(nowdate(), 10)39 staffing_plan.append("staffing_details", {40 "designation": "Designer",41 "vacancies": 3,42 "estimated_cost_per_position": 4500043 })44 self.assertRaises(SubsidiaryCompanyError, staffing_plan.insert)45 def test_staffing_plan_parent_company(self):...
Using AI Code Generation
1const test = require('ava');2test('foo', t => {3 t.plan(2);4 t.pass();5 t.pass();6});7test('bar', async t => {8 const bar = Promise.resolve('bar');9 t.is(await bar, 'bar');10});
Using AI Code Generation
1const test = require('ava');2test('my passing test', t => {3 t.plan(2);4 t.is(1, 1);5 t.is(2, 2);6});7test('my failing test', t => {8 t.plan(2);9 t.is(1, 1);10 t.is(2, 3);11});
Using AI Code Generation
1test('my passing test', t => {2 t.plan(2);3 t.is(1, 1);4 t.is(2, 2);5});6test('my failing test', t => {7 t.plan(2);8 t.is(1, 1);9 t.is(2, 3);10});11test('my failing test', t => {12 t.plan(2);13 t.is(1, 1);14 t.is(2, 3);15 t.is(3, 3);16});17test('my failing test', t => {18 t.plan(2);19 t.is(1, 1);20 t.is(2, 3);21 t.is(3, 3);22 t.is(4, 4);23});24test('my failing test', t => {25 t.plan(2);26 t.is(1, 1);27 t.is(2, 3);28 t.is(3, 3);29 t.is(4, 4);30 t.is(5, 5);31});32test('my failing test', t => {33 t.plan(2);34 t.is(1, 1);35 t.is(2, 3);36 t.is(3, 3);37 t.is(4, 4);38 t.is(5, 5);39 t.is(6, 6);40});41test('my failing test', t => {42 t.plan(2);43 t.is(1, 1);44 t.is(2, 3);45 t.is(3, 3);46 t.is(4, 4);47 t.is(5, 5);48 t.is(6, 6);49 t.is(7, 7);50});51test('my failing test', t => {52 t.plan(2);53 t.is(1, 1);54 t.is(2, 3);55 t.is(3, 3);56 t.is(4, 4);57 t.is(5, 5);
Using AI Code Generation
1test('My first test', t => {2 t.plan(2);3 t.is(1, 1);4 t.is(2, 2);5});6test.cb('My second test', t => {7 t.plan(2);8 t.is(1, 1);9 t.is(2, 2);10 t.end();11});12test.cb('My third test', t => {13 t.plan(2);14 t.is(1, 1);15 t.is(2, 2);16 t.end();17});18test('My fourth test', t => {19 t.plan(2);20 t.is(1, 1);21 t.is(2, 2);22 t.end();23});24test('My fifth test', t => {25 t.plan(2);26 t.is(1, 1);27 t.is(2, 2);28 t.end();29});30test('My sixth test', t => {31 t.plan(2);32 t.is(1, 1);33 t.is(2, 2);34 t.end();35});36test('My seventh test', t => {37 t.plan(2);38 t.is(1, 1);39 t.is(2, 2);40 t.end();41});42test('My eighth test', t => {43 t.plan(2);44 t.is(1, 1);45 t.is(2, 2);46 t.end();47});48test('My ninth test', t => {49 t.plan(2);50 t.is(1, 1);51 t.is(2, 2);52 t.end();53});54test('My tenth test', t => {55 t.plan(2);56 t.is(1, 1);57 t.is(2, 2);58 t.end();59});60test('My eleventh test', t => {61 t.plan(2);62 t.is(1
Using AI Code Generation
1test('ava test', t => {2 t.plan(3);3 t.is(1, 1);4 t.is(2, 2);5 t.is(3, 3);6});7it('mocha test', function() {8 expect(1).to.equal(1);9 expect(2).to.equal(2);10 expect(3).to.equal(3);11});12test('jest test', () => {13 expect(1).toBe(1);14 expect(2).toBe(2);15 expect(3).toBe(3);16});17it('jasmine test', () => {18 expect(1).toBe(1);19 expect(2).toBe(2);20 expect(3).toBe(3);21});22test('tap test', t => {23 t.plan(3);24 t.equal(1, 1);25 t.equal(2, 2);26 t.equal(3, 3);27});28test('tape test', t => {29 t.plan(3);30 t.equal(1, 1);31 t.equal(2, 2);32 t.equal(3, 3);33});34test('node-tap test', t => {35 t.plan(3);36 t.equal(1, 1);37 t.equal(2, 2);38 t.equal(3, 3);39});40test('tape-promise test', t => {41 t.plan(3);42 t.equal(1, 1);43 t.equal(2, 2);44 t.equal(3, 3);45});46test('node-tap-promise test', t => {47 t.plan(3);48 t.equal(1, 1);49 t.equal(2, 2);50 t.equal(3, 3);51});52test('node-tap-async test', t => {53 t.plan(3);54 t.equal(1, 1);55 t.equal(
Using AI Code Generation
1const test = require('ava')2test('test', t => {3 t.plan(2)4 t.is(1, 1)5 t.is(2, 2)6})7const test = require('ava')8test('test', t => {9 t.plan(2)10 t.is(1, 1)11 t.is(2, 2)12})13const test = require('ava')14test('test', t => {15 t.plan(2)16 t.is(1, 1)17 t.is(2, 2)18})19const test = require('ava')20test('test', t => {21 t.plan(2)22 t.is(1, 1)23 t.is(2, 2)24})25const test = require('ava')26test('test', t => {27 t.plan(2)28 t.is(1, 1)29 t.is(2, 2)30})31const test = require('ava')32test('test', t => {33 t.plan(2)34 t.is(1, 1)35 t.is(2, 2)36})37const test = require('ava')38test('test', t => {39 t.plan(2)40 t.is(1, 1)41 t.is(2, 2)42})43const test = require('ava')44test('test', t => {45 t.plan(2)46 t.is(1
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!!