Skip to content

Commit

Permalink
Do not open new project if invitation rejected. Fixes #1175 (#1176)
Browse files Browse the repository at this point in the history
* Do not open new project if invitation rejected. Fixes #1175

* Only load new project on accept. Fixes #1175
  • Loading branch information
brollb authored Jan 21, 2021
1 parent f630973 commit d4ea358
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,11 @@ RoomMorph.prototype.promptInvite = function (id, role, roomName, inviter) {
'Would you like to move to "' + roomName + '"?' :
inviter + ' has invited you to join\nhim/her at "' + roomName + '"';

dialog.cancel = () => this.respondToInvitation(id, role, false);
const superCancel = dialog.cancel;
dialog.cancel = () => {
this.respondToInvitation(id, role, false);
superCancel.call(dialog);
};
dialog.askYesNo(
'Room Invitation',
localize(msg),
Expand All @@ -788,6 +792,8 @@ RoomMorph.prototype.respondToInvitation = function (id, role, accepted) {
accepted,
async project => {
// Load the project or make the project empty
if (!accepted) return;

this.ide.source = 'cloud';
if (project.Public === 'true') {
location.hash = '#present:Username=' +
Expand Down
24 changes: 24 additions & 0 deletions test/multi/collaboration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
describe('collaboration', function() {
this.timeout(7500);

it('should close prompt if rejected', async () => {
await driver.user1.reset();
const {SnapCloud} = driver.user2.globals();
driver.user1.invite(SnapCloud.username);
await driver.user2.expect(
() => driver.user2.dialogs()
.find(d => d.key && d.key.includes('invite')),
`Invited user never received invite`,
{maxWait: 1000}
);

const dialog = driver.user2.dialogs()
.filter(dialog => dialog.key)
.find(dialog => dialog.key.includes('invite'));
const cancelBtn = dialog.buttons.children.find(btn => btn.action === 'cancel');
driver.user2.click(cancelBtn);

await driver.user2.expect(
() => driver.user2.dialogs().length === 0,
'Dialog did not close. Maybe an error occurred?',
{maxWait: 1000}
);
});

describe('NO existing edits', function() {
before(async () => {
await driver.user1.reset();
Expand Down
3 changes: 1 addition & 2 deletions test/snap-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ SnapDriver.prototype.dialog = function() {
// Controlling the IDE
SnapDriver.prototype.reset = async function() {
// Close all open dialogs
const oldVersion = this.ide().room.version;
const dialogs = this.world().children.slice(1);
dialogs.forEach(dialog => dialog.destroy());

this.ide().exitReplayMode();
await this.ide().newProject();
await this.expect(
() => this.ide().room.version !== oldVersion,
() => this.ide().room.version !== -1,
'No room state received'
);
};
Expand Down

0 comments on commit d4ea358

Please sign in to comment.