Beispiel #1
0
QUnit.test("type converters", function() {

	var Typer = function(date, string, number, bool, htmlbool, leaveAlone) {
		this.date = date;
		this.string = string;
		this.number = number;
		this.bool = bool;
		this.htmlbool = htmlbool;
		this.leaveAlone = leaveAlone;
	};

	define(Typer.prototype, {
		date: {
			type: 'date'
		},
		string: {
			type: 'string'
		},
		number: {
			type: 'number'
		},
		bool: {
			type: 'boolean'
		},
		htmlbool: {
			type: 'htmlbool'
		},
		leaveAlone: {
			type: '*'
		},
	});

	var obj = {};

	var t = new Typer(
		1395896701516,
		5,
		'5',
		'false',
		"",
		obj
	);

	QUnit.ok(t.date instanceof Date, "converted to date");

	QUnit.equal(t.string, '5', "converted to string");

	QUnit.equal(t.number, 5, "converted to number");

	QUnit.equal(t.bool, false, "converted to boolean");

	QUnit.equal(t.htmlbool, true, "converted to htmlbool");

	QUnit.equal(t.leaveAlone, obj, "left as object");

	t.number = '15';

	QUnit.ok(t.number === 15, "converted to number");

});
Beispiel #2
0
QUnit.test("Click Radio Buttons", function () {

	var radio1 = 0,
		radio2 = 0;

	st.g("radio1")
		.checked = false;
	//make sure changes are called
	st.bind(st.g("radio1"), "change", function (ev) {
		radio1++;
	});
	st.bind(st.g("radio2"), "change", function (ev) {
		radio2++;
	});

	syn.trigger(st.g("radio1"), "click", {});

	QUnit.equal(radio1, 1, "radio event");
	QUnit.ok(st.g("radio1")
		.checked, "radio checked");

	syn.trigger(st.g("radio2"), "click", {});

	QUnit.equal(radio2, 1, "radio event");
	QUnit.ok(st.g("radio2")
		.checked, "radio checked");

	QUnit.ok(!st.g("radio1")
		.checked, "radio unchecked");

});
Beispiel #3
0
QUnit.test("extending DefineMap constructor functions (#18)", function(){
    var AType = DefineMap.extend("AType", { aProp: {}, aMethod: function(){} });

    var BType = AType.extend("BType", { bProp: {}, bMethod: function(){} });

    var CType = BType.extend("CType", { cProp: {}, cMethod: function(){} });

    var map = new CType();

    map.on("aProp", function(ev, newVal, oldVal){
        QUnit.equal(newVal, "PROP");
        QUnit.equal(oldVal, undefined);
    });
    map.on("bProp", function(ev, newVal, oldVal){
        QUnit.equal(newVal, "FOO");
        QUnit.equal(oldVal, undefined);
    });
    map.on("cProp", function(ev, newVal, oldVal){
        QUnit.equal(newVal, "BAR");
        QUnit.equal(oldVal, undefined);
    });

    map.aProp = "PROP";
    map.bProp = 'FOO';
    map.cProp = 'BAR';
    QUnit.ok(map.aMethod);
    QUnit.ok(map.bMethod);
    QUnit.ok(map.cMethod);
});
Beispiel #4
0
QUnit.test("extending DefineList constructor functions (#61)", function(){
  var AList = DefineList.extend('AList', { aProp: {}, aMethod: function(){} });
  var BList = AList.extend('BList', { bProp: {}, bMethod: function(){} });
  var CList = BList.extend('CList', { cProp: {}, cMethod: function(){} });

  var list = new CList([{},{}]);

  list.on("aProp", function(ev, newVal, oldVal){
      QUnit.equal(newVal, "PROP");
      QUnit.equal(oldVal, undefined);
  });
  list.on("bProp", function(ev, newVal, oldVal){
      QUnit.equal(newVal, "FOO");
      QUnit.equal(oldVal, undefined);
  });
  list.on("cProp", function(ev, newVal, oldVal){
      QUnit.equal(newVal, "BAR");
      QUnit.equal(oldVal, undefined);
  });

  list.aProp = "PROP";
  list.bProp = 'FOO';
  list.cProp = 'BAR';

  QUnit.ok(list.aMethod);
  QUnit.ok(list.bMethod);
  QUnit.ok(list.cMethod);
});
QUnit.test('MonthlyOSProject List basic test', () => {
  let osProject01 = new OSProject({
    _id: '1',
    name: 'DoneJS'
  });

  let osProject02 = new OSProject({
    _id: '2',
    name: 'CanJS'
  });

  let monthlyOSProject01 = new MonthlyOSProject({
    significance: 1,
    commissioned: true,
    osProjectRef: osProject01
  });

  let monthlyOSProject02 = new MonthlyOSProject({
    significance: 0,
    commissioned: false,
    osProjectRef: osProject02
  });

  let monthlyOSProjectsList = new MonthlyOSProject.List();
  monthlyOSProjectsList.push(monthlyOSProject01);
  monthlyOSProjectsList.push(monthlyOSProject02);

  QUnit.ok(monthlyOSProjectsList.has(osProject01), "has works as expected");
  QUnit.ok(monthlyOSProjectsList.getSignificance(osProject01) === 1, "getSignificance works as expected");
  QUnit.ok(monthlyOSProjectsList.commissioned.length === 1, "got the right amount of commissioned");
});
test("works with can-reflect", 8, function(){
	var b = new SimpleMap({ "foo": "bar" });
	// var c = new (SimpleMap.extend({
	// 	"baz": canCompute(function(){
	// 		return b.attr("foo");
	// 	})
	// }))({ "foo": "bar", thud: "baz" });

	QUnit.equal( canReflect.getKeyValue(b, "foo"), "bar", "get value");

	var handler = function(newValue){
		QUnit.equal(newValue, "quux", "observed new value");

		// Turn off the "foo" handler but "thud" should still be bound.
		canReflect.offKeyValue(b, "foo", handler);
	};
	QUnit.ok(!canReflect.isValueLike(b), "isValueLike is false");
	QUnit.ok(canReflect.isMapLike(b), "isMapLike is true");
	QUnit.ok(!canReflect.isListLike(b), "isListLike is false");

	QUnit.ok( !canReflect.keyHasDependencies(b, "foo"), "keyHasDependencies -- false");

	canReflect.onKeyValue(b, "foo", handler);
	// Do a second binding to check that you can unbind correctly.
	canReflect.onKeyValue(b, "baz", handler);

	b.attr("foo", "quux");

	QUnit.equal( canReflect.getKeyValue(b, "foo"), "quux", "bound value");
	// sanity checks to ensure that handler doesn't get called again.
	b.attr("foo", "thud");
	b.attr("baz", "quux");

});
Beispiel #7
0
QUnit.test("Works with checkboxes", function(){
	var template = stache("<input type='checkbox' {($checked)}='boolean-to-inList(item, list)' />");
	var map = new DefineMap({
		item: 2,
		list: new DefineList([ 1, 2, 3 ])
	});

	var frag = template(map);
	var input = frag.firstChild;

	QUnit.ok(input.checked, "it is initially checked");
	QUnit.equal(map.list.indexOf(2), 1, "two is in the list");

	input.checked = false;
	canEvent.trigger.call(input, "change");

	QUnit.equal(map.list.indexOf(2), -1, "No longer in the list");

	map.item = 3;
	QUnit.ok(input.checked, "3 is in the list");

	// Add something to the list
	map.item = 5;
	QUnit.ok(!input.checked, "5 is not in the list");

	map.list.push(5);
	QUnit.ok(input.checked, "Now 5 is in the list");

	map.item = 6;
	input.checked = true;
	canEvent.trigger.call(input, "change");

	QUnit.equal(map.list.indexOf(6), 3, "pushed into the list");
});
QUnit.test("Reflect.hasOwnKey", function(){
	var map = new SimpleMap({a: undefined, b: null, c: ""});

	QUnit.ok( canReflect.hasOwnKey(map,"a"), "undefined is a key");
	QUnit.ok( canReflect.hasOwnKey(map,"b"), "null is a key");
	QUnit.ok( canReflect.hasOwnKey(map,"c"), "empty string is a key");
	QUnit.ok( !canReflect.hasOwnKey(map,"d"), "no prop is not a key");
});
Beispiel #9
0
QUnit.test("basics", function(){
    var items = new DefineMap({ people: [{name: "Justin"},{name: "Brian"}], count: 1000 });
    QUnit.ok(items.people instanceof types.DefineList, "people is list");
    QUnit.ok(items.people.item(0) instanceof types.DefineMap, "1st object is Map");
    QUnit.ok(items.people.item(1) instanceof types.DefineMap, "2nd object is Map");
    QUnit.equal(items.people.item(1).name, "Brian", "2nd object's name is right");
    QUnit.equal(items.count, 1000, "count is number");
});
Beispiel #10
0
QUnit.test("passing a DefineList to DefineList (#33)", function(){
    var m = new DefineList([{},{}]);

    var m2 = new DefineList(m);
    QUnit.deepEqual(m.get(), m2.get());
    QUnit.ok(m[0] === m2[0], "index the same");
    QUnit.ok(m[1] === m2[1], "index the same");

});
Beispiel #11
0
	].forEach(function(Model){
		var instance = new Model();
		try {
			instance.__test_prop = 0;
			QUnit.ok(true, Model.name + " is unsealed");
		} catch(e) {
			QUnit.ok(false, Model.name + " is sealed when it should NOT be");
		}
	});
