This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show notifications to host when sites join or leave
- Loading branch information
Antonio Scandurra
committed
Sep 27, 2017
1 parent
43babf6
commit 69dea87
Showing
4 changed files
with
73 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const environments = [] | ||
|
||
exports.buildAtomEnvironment = function buildAtomEnvironment () { | ||
const env = global.buildAtomEnvironment() | ||
environments.push(env) | ||
return env | ||
} | ||
|
||
exports.destroyAtomEnvironments = function destroyAtomEnvironments () { | ||
const destroyPromises = environments.map((e) => e.destroy()) | ||
environments.length = 0 | ||
return Promise.all(destroyPromises) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,67 @@ | ||
const assert = require('assert') | ||
const {buildAtomEnvironment, destroyAtomEnvironments} = require('./helpers/atom-environments') | ||
const {RealTimeClient} = require('@atom/real-time-client') | ||
const HostPortalBinding = require('../lib/host-portal-binding') | ||
const FakeClipboard = require('./helpers/fake-clipboard') | ||
|
||
suite('HostPortalBinding', () => { | ||
teardown(async () => { | ||
await destroyAtomEnvironments() | ||
}) | ||
|
||
test('handling an unexpected error when joining a portal', async () => { | ||
const client = new RealTimeClient({}) | ||
client.createPortal = function () { | ||
throw new Error('It broke!') | ||
} | ||
const notificationManager = { | ||
errors: [], | ||
addError (...args) { this.errors.push(args) } | ||
} | ||
const portalBinding = new HostPortalBinding({ | ||
client, | ||
notificationManager | ||
}) | ||
const atomEnv = buildAtomEnvironment() | ||
const portalBinding = buildHostPortalBinding(client, atomEnv) | ||
|
||
const result = await portalBinding.initialize() | ||
assert.equal(result, false) | ||
|
||
assert.equal(notificationManager.errors.length, 1) | ||
const [[message, params]] = notificationManager.errors | ||
assert.equal(atomEnv.notifications.getNotifications().length, 1) | ||
const {message, options} = atomEnv.notifications.getNotifications()[0] | ||
assert.equal(message, 'Failed to share portal') | ||
assert(params.description.includes('It broke!')) | ||
assert(options.description.includes('It broke!')) | ||
}) | ||
|
||
test('showing notifications when sites join or leave', async () => { | ||
const client = new RealTimeClient({}) | ||
const portal = { | ||
setDelegate (delegate) { | ||
this.delegate = delegate | ||
}, | ||
getSiteIdentity (siteId) { | ||
return {username: 'site-' + siteId} | ||
}, | ||
setActiveEditorProxy () {} | ||
} | ||
client.createPortal = function () { | ||
return portal | ||
} | ||
const atomEnv = buildAtomEnvironment() | ||
const portalBinding = buildHostPortalBinding(client, atomEnv) | ||
await portalBinding.initialize() | ||
|
||
atomEnv.notifications.clear() | ||
portal.delegate.siteDidJoin(2) | ||
assert.equal(atomEnv.notifications.getNotifications().length, 1) | ||
assert(atomEnv.notifications.getNotifications()[0].message.includes('@site-2')) | ||
|
||
atomEnv.notifications.clear() | ||
portal.delegate.siteDidLeave(3) | ||
assert.equal(atomEnv.notifications.getNotifications().length, 1) | ||
assert(atomEnv.notifications.getNotifications()[0].message.includes('@site-3')) | ||
}) | ||
|
||
function buildHostPortalBinding (client, atomEnv) { | ||
return new HostPortalBinding({ | ||
client, | ||
notificationManager: atomEnv.notifications, | ||
workspace: atomEnv.workspace, | ||
clipboard: new FakeClipboard(), | ||
addStatusBarIndicatorForPortal: () => {} | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69dea87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SecurityXploded_License.pdf