diaspora/spec/javascripts/app/collections/contacts_collection_spec.js
Sage Ross ae3bd1f62e
Fix order-dependent jasmine failure in contacts_collection_spec.js
This was failing if `app.aspect` got set by another spec than ran before it (such as one of the other specs in the same file, when run in a different order).
2022-06-19 17:22:59 +02:00

38 lines
1.4 KiB
JavaScript

describe("app.collections.Contacts", function(){
beforeEach(function(){
this.collection = new app.collections.Contacts();
});
describe("comparator", function() {
beforeEach(function(){
this.aspect = new app.models.Aspect({id: 42, name: "cats"});
this.con1 = new app.models.Contact({
person: { name: "aaa" },
aspect_memberships: []
});
this.con2 = new app.models.Contact({
person: { name: "aaa" },
aspect_memberships: [{id: 23, aspect: this.aspect}]
});
this.con3 = new app.models.Contact({
person: { name: "zzz" },
aspect_memberships: [{id: 23, aspect: this.aspect}]
});
});
it("should compare the username if app.aspect is not present", function() {
delete app.aspect;
expect(this.collection.comparator(this.con1, this.con3)).toBeLessThan(0);
});
it("should compare the aspect memberships if app.aspect is present", function() {
app.aspect = this.aspect;
expect(this.collection.comparator(this.con1, this.con3)).toBeGreaterThan(0);
});
it("should compare the username if the contacts have equal aspect memberships", function() {
app.aspect = this.aspect;
expect(this.collection.comparator(this.con2, this.con3)).toBeLessThan(0);
});
});
});