This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/lib/sharing-test.js
Robin Ward 71d37953d5 REFACTOR: Import QUnit and related helpers rather than globals
We used many global functions to handle tests when they should be
imported like other libraries in our application. This also gets us
closer to the way Ember CLI prefers our tests to be laid out.
2020-10-07 11:50:49 -04:00

72 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test, module } from "qunit";
import Sharing from "discourse/lib/sharing";
module("lib:sharing", {
beforeEach() {
Sharing._reset();
},
afterEach() {
Sharing._reset();
},
});
test("addSource", (assert) => {
const sharingSettings = "facebook|twitter";
assert.blank(Sharing.activeSources(sharingSettings));
Sharing.addSource({
id: "facebook",
});
assert.equal(Sharing.activeSources(sharingSettings).length, 1);
});
test("addSharingId", (assert) => {
const sharingSettings = "";
assert.blank(Sharing.activeSources(sharingSettings));
Sharing.addSource({
id: "new-source",
});
assert.blank(
Sharing.activeSources(sharingSettings),
"it doesnt activate a source not in settings"
);
Sharing.addSharingId("new-source");
assert.equal(
Sharing.activeSources(sharingSettings).length,
1,
"it adds sharing id to existing sharing settings"
);
const privateContext = true;
Sharing.addSource({
id: "another-source",
});
Sharing.addSharingId("another-source");
assert.equal(
Sharing.activeSources(sharingSettings, privateContext).length,
0,
"it does not add a regular source to sources in a private context"
);
Sharing.addSource({
id: "a-private-friendly-source",
showInPrivateContext: true,
});
Sharing.addSharingId("a-private-friendly-source");
assert.equal(
Sharing.activeSources(sharingSettings, privateContext).length,
1,
"it does not add a regular source to sources in a private context"
);
});