Beispiel #12
0
QUnit.test("passing a DefineMap to DefineMap (#33)", function(){
    var MyMap = DefineMap.extend({foo: "observable"});
    var m = new MyMap({foo: {}, bar: {}});

    var m2 = new MyMap(m);
    QUnit.deepEqual(m.get(), m2.get());
    QUnit.ok(m.foo === m2.foo, "defined props the same");
    QUnit.ok(m.bar === m2.bar, "expando props the same");

});
Beispiel #13
0
	setTimeout(function(){

		QUnit.ok(canRoute.url({}, true), "empty is true");
		QUnit.ok(canRoute.url({page: "recipe"}, true), "page:recipe is true");

		QUnit.ok(canRoute.url({page: "recipe", id: 5}, true), "number to string works");
		QUnit.ok(canRoute.url({page: "recipe", id: 6}, true), "not all equal");

		mockRoute.stop();
		QUnit.start();
	},200);
Beispiel #14
0
QUnit.test("Array shorthand uses #", function(){
    var MyMap = DefineMap.extend({
        "numbers": ["number"]
    });

    var map = new MyMap({numbers: ["1","2"]});
    QUnit.ok(map.numbers[0] === 1, "converted to number");

    map.numbers.set("prop", "4");
    QUnit.ok(map.numbers.prop === "4", "type left alone");
});
Beispiel #15
0
	obj.on("first", function(){
		canBatch.start();
		obj.dispatch("second");
		obj.dispatch("third");
		canBatch.stop();

		canBatch.flush();
		QUnit.ok(firstFired, "first fired");
		QUnit.ok(secondFired, "second fired");
		QUnit.ok(thirdFired, "third fired");
	});
	ContributionMonth.getList({}).then(function(contributionMonths) {

		// TODO: check if we need to test against `clientProjectRef.value`.
		QUnit.ok(contributionMonths[0].monthlyClientProjects[0].clientProjectRef._id === "1-Levis", 'contains a client project');
		var first = contributionMonths[0].monthlyOSProjects[0].osProjectRef._id,
			second = contributionMonths[0].monthlyClientProjects[0].monthlyClientProjectsOSProjects[0]._id;

		QUnit.ok(first, 'first exists');
		QUnit.ok(first === second, 'first and second are equal');

		done();
	}, function(err) {
Beispiel #17
0
    canReflect.onValue(mock,function(){
        QUnit.equal(canRoute.url({}, true), "#!&foo=bar&page=recipe&id=5", "empty");
        QUnit.ok(canRoute.url({page: "recipe"}, true), "page:recipe is true");

        QUnit.ok(canRoute.url({page: "recipe", id: 5}, true), "number to string works");
        QUnit.ok(canRoute.url({page: "recipe", id: 6}, true), "not all equal");

        setTimeout(function(){
            canRoute.urlData = oldUsing;
            QUnit.start();
        },20);

    });
Beispiel #18
0
	obj.on("first", function(ev, arg1, arg2){
		QUnit.equal(collecting.number, ev.batchNum, "same batch num");
		QUnit.equal(canBatch.dispatching(), collecting, "dispatching old collecting");
		QUnit.equal(arg1, 1, "first arg");
		QUnit.equal(arg2, 2, "second arg");

		collecting = canBatch.collecting();
		QUnit.ok(!collecting, "not collecting b/c we're not in a batch yet");
		obj.dispatch("second");
		collecting = canBatch.collecting();
		QUnit.ok(collecting, "forced a batch");
		QUnit.equal(secondFired, false, "don't fire yet, put in next batch");

	});
QUnit.test('MonthlyOSProject basic test', () => {
  let osProject = new OSProject({
    _id: 'qwe123',
    name: 'DoneJS'
  });

  let monthlyOSProject = new MonthlyOSProject({
    significance: 0,
    commissioned: false,
    osProjectRef: osProject
  });

  QUnit.ok(monthlyOSProject.osProjectRef._id === "qwe123", "osProjectRef _id is correct");
  QUnit.ok(monthlyOSProject.osProjectRef._value.name === "DoneJS", "osProjectRef name is correct");
});
				var checkLifecycleBindings = function(){
					var meta = vm[canSymbol.for("can.meta")];

					if( meta.handlers.get([]).length === 0 ) {
						QUnit.ok(true, "no bindings");
						start();
					} else {
						checkCount++;
						if (checkCount > 5) {
							QUnit.ok(false, "lifecycle bindings still existed after timeout");
							return start();
						}
						setTimeout(checkLifecycleBindings, 1000);
					}
				};
Beispiel #21
0
QUnit.test("If there is no list, treated as false", function(){
	var template = stache("<input type='checkbox' {($checked)}='boolean-to-inList(item, list)' />");
	var map = new DefineMap({
		item: 2,
		list: undefined
	});
	var frag = template(map);
	var input = frag.firstChild;

	QUnit.ok(!input.checked, "not checked because there is no list");

	input.checked = true;
	canEvent.trigger.call(input, "change");

	QUnit.ok(true, "no errors thrown");
});
QUnit.test("Components can be instantiated with templates", function() {
	var ComponentConstructor = Component.extend({
		tag: "new-instantiation-templates",
		view: "<can-slot name='messageInput' />"
	});

	var scopeVM = new DefineMap({
		message: "world"
	});
	var componentInstance = new ComponentConstructor({
		scope: scopeVM,
		templates: {
			messageInput: "<input value:bind='message' />"
		}
	});

	// Basics look correct
	var element = componentInstance.element;
	var inputElement = element.querySelector("input");
	QUnit.ok(inputElement, "template rendered");
	QUnit.equal(inputElement.value, "world", "input has correct value");

	// Updating the scopeVM should update the template
	scopeVM.message = "mundo";
	QUnit.equal(inputElement.value, "mundo", "input has correct value after updating scopeVM");
});
QUnit.asyncTest('async can immediately read', 4, function () {
	var canAsync = require("can-event/async/async");
	canAsync.async();

	var compute = require("can-compute");

	var first = compute("Justin");
	var last = compute("Meyer");

	var fullName = compute(function(){
		return first() + " " + last();
	});
	var firedEvents = false;
	fullName.on("change", function(ev, newVal, oldVal){
		QUnit.equal( newVal,  "Payal Shah", "change newVal");
		QUnit.equal( oldVal, "Justin Meyer", "change oldVal");
		firedEvents = true;
		QUnit.start();
	});

	first("Payal");
	last("Shah");

	QUnit.equal( fullName(),  "Payal Shah");
	QUnit.ok(firedEvents, "fired events");
});
Beispiel #24
0
QUnit.test("inline DefineList Type", function(){
    var M = DefineMap.extend("M",{
        id: "number"
    });

    var MyMap = DefineMap.extend({
        l: {Type: [M]}
    });

    var m = new MyMap({
        l: [{id: 5}]
    });

    QUnit.ok( m.l[0] instanceof M, "is instance" );
    QUnit.ok(m.l[0].id, 5, "correct props");
});
Beispiel #25
0
QUnit.test("#each throws error (can-stache-bindings#444)", function(){
    var list = new DefineList([
        {name: 'A'},
        {name: 'B'},
        {name: 'C'}
    ]);
    var data = new DefineMap({
        list: list,
        item : list[1]
    });

    var template = stache(

        "<div>"+
        // The space after }} is important here
            "{{#each list}} "+
            "{{^is(., ../item)}}"+
            "<div>{{name}}</div>"+
            "{{/is}}"+
            "{{/each}}"+
        "</div>");

    template(data);


    queues.batch.start();
    queues.mutateQueue.enqueue(function clearItemAndSplice() {

      this.item = null;
      this.list.splice(1, 1);
    }, data, []);
    queues.batch.stop();

    QUnit.ok(true, "no errors");
});
Beispiel #26
0
	Game.get({id: 1, populate: "teamRef"}).then(function(game){
		game.on("teamRef", handler);
		game.teamRef.on("value", handler);
		var teamRef = game.teamRef;
		QUnit.ok( teamRef.value instanceof Team);
		QUnit.equal(teamRef.value.name, "Cubs");
		QUnit.equal(teamRef.id, 2);

		Game.getList({}).then(function(games){
			QUnit.ok( games[0].teamRef === teamRef, "same team ref");
			QUnit.ok( games[2].teamRef === teamRef, "same team ref on a different object");
			QUnit.ok( teamRef.value instanceof Team);
			QUnit.equal(teamRef.id, 2);
			QUnit.equal(teamRef.value.name, "Cubs");
			QUnit.equal(games[1].teamRef.id, 3);

			QUnit.equal(games[0].teamRef.isResolved(), true);

			games[1].teamRef.on("value", function(ev, newVal){
				QUnit.ok(newVal instanceof Team);
				QUnit.equal(newVal.name, "Bears");
				QUnit.start();
			});

			QUnit.equal(games[1].teamRef.isResolved(), false);

		});
	}, function(error){
Beispiel #27
0
QUnit.test(".extend errors when re-defining a property (#117)", function(){

	var A = DefineMap.extend("A", {
	    foo: {
	        type: "string",
	        value: "blah"
	    }
	});


	A.extend("B", {
	    foo: {
	        type: "string",
	        value: "flub"
	    }
	});

	var C = DefineMap.extend("C", {
	    foo: {
	        get: function() {
	            return "blah";
	        }
	    }
	});


	C.extend("D", {
	    foo: {
	        get: function() {
	            return "flub";
	        }
	    }
	});
	QUnit.ok(true, "extended without errors");
});
Beispiel #28
0
QUnit.test("basics", function(){
	var collecting;
	var secondFired = false;
	var obj = assign({}, canEvent);
	obj.on("first", function(ev, arg1, arg2){
		QUnit.equal(collecting.number, ev.batchNum, "same batch num");
		QUnit.equal(canBatch.dispatching(), collecting, "dispatching old collecting");
		QUnit.equal(arg1, 1, "first arg");
		QUnit.equal(arg2, 2, "second arg");

		collecting = canBatch.collecting();
		QUnit.ok(!collecting, "not collecting b/c we're not in a batch yet");
		obj.dispatch("second");
		collecting = canBatch.collecting();
		QUnit.ok(collecting, "forced a batch");
		QUnit.equal(secondFired, false, "don't fire yet, put in next batch");

	});


	obj.on("second", function(ev){
		secondFired = true;
		QUnit.equal(collecting.number, ev.batchNum, "same batch num on second");
		QUnit.equal(canBatch.dispatching(), collecting, "dispatching second collecting");
	});

	canBatch.start();
	collecting = canBatch.collecting();
	QUnit.ok(canBatch.collecting(), "is collecting");
	obj.dispatch("first",[1,2]);
	canBatch.stop();


});
Beispiel #29
0
QUnit.test("recursively `get`s (#31)", function(){
    var M = DefineMap.extend("M",{
        id: "number"
    });

    var MyMap = DefineMap.extend({
        l: {Type: [M]}
    });

    var m = new MyMap({
        l: [{id: 5}]
    });

    var res = m.get();
    QUnit.ok( isArray(res.l), "is a plain array");
    QUnit.ok( isPlainObject(res.l[0]), "plain object");
});
Beispiel #30
0
	syn.rightClick("one", {}, function () {
		if (syn.mouse.browser.contextmenu) {
			QUnit.equal(1, context, "context was called");
		} else {
			QUnit.ok(true, "context shouldn't be called in this browser");
		}
		QUnit.start();
	});