I am trying to write some unit tests for the following JS file, I am really struggling as none of them actually return values, plus I am new to unit testing, some assistance and example tests would be extremely useful as I am really struggling at the moment.
//FILE 1 --------------------------------------------------
// Declare all the product prices in an associative array
var prices = new Array();
prices["unflav-1"] = 12.69;
prices["flav-1"] = 15.79;
prices["unflav-2.5"] = 26.49;
prices["flav-2.5"] = 31.19;
prices["unflav-5"] = 46.79;
prices["flav-5"] = 57.19;
// Declare the colours for flavours in an associative array
var flavourColours = new Array();
flavourColours["Unflavoured"] = {
background: "#ead9ed",
border: "#8c828e"
};
flavourColours["Chocolate"] = {
background: "#D2691E",
border: "#2a1506"
};
flavourColours["Banana"] = {
background: "#FFFF00",
border: "#666600"
};
flavourColours["Strawberry"] = {
background: "#FF0000",
border: "#7f0000"
};
flavourColours["Cookies & Cream"] = {
background: "#B57E1D",
border: "#48320b"
};
//
function formChange() {
// get value and name for flavour, package and amount
var flavourElem = document.getElementById('flavour-select');
var flavourValue = flavourElem.value;
var flavour = flavourElem.options[flavourElem.selectedIndex].text;
var packageValue = document.getElementById('package-select').value;
var amountValue = document.getElementById('amount-select').value;
// lookup price in array then change the price on screen
document.getElementById('product-price').innerHTML = prices[flavourValue + '-' + amountValue];
// update graphical visualisation for flavour and amount
document.getElementById('chosen-flavour-colour').style.backgroundColor = flavourColours[flavour].background;
var border = "3px solid " + flavourColours[flavour].border;
document.getElementById('chosen-flavour-colour').style.border = border;
document.getElementById('chosen-flavour-text').innerHTML = flavour;
var ref = "img/" + amountValue + "kg-weight.png";
document.getElementById('chosen-weight-visual').style.backgroundImage = "url(" + ref + ")";
}
Aucun commentaire:
Enregistrer un commentaire