How to I check the contents of a functionality of a web component function using sinon? - ecmascript-6

I am relatively new to web components and testing them. How do I test the functionality of a function?
createObjForStartBusiness() {
this.financingObj = [];
if (this.dropDownValue === common.ONE_YEAR_OR_LESS) {
if (this.ammountEntered >= 1250 && this.ammountEntered <= common.MAX_ALLOWED_VALUE) {
this.financingObj.push(this.createFinancingStructure('BusinessLine'));
}
if (this.ammountEntered >= 25000 && this.ammountEntered <= common.MAX_ALLOWED_VALUE) {
this.financingObj.push(this.createFinancingStructure('Opticash'));
}
} else if (this.dropDownValue === common.OVER_ONE_YEAR) {
if (this.ammountEntered >= 2000 && this.ammountEntered <= 999999) {
this.financingObj.push(this.createFinancingStructure('BusinessLoan'));
}
if (this.ammountEntered >= 10000 && this.ammountEntered <= common.MAX_ALLOWED_VALUE) {
this.financingObj.push(this.createFinancingStructure('Leasing'));
}
if (this.ammountEntered >= 250000 && this.ammountEntered <= common.MAX_ALLOWED_VALUE) {
this.financingObj.push(this.createFinancingStructure('InvestmentLoan'));
}
}
}
This is the function. Any help will be greatly appreciated.

Related

Encountering an error while attempting to create a game

I'm trying to create a crossword puzzle game using Actionscript 3.0 in Adobe
Animate. For the game coding, I followed an online tutorial and now I'm encountering an error. The error occurs whenever I'm in the actual game scene, no errors are encountered on the home page or instruction page. can anyone help me? my coding skills are below basic.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at CROSSWORD_CODE_fla::MainTimeline/entFrame().
stop();
quitbtn.addEventListener(MouseEvent.CLICK, quitt);
function quitt(evt: MouseEvent): void {
gotoAndStop("start");
}
var hippopotamus: Number = 0;
var horse: Number = 0;
var eel: Number = 0;
var frog: Number = 0;
var ant: Number = 0;
var turtle: Number = 0;
var tiger: Number = 0;
var bird: Number = 0;
var penguin: Number = 0;
var orca: Number = 0;
var octopus: Number = 0;
var owl: Number = 0;
var snail: Number = 0;
var duck: Number = 0;
var kangaroo: Number = 0;
var iguana: Number = 0;
var ALLwords:Number = 0;
var Total:Number = 0;
{
stage.addEventListener(Event.ENTER_FRAME, entFrame);
function entFrame(evt:Event):void {
if ((hypoH.text == ("h").toString())
&& (hypo1.text == ("i").toString())
&& (hypoP.text == ("p").toString())
&& (hypoP2.text == ("p").toString())
&& (hypoO.text == ("o").toString())
&& (hypoP3.text == ("p").toString())
&& (hypoO2.text == ("o").toString())
&& (hypoT.text == ("t").toString())
&& (hypoA.text == ("a").toString())
&& (hypoM.text == ("m").toString())
&& (hypoU.text == ("u").toString())
&& (hypoS.text == ("s").toString()))
{
hippopotamus = 1;
trace("hippopotamus");
}
}
{
if ((hrsO.text == ("o").toString())
&& (hrsR.text == ("r").toString())
&& (hrsS.text == ("s").toString())
&& (hrsE.text == ("e").toString()))
{
horse = 1;
trace("horse");
}
}
{
if ((eelE.text == ("e").toString())
&& (eel1.text == ("l").toString()))
{
eel = 1;
trace("eel");
}
}
{
if ((penP.text == ("p").toString())
&& (penE.text == ("e").toString())
&& (penN.text == ("n").toString())
&& (penG.text == ("g").toString())
&& (penU.text == ("u").toString())
&& (pen1.text == ("i").toString())
&& (penN2.text == ("n").toString()))
{
penguin = 1;
trace("penguin");
}
}
{
if ((brdB.text == ("b").toString())
&& (brdR.text == ("r").toString())
&& (brdD.text == ("d").toString()))
{
bird = 1;
trace("bird");
}
}
{
if ((octO.text == ("o").toString())
&& (octC.text == ("c").toString())
&& (octT.text == ("t").toString())
&& (octO2.text == ("0").toString())
&& (octP.text == ("p").toString())
&& (octU.text == ("u").toString()))
{
octopus = 1;
trace("octopus");
}
}
{
if ((orcR.text == ("r").toString())
&& (orcC.text == ("c").toString())
&& (orcA.text == ("a").toString()))
{
orca = 1;
trace("orca");
}
}
{
if ((owlO.text == ("o").toString())
&& (owlW.text == ("w").toString()))
{
owl = 1;
trace("owl");
}
}
{
if ((nailS.text == ("s").toString())
&& (nailA.text == ("a").toString())
&& (nail1.text == ("i").toString())
&& (nailL.text == ("l").toString()))
{
snail = 1;
trace("snail");
}
}
{
if ((dkD.text == ("d").toString())
&& (dkU.text == ("u").toString())
&& (dkC.text == ("c").toString())
&& (dkK.text == ("k").toString()))
{
duck = 1;
trace("duck");
}
}
{
if ((groA.text == ("a").toString())
&& (groN.text == ("n").toString())
&& (groG.text == ("g").toString())
&& (groA2.text == ("a").toString())
&& (groR.text == ("r").toString())
&& (groO.text == ("o").toString()))
{
kangaroo = 1;
trace("kangaroo");
}
}
{
if ((frgF.text == ("f").toString())
&& (frgR.text == ("r").toString())
&& (frgG.text == ("g").toString()))
{
frog = 1;
trace("frog");
}
}
{
if ((ignG.text == ("g").toString())
&& (ignU.text == ("u").toString())
&& (ignA.text == ("a").toString())
&& (ignN.text == ("n").toString()))
{
iguana = 1;
trace("iguana");
}
}
{
if ((antA.text == ("a").toString())
&& (antN.text == ("n").toString()))
{
ant = 1;
trace("ant");
}
}
{
if ((trtT.text == ("t").toString())
&& (trtU.text == ("u").toString())
&& (trtR.text == ("r").toString())
&& (trtT2.text == ("t").toString())
&& (trtL.text == ("l").toString()))
{
turtle = 1;
trace("turtle");
}
}
{
if ((tgr1.text == ("i").toString())
&& (tgrG.text == ("g").toString())
&& (tgrE.text == ("e").toString()))
{
tiger = 1;
trace("tiger");
}
}
ALLwords = hippopotamus + horse + eel + frog + tiger + octopus + penguin + bird + orca +
turtle + duck + snail + ant + kangaroo + iguana + owl;
Total = 16 - ALLwords;
if (Total == 0)
{
trace("Gameover");
}
incorrectTXT.text = ("you have" + Total+ " incorrect words remaining").toString();
}

