define([
	'bacon',
	'jquery',
	'bitbucket/internal/widget/updating-section'
],
function (
	bacon,
	$,
	UpdatingSection
) {

	'use strict';

	var $el;
	var	templateStub;

	module('widget-updating-section', {
		setup: function () {
			$el = $("<div><div class='replacement-placeholder'>XX</div></div>");
			templateStub = sinon.stub();
		}
	});

	test('is present', function() {
		ok(UpdatingSection);
	});

	test('updates when an event occurs', function () {
		var testValue = { key: 'value' };
		var testStream = bacon.once(testValue);

		var updatingSection = new UpdatingSection($el, testStream, templateStub);

		propEqual(templateStub.args[0][0], testValue, "Expected Soy template to be passed value from EventStream");
	});

	test('applies context values on update', function () {
		var testValue = { key: 'value' };
		var testStream = bacon.once(testValue);
		var context = { contextKey: 'contextValue' };

		var updatingSection = new UpdatingSection($el, testStream, templateStub, {
			context: context
		});

		updatingSection.updateValue(testValue);

		propEqual(templateStub.args[0][0], {
			key: 'value',
			contextKey: 'contextValue'
		}, "Expected Soy template to be passed value merged with context");

        templateStub.reset();
        updatingSection.updateValue(testValue);
        ok(!templateStub.called, "Expected the template to not have been called when the same template parameters are passed");
	});
});