<commit_before>import test from "tape";
import sinon from "sinon";
import * as Util from "../../../resources/js/common/utils";

test( 'addEventListener attaches the given listener to the given element for the given event', ( assert ) => {
	assert.equal(
		typeof Util.addEventListener,
		'function',
		'addEventListener SHOULD be a function.'
	);

	const $element = {
		attachEvent: sinon.spy()
	};

	const type = 'type';

	const listener = sinon.spy();

	Util.addEventListener( $element, type, listener );

	assert.equal(
		$element.attachEvent.callCount,
		1,
		'addEventListener SHOULD attach one event listener using IE8 methods for IE8 browsers.'
	);

	assert.equal(
		$element.attachEvent.calledWith( 'on' + type ),
		true,
		'addEventListener SHOULD attach the expected event listener using IE8 methods for IE8 browsers.'
	);

	// Reset spy.
	$element.attachEvent.reset();

	// Add IE8+ method.
	$element.addEventListener = sinon.spy();

	Util.addEventListener( $element, type, listener );

	assert.equal(
		$element.attachEvent.callCount,
		0,
		'addEventListener SHOULD NOT attach an event listener using IE8 methods for IE8+ browsers.'
	);

	assert.equal(
		$element.addEventListener.callCount,
		1,
		'addEventListener SHOULD attach one event listener using IE8+ methods for IE8+ browsers.'
	);

	assert.equal(
		$element.addEventListener.calledWith( type, listener ),
		true,
		'addEventListener SHOULD attach the expected event listener using IE8+ methods for IE8+ browsers.'
	);

	assert.end();
} );

test( 'setLocation redirects the user to the given URL', ( assert ) => {
	assert.equal(
		typeof Util.setLocation,
		'function',
		'setLocation SHOULD be a function.'
	);

	global.window = {
		location: {
			href: ''
		}
	};

	const url = 'url';

	Util.setLocation( url );

	assert.equal(
		global.window.location.href,
		url,
		'setLocation SHOULD redirect the user to the given URL.'
	);<commit_msg>Update test.<commit_after>import test from "tape";
import sinon from "sinon";
import * as Util from "../../../resources/js/common/utils";

test( 'addEventListener attaches the given listener to the given element for the given event', ( assert ) => {
	assert.equal(
		typeof Util.addEventListener,
		'function',
		'addEventListener SHOULD be a function.'
	);

	const $element = {
		attachEvent: sinon.spy()
	};

	const type = 'type';

	const listener = sinon.spy();

	Util.addEventListener( $element, type, listener );

	assert.equal(
		$element.attachEvent.callCount,
		1,
		'addEventListener SHOULD attach one event listener using IE8 methods for IE8 browsers.'
	);

	assert.equal(
		$element.attachEvent.calledWith( 'on' + type ),
		true,
		'addEventListener SHOULD attach the expected event listener using IE8 methods for IE8 browsers.'
	);

	// Reset spy.
	$element.attachEvent.reset();

	// Add IE8+ method.
	$element.addEventListener = sinon.spy();

	Util.addEventListener( $element, type, listener );

	assert.equal(
		$element.attachEvent.callCount,
		0,
		'addEventListener SHOULD NOT attach an event listener using IE8 methods for IE8+ browsers.'
	);

	assert.equal(
		$element.addEventListener.callCount,
		1,
		'addEventListener SHOULD attach one event listener using IE8+ methods for IE8+ browsers.'
	);

	assert.equal(
		$element.addEventListener.calledWith( type, listener ),
		true,
		'addEventListener SHOULD attach the expected event listener using IE8+ methods for IE8+ browsers.'
	);

	assert.end();
} );

test( 'reloadLocation reloads the current page', ( assert ) => {
	assert.equal(
		typeof Util.reloadLocation,
		'function',
		'reloadLocation SHOULD be a function.'
	);

	global.window = {
		location: {
			reload: sinon.spy()
		}
	};

	Util.reloadLocation();

	assert.equal(
		global.window.location.reload.callCount,
		1,
		'reloadLocation SHOULD reload the current page.'
	);

	assert.equal(
		global.window.location.reload.calledWith( true ),
		true,
		'reloadLocation SHOULD reload the current page via a GET request.'
	);

	assert.end();
} );

test( 'setLocation redirects the user to the given URL', ( assert ) => {
	assert.equal(
		typeof Util.setLocation,
		'function',
		'setLocation SHOULD be a function.'
	);

	global.window = {
		location: {
			href: ''
		}
	};

	const url = 'url';

	Util.setLocation( url );

	assert.equal(
		global.window.location.href,
		url,
		'setLocation SHOULD redirect the user to the given URL.'
	);
{'fraction_non_alphanumeric': 0.12168949771689498, 'fraction_numerical': 0.006621004566210046, 'mean_word_length': 3.8408839779005524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2462256', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1324, 'n_words': 416}