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

Commit 584c105

Browse files
committed
RootController publish dialog tests
1 parent 645ed10 commit 584c105

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

test/controllers/root-controller.test.js

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {multiFilePatchBuilder} from '../builder/patch';
1111
import Repository from '../../lib/models/repository';
1212
import WorkdirContextPool from '../../lib/models/workdir-context-pool';
1313
import ResolutionProgress from '../../lib/models/conflicts/resolution-progress';
14+
import RemoteSet from '../../lib/models/remote-set';
15+
import Remote from '../../lib/models/remote';
1416
import RefHolder from '../../lib/models/ref-holder';
1517
import {getEndpoint} from '../../lib/models/endpoint';
1618
import GithubLoginModel from '../../lib/models/github-login-model';
@@ -626,10 +628,38 @@ describe('RootController', function() {
626628
publishable = await buildRepository(await cloneRepository());
627629
});
628630

629-
it('renders the modal publish dialog', function() {
630-
const wrapper = shallow(React.cloneElement(app, {repository: publishable}));
631+
it('does not register the command while repository data is being fetched', function() {
632+
const wrapper = shallow(app);
633+
const inner = wrapper.find('ObserveModel').renderProp('children')(null);
634+
assert.isTrue(inner.isEmptyRender());
635+
});
636+
637+
it('does not register the command when the repository is not publishable', function() {
638+
const wrapper = shallow(app);
639+
const inner = wrapper.find('ObserveModel').renderProp('children')({isPublishable: false});
640+
assert.isTrue(inner.isEmptyRender());
641+
});
642+
643+
it('does not register the command when the repository already has a GitHub remote', function() {
644+
const remotes = new RemoteSet([
645+
new Remote('origin', '[email protected]:atom/github'),
646+
]);
647+
648+
const wrapper = shallow(app);
649+
const inner = wrapper.find('ObserveModel').renderProp('children')({isPublishable: true, remotes});
650+
assert.isTrue(inner.isEmptyRender());
651+
});
652+
653+
it('renders the modal publish dialog', async function() {
654+
const wrapper = shallow(app);
655+
const observer = wrapper.find('ObserveModel');
656+
657+
const payload = await observer.prop('fetchData')(publishable);
658+
assert.isTrue(payload.isPublishable);
659+
assert.isTrue(payload.remotes.filter(each => each.isGithubRepo()).isEmpty());
660+
const inner = observer.renderProp('children')(payload);
631661

632-
wrapper.find('Command[command="github:publish-repository"]').prop('callback')();
662+
inner.find('Command[command="github:publish-repository"]').prop('callback')();
633663
assert.strictEqual(wrapper.find('DialogsController').prop('request').identifier, 'publish');
634664
});
635665

@@ -651,8 +681,11 @@ describe('RootController', function() {
651681
sinon.stub(publishable, 'push').resolves();
652682

653683
const wrapper = shallow(React.cloneElement(app, {repository: publishable}));
654-
655-
wrapper.find('Command[command="github:publish-repository"]').prop('callback')();
684+
const inner = wrapper.find('ObserveModel').renderProp('children')({
685+
isPublishable: true,
686+
remotes: new RemoteSet(),
687+
});
688+
inner.find('Command[command="github:publish-repository"]').prop('callback')();
656689

657690
const req0 = wrapper.find('DialogsController').prop('request');
658691
await req0.accept({
@@ -676,7 +709,11 @@ describe('RootController', function() {
676709

677710
it('dismisses the CreateDialog on cancel', function() {
678711
const wrapper = shallow(React.cloneElement(app, {repository: publishable}));
679-
wrapper.find('Command[command="github:publish-repository"]').prop('callback')();
712+
const inner = wrapper.find('ObserveModel').renderProp('children')({
713+
isPublishable: true,
714+
remotes: new RemoteSet(),
715+
});
716+
inner.find('Command[command="github:publish-repository"]').prop('callback')();
680717

681718
const req0 = wrapper.find('DialogsController').prop('request');
682719
req0.cancel();
@@ -685,19 +722,6 @@ describe('RootController', function() {
685722
const req1 = wrapper.find('DialogsController').prop('request');
686723
assert.strictEqual(req1, dialogRequests.null);
687724
});
688-
689-
it('does not render the command if the current repository is absent', function() {
690-
const repository = Repository.absent();
691-
const wrapper = shallow(React.cloneElement(app, {repository}));
692-
assert.isFalse(wrapper.exists('Command[command="github:publish-repository"]'));
693-
});
694-
695-
it('does not render the command if the current repository is empty', async function() {
696-
const emptyWorkdir = temp.mkdirSync({prefix: 'rootctrl-'});
697-
const repository = await buildRepository(emptyWorkdir);
698-
const wrapper = shallow(React.cloneElement(app, {repository}));
699-
assert.isFalse(wrapper.exists('Command[command="github:publish-repository"]'));
700-
});
701725
});
702726

703727
describe('openFiles(filePaths)', () => {

0 commit comments

Comments
 (0)