DEV: Unflak-ify tests and make them more robust (#16659)
This commit is contained in:
parent
4e5f5b67b0
commit
337cacc7bf
|
@ -32,19 +32,17 @@ discourseModule("Unit | Controller | user-notifications", function () {
|
||||||
EmberObject.create({ read: false }),
|
EmberObject.create({ read: false }),
|
||||||
EmberObject.create({ read: true }),
|
EmberObject.create({ read: true }),
|
||||||
];
|
];
|
||||||
let markModelsRead = false;
|
const controller = this.getController("user-notifications", { model });
|
||||||
const controller = this.getController("user-notifications", {
|
|
||||||
model,
|
|
||||||
markModelsRead: () => {
|
|
||||||
markModelsRead = true;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
pretender.put("/notifications/mark-read", () => {
|
pretender.put("/notifications/mark-read", () => {
|
||||||
return [500];
|
return [500];
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.rejects(controller.markRead());
|
assert.rejects(controller.markRead());
|
||||||
assert.strictEqual(markModelsRead, false);
|
assert.deepEqual(
|
||||||
|
model.map(({ read }) => read),
|
||||||
|
[false, true],
|
||||||
|
"models unmodified"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Marks all notifications read when no high priority notifications", function (assert) {
|
test("Marks all notifications read when no high priority notifications", function (assert) {
|
||||||
|
@ -53,9 +51,9 @@ discourseModule("Unit | Controller | user-notifications", function () {
|
||||||
const controller = this.getController("user-notifications", {
|
const controller = this.getController("user-notifications", {
|
||||||
model: [],
|
model: [],
|
||||||
currentUser,
|
currentUser,
|
||||||
markRead: () => {
|
});
|
||||||
markRead = true;
|
sinon.stub(controller, "markRead").callsFake(() => {
|
||||||
},
|
markRead = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
controller.send("resetNew");
|
controller.send("resetNew");
|
||||||
|
@ -65,7 +63,6 @@ discourseModule("Unit | Controller | user-notifications", function () {
|
||||||
|
|
||||||
test("Shows modal when has high priority notifications", function (assert) {
|
test("Shows modal when has high priority notifications", function (assert) {
|
||||||
let capturedProperties;
|
let capturedProperties;
|
||||||
const markReadStub = () => {};
|
|
||||||
sinon
|
sinon
|
||||||
.stub(showModal, "default")
|
.stub(showModal, "default")
|
||||||
.withArgs("dismiss-notification-confirmation")
|
.withArgs("dismiss-notification-confirmation")
|
||||||
|
@ -75,15 +72,14 @@ discourseModule("Unit | Controller | user-notifications", function () {
|
||||||
const currentUser = User.create({ unread_high_priority_notifications: 1 });
|
const currentUser = User.create({ unread_high_priority_notifications: 1 });
|
||||||
const controller = this.getController("user-notifications", {
|
const controller = this.getController("user-notifications", {
|
||||||
currentUser,
|
currentUser,
|
||||||
markRead: markReadStub,
|
|
||||||
});
|
});
|
||||||
|
const markReadFake = sinon.fake();
|
||||||
|
sinon.stub(controller, "markRead").callsFake(markReadFake);
|
||||||
|
|
||||||
controller.send("resetNew");
|
controller.send("resetNew");
|
||||||
|
|
||||||
assert.strictEqual(capturedProperties.count, 1);
|
assert.strictEqual(capturedProperties.count, 1);
|
||||||
assert.strictEqual(
|
capturedProperties.dismissNotifications();
|
||||||
capturedProperties.dismissNotifications(),
|
assert.strictEqual(markReadFake.callCount, 1);
|
||||||
markReadStub()
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue