Write test for Client Script by ATF

escanor
Giga Contributor

Hi,

Can we write a test for client side like a unit test ? If it can, can you guys show me an example for my client script below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	var ga = new GlideAjax('EmailValid');
	ga.addParam('sysparm_name','isEmailValid');
	ga.addParam('sysparm_id', newValue);
	ga.getXML(processCallback);
	
	function processCallback(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		if (answer == 'false') {
			var ga = new GlideAjax('CM_02');
			ga.addParam('sysparm_name','isMessage');
			ga.addParam('sysparm_id', 'email');
			ga.getXMLAnswer(function(CM02Answer){
				g_form.addErrorMessage(CM02Answer);
			});
			g_form.clearValue('email');
			setTimeout(function() {
				g_form.clearMessages();
			}, 2000);
		} else {
			return true;
		}
	}
}
2 REPLIES 2

Adam Rasmussen
Tera Contributor

Did you ever find a solution?  I'm looking for the effectively same thing.  I am going to dig into the server-side script test to see if I can replicate the functionality, but that's not the same as actually testing it.  In my case, the glide ajax updates the choice list in a SelectBox variable based on a group role.

Masha
Kilo Guru

 Adam , I believe you should be able to test the script functionality on the server side, but on the Client Side you might be able to check dropdown values by impersonating the qualified user and setting the drop down values one by one on the form .