FIX: Invisible is not the opposite of visible (#11881)

If visible is undefined, then invisible should be too.
This commit is contained in:
Bianca Nenciu 2021-01-28 20:17:46 +02:00 committed by GitHub
parent b70e0d88f7
commit 8e53c2a2c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { and, equal, not, notEmpty, or } from "@ember/object/computed";
import { and, equal, notEmpty, or } from "@ember/object/computed";
import { fmt, propertyEqual } from "discourse/lib/computed";
import ActionSummary from "discourse/models/action-summary";
import Category from "discourse/models/category";
@ -210,7 +210,11 @@ const Topic = RestModel.extend({
});
},
invisible: not("visible"),
@discourseComputed("visible")
invisible(visible) {
return visible !== undefined ? !visible : undefined;
},
deleted: notEmpty("deleted_at"),
@discourseComputed("id")

View File

@ -163,4 +163,18 @@ discourseModule("Unit | Model | topic", function () {
"supports emojis"
);
});
test("visible & invisible", function (assert) {
const topic = Topic.create();
assert.equal(topic.visible, undefined);
assert.equal(topic.invisible, undefined);
const visibleTopic = Topic.create({ visible: true });
assert.equal(visibleTopic.visible, true);
assert.equal(visibleTopic.invisible, false);
const invisibleTopic = Topic.create({ visible: false });
assert.equal(invisibleTopic.visible, false);
assert.equal(invisibleTopic.invisible, true);
});
});