How to use makeSelector method in Testcafe

Best JavaScript code snippet using testcafe

connected-droppable.spec.js

Source:connected-droppable.spec.js Github

copy

Full Screen

...126 describe('dropping is disabled', () => {127 const phases: Phase[] = ['IDLE', 'COLLECTING_DIMENSIONS', 'DRAGGING', 'DROP_ANIMATING', 'DROP_COMPLETE'];128 it('should always return the default props', () => {129 phases.forEach((phase: Phase) => {130 const props: MapProps = execute(makeSelector())({131 phase,132 drag: null,133 pending: null,134 id: droppableId,135 isDropDisabled: true,136 });137 expect(props).to.deep.equal(defaultMapProps);138 });139 });140 it('should not break memoization on multiple calls', () => {141 phases.forEach((phase: Phase) => {142 const selector = makeSelector();143 const first: MapProps = execute(selector)({144 phase,145 drag: null,146 pending: null,147 id: droppableId,148 });149 const second: MapProps = execute(selector)({150 phase,151 drag: null,152 pending: null,153 id: droppableId,154 });155 // checking object equality156 expect(first).to.equal(second);157 });158 });159 });160 describe('while dragging', () => {161 it('should log an error an return the default props if no drag is available', () => {162 const props: MapProps = execute(makeSelector())({163 phase: 'DRAGGING',164 drag: null,165 pending: null,166 id: droppableId,167 });168 expect(props).to.deep.equal(defaultMapProps);169 expect(console.error.called).to.equal(true);170 });171 describe('dragging over', () => {172 it('should return that it is dragging over', () => {173 const expected: MapProps = {174 isDraggingOver: true,175 };176 const props: MapProps = execute(makeSelector())({177 phase: 'DRAGGING',178 drag: perform.drag({ isDraggingOver: true }),179 pending: null,180 id: droppableId,181 });182 expect(props).to.deep.equal(expected);183 });184 it('should not break memoization on multiple drags', () => {185 const selector = makeSelector();186 const expected: MapProps = {187 isDraggingOver: true,188 };189 const props1: MapProps = execute(selector)({190 phase: 'DRAGGING',191 drag: perform.drag({ isDraggingOver: true }),192 pending: null,193 id: droppableId,194 });195 const props2: MapProps = execute(selector)({196 phase: 'DRAGGING',197 drag: perform.drag({ isDraggingOver: true }),198 pending: null,199 id: droppableId,200 });201 // checking object equality202 expect(props1).to.equal(props2);203 expect(props1).to.deep.equal(expected);204 expect(props2).to.deep.equal(expected);205 });206 });207 describe('not dragging over', () => {208 it('should return that it is not dragging over', () => {209 const expected: MapProps = {210 isDraggingOver: false,211 };212 const props: MapProps = execute(makeSelector())({213 phase: 'DRAGGING',214 drag: perform.drag({ isDraggingOver: false }),215 pending: null,216 id: droppableId,217 });218 expect(props).to.deep.equal(expected);219 });220 it('should not break memoization on multiple drags', () => {221 const selector = makeSelector();222 const expected: MapProps = {223 isDraggingOver: false,224 };225 const props1: MapProps = execute(selector)({226 phase: 'DRAGGING',227 drag: perform.drag({ isDraggingOver: false }),228 pending: null,229 id: droppableId,230 });231 const props2: MapProps = execute(selector)({232 phase: 'DRAGGING',233 drag: perform.drag({ isDraggingOver: false }),234 pending: null,235 id: droppableId,236 });237 // checking object equality238 expect(props1).to.equal(props2);239 expect(props1).to.deep.equal(expected);240 expect(props2).to.deep.equal(expected);241 });242 });243 });244 describe('while drop animating', () => {245 it('should log an error an return the default props if no pending drop is available', () => {246 const props: MapProps = execute(makeSelector())({247 phase: 'DROP_ANIMATING',248 drag: null,249 pending: null,250 id: droppableId,251 });252 expect(props).to.deep.equal(defaultMapProps);253 expect(console.error.called).to.equal(true);254 });255 describe('dragging over', () => {256 it('should return that it is dragging over', () => {257 const expected: MapProps = {258 isDraggingOver: true,259 };260 const props: MapProps = execute(makeSelector())({261 phase: 'DROP_ANIMATING',262 drag: null,263 pending: perform.drop({ isDraggingOver: true }),264 id: droppableId,265 });266 expect(props).to.deep.equal(expected);267 });268 it('should not break memoization from a previous DRAGGING phase', () => {269 const selector = makeSelector();270 const expected: MapProps = {271 isDraggingOver: true,272 };273 const dragging: MapProps = execute(selector)({274 phase: 'DRAGGING',275 drag: perform.drag({ isDraggingOver: true }),276 pending: null,277 id: droppableId,278 });279 const dropAnimating: MapProps = execute(selector)({280 phase: 'DROP_ANIMATING',281 drag: null,282 pending: perform.drop({ isDraggingOver: true }),283 id: droppableId,284 });285 expect(dragging).to.deep.equal(expected);286 expect(dropAnimating).to.deep.equal(expected);287 // checking object equality288 expect(dragging).to.equal(dropAnimating);289 });290 });291 describe('not dragging over', () => {292 it('should return that it is not dragging over', () => {293 const expected: MapProps = {294 isDraggingOver: false,295 };296 const props: MapProps = execute(makeSelector())({297 phase: 'DROP_ANIMATING',298 drag: null,299 pending: perform.drop({ isDraggingOver: false }),300 id: droppableId,301 });302 expect(props).to.deep.equal(expected);303 });304 it('should not break memoization from a previous DRAGGING phase', () => {305 const selector = makeSelector();306 const expected: MapProps = {307 isDraggingOver: false,308 };309 const dragging: MapProps = execute(selector)({310 phase: 'DRAGGING',311 drag: perform.drag({ isDraggingOver: false }),312 pending: null,313 id: droppableId,314 });315 const dropAnimating: MapProps = execute(selector)({316 phase: 'DROP_ANIMATING',317 drag: null,318 pending: perform.drop({ isDraggingOver: false }),319 id: droppableId,320 });321 expect(dragging).to.deep.equal(expected);322 expect(dropAnimating).to.deep.equal(expected);323 // checking object equality324 expect(dragging).to.equal(dropAnimating);325 });326 });327 });328 describe('other phases', () => {329 const other: Phase[] = ['IDLE', 'COLLECTING_DIMENSIONS', 'DROP_COMPLETE'];330 it('should return the default props', () => {331 const selector = makeSelector();332 other.forEach((phase: Phase): void => {333 const props: MapProps = execute(selector)({334 phase,335 drag: null,336 pending: null,337 id: droppableId,338 });339 expect(props).to.deep.equal(defaultMapProps);340 });341 });342 it('should not break memoization on multiple calls', () => {343 const selector = makeSelector();344 other.forEach((phase: Phase): void => {345 const first: MapProps = execute(selector)({346 phase,347 drag: null,348 pending: null,349 id: droppableId,350 });351 const second: MapProps = execute(selector)({352 phase,353 drag: null,354 pending: null,355 id: droppableId,356 });357 expect(first).to.deep.equal(defaultMapProps);...

Full Screen

Full Screen

MultiSelector.js

Source:MultiSelector.js Github

copy

Full Screen

...45 surname: lastNames[i]46 });47 }48 }49 function makeSelector(storeCfg, searchStoreCfg) {50 storeCfg = storeCfg || defaultStoreCfg;51 searchStoreCfg = searchStoreCfg || defaultSearchStoreCfg;52 multiSelector = new Ext.view.MultiSelector({53 renderTo: Ext.getBody(),54 width: 400,55 height: 300,56 store: storeCfg,57 fieldName: 'name',58 viewConfig: {59 deferEmptyText: false,60 emptyText: 'No employees selected'61 },62 search: {63 field: 'name',64 store: searchStoreCfg65 }66 });67 }68 function completeRequest(responseData, status) {69 var responseText = Ext.encode(responseData || data);70 Ext.Ajax.mockComplete({71 status: status || 200,72 responseText: responseText73 });74 }75 beforeEach(function() {76 Employee = Ext.define('spec.Employee', {77 extend: 'Ext.data.Model',78 fields: [{79 name: 'id'80 }, {81 name: 'forename'82 }, {83 name: 'surname'84 }, {85 name: 'name',86 convert: function(v, rec) {87 return rec.editing ? v : rec.get('forename') + ' ' + rec.get('surname');88 }89 }]90 });91 });92 afterEach(function() {93 Ext.undefine('spec.Employee');94 Ext.data.Model.schema.clear();95 multiSelector = Ext.destroy(multiSelector);96 });97 describe("search popup", function () {98 describe("alignment", function() {99 beforeEach(function() {100 makeSelector();101 jasmine.fireMouseEvent(multiSelector.down('tool').el, 'click');102 });103 it("should align to the top right", function() {104 var popup = multiSelector.searchPopup;105 expect(popup.el.getTop()).toBe(multiSelector.el.getTop());106 expect(popup.el.getLeft()).toBe(multiSelector.el.getRight());107 });108 it("should retain selection when moving", function() {109 var popup = multiSelector.searchPopup;110 multiSelector.setWidth(600);111 expect(popup.el.getTop()).toBe(multiSelector.el.getTop());112 expect(popup.el.getLeft()).toBe(multiSelector.el.getRight());113 });114 });115 describe("synchronizing selection", function () {116 describe("store with remote data", function () {117 beforeEach(function() {118 // Override so that we can control asynchronous loading119 loadStore = Ext.data.ProxyStore.prototype.load = function() {120 proxyStoreLoad.apply(this, arguments);121 if (synchronousLoad) {122 this.flushLoad.apply(this, arguments);123 }124 return this;125 };126 MockAjaxManager.addMethods();127 makeSelector();128 });129 afterEach(function() {130 // Undo the overrides.131 Ext.data.ProxyStore.prototype.load = proxyStoreLoad;132 MockAjaxManager.removeMethods();133 });134 it("should select the records in the searcher which match by ID the records in the selector", function() {135 var searchStore,136 searchGrid;137 // Load the multiSelector's store138 multiSelector.store.load();139 completeRequest(data[0]);140 multiSelector.onShowSearch();141 142 // Search grid's store is set to autoload, so wait for it to kick off a load143 waitsFor(function() {144 searchGrid = multiSelector.searchPopup.child('gridpanel');145 searchStore = searchGrid.store;146 return (searchStore instanceof Ext.data.Store) && searchStore.isLoading();147 }, 'searchStore to kick off a load'); 148 runs(function() {149 completeRequest();150 151 expect(searchGrid.getSelectionModel().getSelection()[0].get('name')).toBe(multiSelector.store.getAt(0).get('name'));152 });153 });154 it("should visually highlight the rows in the searcher which match by ID the records in the selector", function () {155 var searchStore,156 searchGrid,157 nodes;158 // Load the multiSelector's store159 multiSelector.store.load();160 completeRequest(data[0]);161 multiSelector.onShowSearch();162 // Search grid's store is set to autoload, so wait for it to kick off a load163 waitsFor(function() {164 searchGrid = multiSelector.searchPopup.child('gridpanel');165 searchStore = searchGrid.store;166 return (searchStore instanceof Ext.data.Store) && searchStore.isLoading();167 }, 'searchStore to kick off a load'); 168 runs(function() {169 completeRequest();170 nodes = multiSelector.down('gridpanel').getView().getSelectedNodes();171 expect(nodes[0]).toHaveCls('x-grid-item-selected');172 });173 });174 });175 describe("store with inline data", function () {176 beforeEach(function () {177 var storeCfg = {178 model: 'spec.Employee',179 data: [{180 forename: 'Ben',181 surname: 'Toll',182 id: 1183 }]184 };185 var searchStoreCfg = {186 model: 'spec.Employee',187 remoteSort: false,188 remoteFilter: false,189 autoLoad: false,190 data: [{191 forename: 'Ben',192 surname: 'Toll',193 id: 1194 },{195 forename: 'Don',196 surname: 'Griffin',197 id: 2198 },{199 forename: 'Evan',200 surname: 'Trimboli',201 id: 3202 }]203 };204 205 makeSelector(storeCfg, searchStoreCfg);206 });207 it("should select the records in the searcher which match by ID the records in the selector", function () {208 multiSelector.onShowSearch();209 210 expect(multiSelector.down('gridpanel').selModel.getSelection()[0].get('name')).toBe(multiSelector.store.getAt(0).get('name'));211 });212 it("should visually highlight the rows in the searcher which match by ID the records in the selector", function () {213 var nodes;214 multiSelector.onShowSearch();215 nodes = multiSelector.down('gridpanel').getView().getSelectedNodes();216 expect(nodes[0]).toHaveCls('x-grid-item-selected');217 });218 if (Ext.supports.TouchEvents) {219 it('should not hide the picker when the picker is tapped', function() {220 multiSelector.onShowSearch();221 var searchGrid = multiSelector.searchPopup.lookupReference('searchGrid'),222 cell = new Ext.grid.CellContext(searchGrid.view).setPosition(1, 0).getCell(),223 selectedCount = multiSelector.store.getCount(),224 x = cell.getX() + cell.getWidth() / 2,225 y = cell.getY() + cell.getHeight() / 2;226 Ext.testHelper.fireEvent('start', cell.dom, [{ x: x, y: y }]);227 Ext.testHelper.fireEvent('end', cell.dom, [{ x: x, y: y }]);228 expect(multiSelector.store.getCount()).toBe(selectedCount + 1);229 expect(multiSelector.searchPopup.isVisible()).toBe(true);230 });231 }232 });233 });234 describe("synchronizing deselection", function () {235 beforeEach(function () {236 var storeCfg = {237 model: 'spec.Employee',238 data: [{239 forename: 'Ben',240 surname: 'Toll',241 id: 1242 }]243 };244 var searchStoreCfg = {245 model: 'spec.Employee',246 remoteSort: false,247 remoteFilter: false,248 autoLoad: false,249 data: [{250 forename: 'Ben',251 surname: 'Toll',252 id: 1253 },{254 forename: 'Don',255 surname: 'Griffin',256 id: 2257 },{258 forename: 'Evan',259 surname: 'Trimboli',260 id: 3261 }]262 };263 264 makeSelector(storeCfg, searchStoreCfg);265 });266 it("should deselect the records in the searcher which match by ID the records removed from the selector", function () {267 var store = multiSelector.getStore(),268 record;269 multiSelector.onShowSearch();270 record = store.getAt(0);271 store.remove(record);272 multiSelector.searchPopup.deselectRecords(record);273 expect(multiSelector.down('gridpanel').selModel.getSelection().length).toBe(0);274 });275 it("should visually unhighlight the rows in the searcher which match by ID the records removed from the selector", function () {276 var store = multiSelector.getStore(),277 record;278 multiSelector.onShowSearch();...

Full Screen

Full Screen

LevelCreator.js

Source:LevelCreator.js Github

copy

Full Screen

...43 powerctx.beginPath();44 powerctx.fillStyle = "#fff"45 powerctx.fillRect(0, 0,this.width+10,this.height+10);46 this.brickSelected = true;47 this.makeSelector();48 this.draw();49 }50 removeEvents(){51 canvas.removeEventListener('mousemove',this.moveBrick);52 canvas.removeEventListener('click',this.placeBrick);53 powerCanvas.removeEventListener('click',this.select); 54 }55 addEvents(){56 canvas.addEventListener('mousemove',this.moveBrick);57 canvas.addEventListener('click',this.placeBrick);58 powerCanvas.addEventListener('click',this.select); 59 }60 moveBrick(e){61 var rct=canvas.getBoundingClientRect();62 levelCreator.x = e.clientX - rct.left ;63 levelCreator.y = e.clientY - rct.top -levelCreator.height;64 levelCreator.out = (levelCreator.x < 20 || levelCreator.y < 2) ? true : false;65 ;66 if (levelCreator.x < 0) levelCreator.x = 0 ;67 if (levelCreator.x > canvas.width - levelCreator.width) levelCreator.x = canvas.width - levelCreator.width;68 if (levelCreator.y < 0) levelCreator.y = 0 ;69 if (levelCreator.y > canvas.height - levelCreator.height) levelCreator.y = canvas.height - levelCreator.height;70 levelCreator.x = parseInt(levelCreator.x/80)*80;71 levelCreator.y = parseInt(levelCreator.y/30)*3072 levelCreator.draw();73 // log('hi')74 75 76 }77 placeBrick(e){78 var brickNumber =levelCreator.y/30*10 + levelCreator.x/80;79 var atIndex = levelCreator.brickNumberArray.indexOf(brickNumber)80 if(!brickAddMode){81 if(atIndex == -1) return;82 levelCreator.bricks.splice(atIndex,1);83 levelCreator.brickNumberArray.splice(atIndex,1);84 levelCreator.draw();85 return;86 }87 if (levelCreator.brickSelected ) {88 if(atIndex === -1){89 levelCreator.bricks.push(new Brick(levelCreator.x,levelCreator.y, levelCreator.damage));90 levelCreator.brickNumberArray.push(brickNumber);91 }92 else{93 levelCreator.bricks[atIndex]=new Brick(levelCreator.x,levelCreator.y, levelCreator.damage);94 }95 }96 else{ 97 if (atIndex !==-1) {98 levelCreator.bricks[atIndex].power = new levelCreator.powers[levelCreator.selectedPowerIndex].constructor99 levelCreator.bricks[atIndex].placePower();100 }101 102 }103 levelCreator.draw()104 }105 draw(){106 ctx.clearRect(0, 0, canvas.width, canvas.height);107 this.bricks.forEach(108 (brick)=>{109 brick.draw(ctx,spritesCreator); 110 if(brick.power) brick.power.draw(ctx)111 }112 )113 if(!brickAddMode || this.out) return;114 if(this.brickSelected) ctx.drawImage(spritesCreator,0,0+(this.damage-1)*23,67,23,this.x +5,this.y+5,this.width,this.height);115 else {116 let pow = this.powers[this.selectedPowerIndex];117 pow.center ={x: this.x +40, y:this.y+15};118 pow.draw(ctx);119 }120 }121 makeSelector(){122 this.offset = 40;123 for (let i=0; i<6; i++){124 powerctx.drawImage(spritesCreator,0,i*23,67,23,i*(this.width+this.offset+30)+5, 5,this.width,this.height);}125 126 for (let i=0; i<this.powers.length; i++){127 let power = this.powers[i];128 power.center ={x:i*(40+this.offset)+5, y:40};129 powerctx.drawImage(...power.spriteLocation, power.center.x, power.center.y, 30, 30)130 }131 }132 select(e){133 var rct=powerCanvas.getBoundingClientRect();134 var x = e.clientX - rct.left ;135 var y = e.clientY - rct.top;136 if (y<40) {137 for (let i=0; i<6; i++){138 var pos = i*(levelCreator.width+levelCreator.offset+30)+5139 if (x>pos && x<pos+levelCreator.width) {140 powerctx.clearRect(0, 0, powerCanvas.width, powerCanvas.height)141 powerctx.beginPath();142 powerctx.fillStyle = "#fff"143 levelCreator.damage = i+1; 144 powerctx.fillRect(pos-5, 0, levelCreator.width+10, levelCreator.height+10 );145 levelCreator.makeSelector();146 levelCreator.brickSelected = true;147 break;148 }149 }150 151 }152 else {153 for (var i=0; i<levelCreator.powers.length; i++){154 var pos =i*(40+levelCreator.offset)+5;155 if (x>pos && x<pos+40) {156 powerctx.clearRect(0, 0, powerCanvas.width, powerCanvas.height)157 powerctx.beginPath();158 powerctx.fillStyle = "#fff"159 powerctx.arc(levelCreator.powers[i].center.x+15, levelCreator.powers[i].center.y+15, 19, 0, Math.PI * 2);160 powerctx.fill(); 161 levelCreator.selectedPowerIndex =i;162 levelCreator.brickSelected = false;163 levelCreator.makeSelector();164 break;165 }166 }167 }168 169 }...

Full Screen

Full Screen

vehicles.js

Source:vehicles.js Github

copy

Full Screen

1/*global define */2/*jslint browser: true */3define(['jquery', 'underscore', 'text!../../data/vehicles.json'], function ($, underscore, vehiclesJsonDataText) {4 'use strict';5 var exports = {},6 vehicles,7 getVehicles;8 getVehicles = function () {9 if (vehicles === undefined) {10 try {11 vehicles = JSON.parse(vehiclesJsonDataText);12 } catch (e) {13 vehicles = [];14 }15 }16 return vehicles;17 };18 exports.setUp = function ($typeSelector, $makeSelector, $modelSelector) {19 $typeSelector.on('change', function () {20 $makeSelector.val('').attr('disabled', 'disabled');21 $modelSelector.val('').attr('disabled', 'disabled');22 exports.loadPostProductMakes($makeSelector, $typeSelector.val());23 });24 exports.loadPostProductMakes($makeSelector, $typeSelector.val(), $makeSelector.val());25 exports.loadPostProductModels(26 $modelSelector,27 $typeSelector.val(),28 $makeSelector.val(),29 $modelSelector.val()30 );31 $makeSelector.on('change', function () {32 $modelSelector.val('').attr('disabled', 'disabled');33 exports.loadPostProductModels($modelSelector, $typeSelector.val(), $makeSelector.val());34 });35 };36 exports.loadPostProductMakes = function ($makeSelector, type, activeMake) {37 var filter,38 makes,39 $optGroup = $($makeSelector.find('optgroup')[0]),40 $entrySet = $('<select>');41 filter = {42 type: type43 };44 makes = underscore.uniq(underscore.pluck(underscore.where(getVehicles(), filter), 'make'));45 $entrySet.append('<option value="">-</option>');46 $.each(makes, function () {47 $entrySet.append($('<option>', { value: this }).text(this));48 });49 $entrySet.append($('<option>', { 'data-action' : 'other' }).text('Outro'));50 $makeSelector.removeAttr('disabled');51 $optGroup.html($entrySet.children());52 if (activeMake !== undefined) {53 $makeSelector.val(activeMake);54 if ($makeSelector.val() === activeMake) {55 return;56 }57 $optGroup.append($('<option>', { value: activeMake }).text(activeMake));58 $makeSelector.val(activeMake);59 }60 };61 exports.loadPostProductModels = function ($modelSelector, type, make, activeModel) {62 var filter,63 models,64 $optGroup,65 $entrySet;66 filter = {67 type: type,68 make: make69 };70 models = underscore.uniq(71 underscore.pluck(72 underscore.where(getVehicles(), filter),73 'model'74 )75 );76 $modelSelector.html('<optgroup label="Modelo"><option value="">-</option></optgroup>');77 $optGroup = $($modelSelector.find('optgroup')[0]);78 $entrySet = $('<select>');79 $.each(models, function () {80 $entrySet.append($('<option>', { value: this }).text(this));81 });82 $entrySet.append($('<option>', { 'data-action' : 'other' }).text('Outro'));83 $modelSelector.removeAttr('disabled');84 $optGroup.append($entrySet.children());85 if (activeModel !== undefined) {86 $modelSelector.val(activeModel);87 if ($modelSelector.val() === activeModel) {88 return;89 }90 $optGroup.append($('<option>', { value: activeModel }).text(activeModel));91 $modelSelector.val(activeModel);92 }93 };94 exports.maskMoney = function ($element) {95 $element.maskMoney(96 {97 symbol: 'R$ ',98 showSymbol: true,99 symbolStay: true,100 thousands: '.',101 decimal: ',',102 defaultZero: false103 }104 );105 };106 exports.parseYouTubeIdFromLink = function (link, softPass) {107 //from http://stackoverflow.com/posts/10591582/revisions108 /*jslint regexp: true*/109 var id = link.match(/(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/);110 /*jslint regexp: false*/111 if (id !== null) {112 return id[1];113 }114 if (softPass) {115 return link;116 }117 return '';118 };119 return exports;...

Full Screen

Full Screen

scripts.js

Source:scripts.js Github

copy

Full Screen

...6 let date = new Date();7 let year = date.getFullYear();8 let text = 'Copyright&nbsp;&copy;&nbsp;' + year + '&nbsp;<a href="http://www.plexdata.de" target="_blank">plexdata.de</a>';910 $(makeSelector(selector)).html(text);11 }12}1314function makeSelector(value) {1516 const hash = '#';1718 if (value) {1920 let index = value.indexOf(hash);2122 if (index < 0) {23 return hash + value;24 }25 }2627 return value;28}2930function selectCaller(caller) {3132 if (caller) {3334 try {3536 let parent = $(makeSelector('navigation'));3738 if (parent) {3940 $(parent).children('a').each(function () {41 $(this).removeClass('selected');42 });4344 if (typeof caller === "string") {45 caller = makeSelector(caller);46 }4748 $(caller).addClass('selected');49 }50 }51 catch (error) {52 console.log(error);53 }54 }5556 return false;57}5859function showContent(caller, chapter, section) {6061 selectCaller(caller);6263 if (chapter) {6465 try {6667 let target = makeSelector('content');6869 $(target).load(chapter);7071 $(target).ready(function () {7273 try {7475 // As first bring current target into view.76 $(target).scrollTop(0);7778 let selector = makeSelector(section);7980 if (selector) {8182 // Prevent execution in the hope that 500 ms is enough wait time to delay scrolling.83 let waittime = $(selector).offset() !== undefined ? 0 : 500;8485 setTimeout(function () {8687 try {8889 let offset = $(selector).offset().top - $(target).offset().top;9091 $(target).scrollTop(offset);92 }93 catch (error) {94 console.log(error);95 }96 }, waittime);97 }98 }99 catch (error) {100 console.log(error);101 }102 });103 }104 catch (error) {105 console.log(error);106 }107 }108109 return false;110}111112function onScrollContent() {113114 let content = $(makeSelector('content'));115 let button = $('.jump-top-button');116117 if (content && button) {118119 if ($(content).scrollTop() > 20) {120121 $(button).show();122123 } else {124125 $(button).hide();126 }127 }128129 return false;130}131132function onJumpTop() {133134 let content = $(makeSelector('content'));135136 if (content) {137 $(content).scrollTop(0);138 }139140 return false;141}142143function copyToClipboard(selector) {144145 try {146147 var $temp = $("<textarea>");148 $("body").append($temp);149 $temp.val($(makeSelector(selector)).text()).select();150 document.execCommand("copy");151 $temp.remove();152 }153 catch (error) {154 console.log(error);155 }156157 return false; ...

Full Screen

Full Screen

createMakeSelector.js

Source:createMakeSelector.js Github

copy

Full Screen

1import { createSelector } from 'reselect'2import invariant from 'invariant'3import isFunction from 'lodash/isFunction'4import isString from 'lodash/isString'5import get from 'lodash/get'6import isArray from 'lodash/isArray'7import isEmpty from 'lodash/isEmpty'8import isNil from 'lodash/isNil'9import startsWith from 'lodash/startsWith'10import { defineFunctionName } from 'reacticoon/utils'11// TODO: unit test12const createPropGetter = (propPath, defaultValue) => (_state, props) =>13 props && get(props, propPath, defaultValue)14// TODO: unit test15const getSelectorNameWithMake = name => {16 return `make${name.charAt(0).toUpperCase()}${name.slice(1)}`17}18const createMakeSelector = (19 selectorName,20 selectorsParam = [],21 propsParam = [],22 selector,23 debugMode = false24) => () => {25 invariant(!isEmpty(selectorName), `createMakeSelector: Missing selector name`)26 invariant(27 !startsWith(selectorName, 'make'),28 `Make selector name must not start with 'make' ${name}`29 )30 invariant(!isEmpty(selectorsParam) || isFunction(selectorsParam), `createMakeSelector: Missing props params`)31 invariant(!isNil(selector), `createMakeSelector: Missing selector param`)32 // generate props selectors. Prop selector can be in multiple forms:33 // - a function: prop => prop.myVar34 // - a string path: 'myVar'35 // - an array: [ 'myVar', 'default value' ]36 // - an object: [ path: 'myVar', defaultValue: 'default value' ]37 const propsSelectors = (isFunction(propsParam) ? [ propsParam ] : propsParam).map(propParam => {38 if (isString(propParam)) {39 return createPropGetter(propParam, null)40 }41 if (isFunction(propParam)) {42 return propParam43 }44 if (isArray(propParam)) {45 invariant(46 propParam.length === 2,47 `Invalid prop param as array. Must follow [ path, defaultValue ]`48 )49 // handle:50 // ["path", getPath]51 if (isFunction(propParam[1])) {52 return propParam[1]53 }54 // handle: 55 // ["path", "myPath"]56 return createPropGetter(propParam[0], propParam[1])57 }58 if (isObject(propParam) && propParam.path && propParam.defaultValue) {59 return createPropGetter(propParam.path, propParam.defaultValue)60 }61 invariant(false, `Invalid prop param: ${propParam}`)62 })63 const propsSelector = createSelector(propsSelectors, (...props) => {64 return props65 })66 const finalSelectors = [67 propsSelector, 68 ...(isFunction(selectorsParam) ? selectorsParam() : selectorsParam)69 ]70 selector.__FROM_CREATE_MAKE_SELECTOR = true71 selector.__IS_SELECTOR = true72 selector.__NAME = selectorName73 defineFunctionName(selector, selectorName)74 const makeSelector = createSelector(finalSelectors, (props, ...data) => {75 const selectorResult = selector.apply(null, [ ...data, ...props ])76 if (debugMode) {77 const groupName = `[make selector] ${selectorName} called with arguments:`78 console.group(groupName)79 console.log(data)80 console.info({ selectorResult })81 console.groupEnd(groupName)82 }83 return selectorResult84 })85 makeSelector.__IS_MAKE_SELECTOR = true86 makeSelector.__NAME = getSelectorNameWithMake(selectorName)87 defineFunctionName(makeSelector, makeSelector.__NAME)88 return makeSelector89}...

Full Screen

Full Screen

connected-dimension-publisher.spec.js

Source:connected-dimension-publisher.spec.js Github

copy

Full Screen

...9 shouldPublish: true,10};11describe('Dimension publisher - connected', () => {12 it('should return the default props when not requested to publish dimensions', () => {13 const selector = makeSelector();14 const result: MapProps = selector.resultFunc(15 'DEFAULT',16 null,17 );18 expect(result).to.deep.equal(defaultMapProps);19 });20 it('should return the default props when the type being requested does not match the current publisher', () => {21 const selector = makeSelector();22 const result: MapProps = selector.resultFunc(23 'MY_TYPE',24 'SOME_OTHER_TYPE',25 );26 expect(result).to.deep.equal(defaultMapProps);27 });28 it('should return that it should publish when the requested type matches', () => {29 const selector = makeSelector();30 const result: MapProps = selector.resultFunc(31 'MY_TYPE',32 'MY_TYPE',33 );34 expect(result).to.deep.equal(shouldPublishMapProps);35 });36 it('should not break memoization on multiple do not publish results', () => {37 const selector = makeSelector();38 // nothing requested39 const result1: MapProps = selector.resultFunc(40 'MY_TYPE',41 null,42 );43 const result2: MapProps = selector.resultFunc(44 'MY_TYPE',45 null,46 );47 // something else requested48 const result3: MapProps = selector.resultFunc(49 'MY_TYPE',50 'NOT_MY_TYPE',51 );52 const result4: MapProps = selector.resultFunc(53 'MY_TYPE',54 'ANOTHER_TYPE_THAT_IS_NOT_MINE',55 );56 // correct result returned?57 expect(result1).to.deep.equal(defaultMapProps);58 // checking object equality59 expect(result1).to.equal(result2);60 expect(result2).to.equal(result3);61 expect(result3).to.equal(result4);62 });63 it('should not break memoization across multiple selectors', () => {64 const shouldPublishSelector = makeSelector();65 const noPublishSelector = makeSelector();66 const shouldPublish1: MapProps = shouldPublishSelector.resultFunc(67 'MY_TYPE',68 'MY_TYPE',69 );70 const noPublish1: MapProps = noPublishSelector.resultFunc(71 'MY_TYPE',72 'NOT_MY_TYPE',73 );74 const shouldPublish2: MapProps = shouldPublishSelector.resultFunc(75 'MY_TYPE',76 'MY_TYPE',77 );78 const noPublish2: MapProps = noPublishSelector.resultFunc(79 'MY_TYPE',...

Full Screen

Full Screen

makeSelector.test.js

Source:makeSelector.test.js Github

copy

Full Screen

1import { shallow, mount } from 'enzyme';2import MakeSelector from './makeSelector';3import { getAvailableMakes } from '../../actions/actions';4import { BrowserRouter as Router } from 'react-router-dom';5import { act } from "react-dom/test-utils";6import toJson from 'enzyme-to-json';7jest.mock("../../actions/actions", () => ({ getAvailableMakes: jest.fn() }));8let makes;9let wrapper;10beforeEach(() => {11 makes = [12 "Hyundai", "Ford"13 ]14})15describe('<MakeSelector />', () => {16 describe('when component initalizes', () => {17 it('should initalize to loading', () => {18 const test = shallow(<Router><MakeSelector /></Router>);19 expect(toJson(test)).toMatchSnapshot();20 });21 });22 describe('when component loads', () => {23 it('should render makes with images', async () => {24 getAvailableMakes.mockImplementationOnce(() => Promise.resolve(makes));25 await act(async () => {26 wrapper = mount(<Router><MakeSelector /></Router>);27 });28 wrapper.update();29 expect(toJson(wrapper)).toMatchSnapshot();30 expect(wrapper.find('Link').length).toBe(2);31 })32 });33 describe('when the api call fails', () => {34 it('should render a ErrorDisplay', async () => {35 getAvailableMakes.mockImplementationOnce(() => Promise.resolve(["Error", new Error("Generic Failure")]));36 await act(async () => {37 wrapper = mount(<Router><MakeSelector /></Router>);38 });39 wrapper.update();40 expect(toJson(wrapper)).toMatchSnapshot();41 expect(wrapper.find('ErrorDisplay').length).toBe(1);42 })43 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const makeSelector = require('./make-selector.js');4 const selector = makeSelector('button', 'Start');5 await t.click(selector);6});7const makeSelector = (tag, text) => {8 return Selector(tag).withText(text);9};10module.exports = makeSelector;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const makeSelector = Selector((selector, ...args) => {4 var el = document.querySelector(selector);5 for(var i = 0; i < args.length; i++) {6 el = el.children[args[i]];7 }8 return el;9 });10 const radio = makeSelector('form', 2, 1, 1);11 .click(radio)12 .expect(radio.checked).ok()13 .typeText('#developer-name', 'Peter Parker')14 .click('#submit-button')15 .expect(Selector('#article-header').innerText).eql('Thank you, Peter Parker!');16});17import { Selector } from 'testcafe';18test('My first test', async t => {19 const makeSelector = Selector((selector, ...args) => {20 var el = document.querySelector(selector);21 for(var i = 0; i < args.length; i++) {22 el = el.children[args[i]];23 }24 return el;25 });26 const radio = makeSelector('form', 2, 1, 1);27 .click(radio)28 .expect(radio.checked).ok()29 .typeText('#developer-name', 'Peter Parker')30 .click('#submit-button')31 .expect(Selector('#article-header').innerText).eql('Thank you, Peter Parker!');32});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My test', async t => {3 const makeSelector = selector => Selector(selector).addCustomMethods({4 });5 const makeSelector = selector => Selector(selector).addCustomMethods({6 });7 const makeSelector = selector => Selector(selector).addCustomMethods({8 });9 const makeSelector = selector => Selector(selector).addCustomMethods({10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2const makeSelector = require('testcafe-react-selectors').makeSelector;3const reactSelector = makeSelector();4const button = reactSelector('Button');5test('My test', async t => {6 await t.click(button);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import makeSelector from './selector';3const input = Selector(makeSelector('input'));4const button = Selector(makeSelector('button'));5test('My test', async t => {6 .typeText(input, 'Peter Parker')7 .click(button);8});9declare function makeSelector (name: string): string;10module.exports = function makeSelector (name) {11 return `[data-test=${name}]`;12};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { makeSelector } from './selector.js';3const selector = makeSelector('div');4test('My first test', async t => {5 .typeText('#developer-name', 'John Smith')6 .click('#submit-button')7 .expect(Selector(selector).innerText).eql('Thank you, John Smith!');8});9export function makeSelector (selector) {10 return selector;11}

Full Screen

Using AI Code Generation

copy

Full Screen

1import {Selector} from 'testcafe';2import {makeSelector} from 'testcafe';3const selector = makeSelector('selectorName');4import {Selector} from 'testcafe';5import {makeSelector} from 'testcafe';6const selector = makeSelector('selectorName');7import {Selector} from 'testcafe';8import {makeSelector} from 'testcafe';9const selector = makeSelector('selectorName');10import {Selector} from 'testcafe';11import {makeSelector} from 'testcafe';12const selector = makeSelector('selectorName');13import {Selector} from 'testcafe';14import {makeSelector} from 'testcafe';15const selector = makeSelector('selectorName');16import {Selector} from 'testcafe';17import {makeSelector} from 'testcafe';18const selector = makeSelector('selectorName');19import {Selector} from 'testcafe';20import {makeSelector} from 'testcafe';21const selector = makeSelector('selectorName');22import {Selector} from 'testcafe';23import {makeSelector} from 'testcafe';24const selector = makeSelector('selectorName');25import {Selector} from 'testcafe';26import {makeSelector} from 'test

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { makeSelector } from 'testcafe-react-selectors';3const myidSelector = makeSelector('#myid');4test('MyTest', async t => {5 .click(myidSelector);6});7import { Selector } from 'testcafe';8import { makeSelector } from 'testcafe-react-selectors';9const myidSelector = makeSelector('#myid');10test('MyTest', async t => {11 .click(myidSelector);12});13import { Selector } from 'testcafe';14import { makeSelector } from 'testcafe-react-selectors';15const myidSelector = makeSelector('#myid');16test('MyTest', async t => {17 .click(myidSelector);18});19import { Selector } from 'testcafe';20import { makeSelector } from 'testcafe-react-selectors';21const myidSelector = makeSelector('#myid');22test('MyTest', async t => {23 .click(myidSelector);24});25import { Selector } from 'testcafe';26import { makeSelector } from 'testcafe-react-selectors';27const myidSelector = makeSelector('#myid');28test('MyTest', async t => {29 .click(myidSelector);30});31import { Selector } from 'testcafe';32import { makeSelector } from 'testcafe-react-selectors';33const myidSelector = makeSelector('#myid');34test('MyTest', async t => {35 .click(myidSelector);36});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful