Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 09c4a6d

Browse files
committed
Tests for locked contexts
1 parent 9dd2f25 commit 09c4a6d

File tree

1 file changed

+108
-3
lines changed

1 file changed

+108
-3
lines changed

test/github-package.test.js

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,23 @@ describe('GithubPackage', function() {
412412
});
413413

414414
describe('when removing a project', function() {
415-
beforeEach(async function() {
415+
it('removes the project\'s context', async function() {
416416
await contextUpdateAfter(githubPackage, () => project.setPaths([workdirPath1]));
417-
});
418417

419-
it('removes the project\'s context', function() {
420418
assert.isFalse(contextPool.getContext(workdirPath2).isPresent());
419+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
420+
});
421+
422+
it('does nothing if the context is locked', async function() {
423+
await githubPackage.scheduleActiveContextUpdate({
424+
usePath: workdirPath2,
425+
lock: true,
426+
});
427+
428+
await contextUpdateAfter(githubPackage, () => project.setPaths([workdirPath1]));
429+
430+
assert.isTrue(contextPool.getContext(workdirPath2).isPresent());
431+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath2);
421432
});
422433
});
423434

@@ -434,6 +445,100 @@ describe('GithubPackage', function() {
434445
assert.isTrue(githubPackage.getActiveRepository().isAbsent());
435446
});
436447
});
448+
449+
describe('when changing the active pane item', function() {
450+
it('follows the active pane item', async function() {
451+
const itemPath2 = path.join(workdirPath2, 'b.txt');
452+
453+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
454+
await contextUpdateAfter(githubPackage, () => atomEnv.workspace.open(itemPath2));
455+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath2);
456+
});
457+
458+
it('does nothing if the context is locked', async function() {
459+
const itemPath2 = path.join(workdirPath2, 'c.txt');
460+
461+
await githubPackage.scheduleActiveContextUpdate({
462+
usePath: workdirPath1,
463+
lock: true,
464+
});
465+
466+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
467+
await contextUpdateAfter(githubPackage, () => atomEnv.workspace.open(itemPath2));
468+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
469+
});
470+
});
471+
472+
describe('with a locked context', function() {
473+
it('preserves the locked context in the pool', async function() {
474+
await githubPackage.scheduleActiveContextUpdate({
475+
usePath: workdirPath1,
476+
lock: true,
477+
});
478+
479+
await contextUpdateAfter(githubPackage, () => project.setPaths([workdirPath2]));
480+
481+
assert.isTrue(contextPool.getContext(workdirPath1).isPresent());
482+
assert.isTrue(contextPool.getContext(workdirPath2).isPresent());
483+
484+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
485+
});
486+
487+
it('may be unlocked', async function() {
488+
const itemPath1a = path.join(workdirPath1, 'a.txt');
489+
const itemPath1b = path.join(workdirPath2, 'b.txt');
490+
491+
await githubPackage.scheduleActiveContextUpdate({
492+
usePath: workdirPath2,
493+
lock: true,
494+
});
495+
496+
await contextUpdateAfter(githubPackage, () => atomEnv.workspace.open(itemPath1a));
497+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath2);
498+
499+
await githubPackage.scheduleActiveContextUpdate({
500+
usePath: workdirPath1,
501+
lock: false,
502+
});
503+
504+
await contextUpdateAfter(githubPackage, () => atomEnv.workspace.open(itemPath1b));
505+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
506+
});
507+
508+
it('triggers a re-render when the context is unchanged', async function() {
509+
sinon.stub(githubPackage, 'rerender');
510+
511+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
512+
await githubPackage.scheduleActiveContextUpdate({
513+
usePath: workdirPath1,
514+
lock: true,
515+
});
516+
517+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
518+
assert.isTrue(githubPackage.rerender.called);
519+
githubPackage.rerender.resetHistory();
520+
521+
await githubPackage.scheduleActiveContextUpdate({
522+
usePath: workdirPath1,
523+
lock: false,
524+
});
525+
526+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
527+
assert.isTrue(githubPackage.rerender.called);
528+
});
529+
});
530+
531+
it('does nothing when the workspace is destroyed', async function() {
532+
sinon.stub(githubPackage, 'rerender');
533+
atomEnv.destroy();
534+
535+
await githubPackage.scheduleActiveContextUpdate({
536+
usePath: workdirPath2,
537+
});
538+
539+
assert.isFalse(githubPackage.rerender.called);
540+
assert.strictEqual(githubPackage.getActiveWorkdir(), workdirPath1);
541+
});
437542
});
438543

439544
describe('with non-repository, no-conflict, and in-progress merge-conflict projects', function() {

0 commit comments

Comments
 (0)