DataTables age range filter is not working

I got a problem when filtering the age range in DataTables. I am using DataTables ver 1.10.10. I am confused because when I started to build the code it was working properly, but when I tested again, it's not working anymore.
I hope anyone could tell me where I am missing since it is a very noob question.
Here is my javascript
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var from = parseInt( $('#ageFrom').val(), 10 );
var to = parseInt( $('#ageTo').val(), 10);
var age = parseFloat( data[3] ) || 0;
if ( (isNaN(from) && isNaN(to)) ||
(isNaN(from) && age <= to) ||
(from <= age && isNaN(to)) ||
(from <= age && age <= to) )
{
return true;
}
return false;
}
);
$('#ageFrom, #ageTo').on('change keyup', function() {
if ($('#ageFrom').val() == "" || $('#ageTo').val() == "") {
table.draw()
}
else {
table.draw();
}
});
Thanks in advance!
Cheers

Angular one of the conditions is to check the password field for certain characters only [! # $% & *]

checkParams(event) {
if (event.length > 8 && event.length <= 30) {
this.passLength = true;
} else {
this.passLength = false;
}
//quantity check
if (event.search(/[0-9]/) > -1) {
this.passNumbers = true;
} else {
this.passNumbers = false;
}
//number check
if (event.search(/[!#$%&*]+/) > -1) {
this.passSpecial = true;
} else {
this.passSpecial = false;
}
//character check
if (event.search(/[a-z].*[A-Z]|[A-Z].*[a-z]/) > -1) {
this.passUpper = true;
} else {
this.passUpper = false;
}
//check upper case
if (event.search(/^\S*$/)) {
this.passSpace = false;
} else {
this.passSpace = true;
}
//check whitespace
if (event.search(/[!#$%&*]+/) > -1 && event.search(/[~`#^()_={}[\]:;,.<>+\/?-]+/) <= -1) {
this.passSpecial = true;
} else {
this.passSpecial = false;
}
You may try using the following single pattern:
^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!#$%&*]).{9,30}$
Your Angular JS code:
if (event.search(/^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!#$%&*]).{9,30}$/) > -1) {
this.passValid = true;
}
else {
this.passValid = false;
}

Page refresh - Enter, arrow keys not working in table cells

This problem is happening both in IE and Chrome.
This is an HTML 5 with Angular JS 4 application. I am using TypeScript. My main aim in a table row I need to make enter, right, and left arrows of keyboard work and set focus on corresponding table cells
I have a page which has a dropdown. It has names of students. I also have a table with single row like below with multiple columns
When I launch by default a student is selected in dropdown which populates students details in table. I made each cell in row as editable. So when user clicks on any cell in the row and presses enter key I move to next cell and so the functions for right arrow and left arrow are working fine on first load/launch of my application.
But when I change another student from my dropdown, I refresh the page to show new selected student details. From this point if I select a cell in the row my enter key, left,
and right arrows are not working. Please see below for my code
Thank you very much in advance.
<table>
<tr>
<td *ngFor="let item of student.classes " >
<!-- I need to use div to make cell editable in IE. -->
<div name='TotalDistributableQtyCell' [id]="item.cellId"
[contentEditable]='!isDisabled' [textContent]="item.value"
(keydown)="onKeydown($event, item)"
style="line-height:1.8em;">{{item.value}}</div>
</td>
</tr>
<table>
MyComponent.ts
totalDistributableQtyCells: HTMLElement[];
ngAfterViewChecked() {
const distCells = document.getElementsByName('TotalDistributableQtyCell');
if(distCells !== null && distCells !== undefined && distCells.length > 0) {
if(this.totalDistributableQtyCells === null || this.totalDistributableQtyCells === undefined) {
this.totalDistributableQtyCells = [];
}
for ( let i = 0 ; i < distCells.length; i++) {
const index = this.totalDistributableQtyCells.findIndex( x => x.id !== undefined && x.id === distCells[i].id);
if(index === -1) {
this.totalDistributableQtyCells.push(distCells[i]);
}
}
}
}
private onKeydown(event: any, item: ITotalDistributableQuantity) {
const key_code = (window.event) ? event.keyCode : event.which;
if (this.deviceInfo.browser === 'ie') {
console.log('ie: event.keyCode ' + event.keyCode);
switch(event.keyCode.toString()) {
case '13': //enter
event.preventDefault ? event.preventDefault() : (event.returnValue = false);
if(item.sequenceNumber === 2) {
this.totalDistributableQtyCells[1].focus();
} else if ( item.sequenceNumber === this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[0].focus();
} else if (item.sequenceNumber > 2 && item.sequenceNumber < this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[item.sequenceNumber - 1].focus();
}
break;
case '39': //right
event.preventDefault ? event.preventDefault() : (event.returnValue = false);
if(item.sequenceNumber === 2) {
this.totalDistributableQtyCells[1].focus();
} else if ( item.sequenceNumber === this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[0].focus();
} else if (item.sequenceNumber > 2 && item.sequenceNumber < this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[item.sequenceNumber - 1].focus();
}
break;
case '37': //left
event.preventDefault ? event.preventDefault() : (event.returnValue = false);
if(item.sequenceNumber === 2) {
this.totalDistributableQtyCells[this.totalDistributableQtyCells.length - 1 ].focus();
} else if ( item.sequenceNumber === this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[this.totalDistributableQtyCells.length - 2 ].focus();
} else if (item.sequenceNumber > 2 && item.sequenceNumber < 11) {
this.totalDistributableQtyCells[item.sequenceNumber - 3].focus();
}
break;
}
}else if ( this.deviceInfo.browser === 'chrome') {
console.log('chrome: event.key ' + event.key);
switch(event.key) {
case 'Enter':
event.preventDefault();
if(item.sequenceNumber === 2) {
this.totalDistributableQtyCells[1].focus();
} else if ( item.sequenceNumber === this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[0].focus();
} else if (item.sequenceNumber > 2 && item.sequenceNumber < this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[item.sequenceNumber - 1].focus();
}
break;
case 'ArrowRight':
event.preventDefault();
if(item.sequenceNumber === 2) {
this.totalDistributableQtyCells[1].focus();
} else if ( item.sequenceNumber === this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[0].focus();
} else if (item.sequenceNumber > 2 && item.sequenceNumber < this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[item.sequenceNumber - 1].focus();
}
break;
case 'ArrowLeft':
event.preventDefault();
if(item.sequenceNumber === 2) {
this.totalDistributableQtyCells[this.totalDistributableQtyCells.length - 1 ].focus();
} else if ( item.sequenceNumber === this.totalDistributableQtyCells.length + 1) {
this.totalDistributableQtyCells[this.totalDistributableQtyCells.length - 2 ].focus();
} else if (item.sequenceNumber > 2 && item.sequenceNumber < 11) {
this.totalDistributableQtyCells[item.sequenceNumber - 3].focus();
}
break;
}
}
}

Nested script in action script 3

Okay someone could really help me with this I've been working REALLY hard to get this working up until this point. One last thing is I need is the nextquestion1 function to bring me to the last from of my application.
I click on my button nextQuestion_btn to take me to one of the labled frames I have. I click on it and nothing happens. Also there is a lot of missing code in between the two Event Listener's , just so you know.
So...How can I make this code so I can trigger the next frame with the button?
stage.addEventListener(Event.CHANGE, checkTotal1000)
function checkTotal1000(e:Event){
var tech:Number = parseInt(tech_txt.text);
var med:Number = parseInt(med_txt.text);
var space:Number = parseInt(space_txt.text);
var genetic:Number = parseInt(ge_txt.text);
var worldComp:Number = parseInt(worldComp_txt.text);
var mars:Number = parseInt(mars_txt.text);
var worldColab:Number = parseInt(worldColab_txt.text);
var nothing:Number = parseInt(nothing_txt.text);
var zombieApocFinal:Number = zombieApoc + genetic;
var robotApocFinal:Number = robotApoc+ tech;
var plagueFinal:Number = plague + med;
var asteroidFinal:Number = asteroid + mars;
var iceAgeFinal:Number = iceAge + nothing;
var aliensFinal:Number = aliens + space;
var nukeWarFinal:Number = nukeWar + worldComp;
//var happyEverAfterFinal:Number = ;
trace(aliensFinal);
var total1000:Number = tech + med + space +
worldComp + mars + genetic + worldColab + nothing;
nextQuestion_btn.addEventListener(MouseEvent.MOUSE_DOWN, nextQuestion1)
function nextQuestion1(e:MouseEvent){
if(tech && med && space && genetic && worldComp
&& mars && worldColab && nothing == 125){
gotoAndStop(7);
}
if(robotApocFinal > zombieApocFinal && plagueFinal &&
asteroidFinal && iceAgeFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("Robot");
}
else if(zombieApocFinal > robotApocFinal && plagueFinal &&
asteroidFinal && iceAgeFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("Zombie");
}
else if( plagueFinal > zombieApocFinal && robotApocFinal &&
asteroidFinal && iceAgeFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("Plague");
}
else if( asteroidFinal > zombieApocFinal && robotApocFinal &&
plagueFinal && iceAgeFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("Asteroid");
}
else if( iceAgeFinal > zombieApocFinal && robotApocFinal &&
plagueFinal && asteroidFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("IceAge");
}
else if( aliensFinal > zombieApocFinal && robotApocFinal &&
plagueFinal && asteroidFinal && iceAgeFinal &&
nukeWarFinal){
gotoAndStop("Aliens");
}
else if( nukeWarFinal > zombieApocFinal && robotApocFinal &&
plagueFinal && asteroidFinal && iceAgeFinal &&
aliensFinal){
gotoAndStop("Nuke");
}
}
}
Apparently you are using binary flags, but you use && operator which only works with booleans. This way if either of your ints is 0, no condition is satisfied. You apparently want to trigger the gotoAndStop() if one of the ints is greater than others. For this you can use the following code:
var bestFinal:int=Math.max(asteroidFinal, zombieApocFinal, robotApocFinal,
plagueFinal, iceAgeFinal, aliensFinal, nukeWarFinal);
if (bestFinal==asteroidFinal) {...}
else if (bestFinal==zombieApocFinal) {...}
...
If you are about to test if one var is greater than all the others, you cannot use what you've written, instead you use either Math.max() and check for equality, or you write many comparations and unite them via &&, like this:
if ((asteroidFinal > zombieApocFinal) && (asteroidFinal > robotApocFinal) &&
(asteroidFinal > plagueFinal) && (asteroidFinal > iceAgeFinal) &&
(asteroidFinal > aliensFinal) && (asteroidFinal > nukeWarFinal))