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

Commit 7736430

Browse files
committed
Flatten and update GitHub tab component props
1 parent 8fb24d6 commit 7736430

File tree

7 files changed

+132
-101
lines changed

7 files changed

+132
-101
lines changed

lib/containers/github-tab-container.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export default class GitHubTabContainer extends React.Component {
1616
loginModel: GithubLoginModelPropType.isRequired,
1717
rootHolder: RefHolderPropType.isRequired,
1818

19+
changeWorkingDirectory: PropTypes.func.isRequired,
20+
onDidChangeWorkDirs: PropTypes.func.isRequired,
21+
getCurrentWorkDirs: PropTypes.func.isRequired,
1922
openCreateDialog: PropTypes.func.isRequired,
2023
openPublishDialog: PropTypes.func.isRequired,
2124
openCloneDialog: PropTypes.func.isRequired,

lib/items/github-tab-item.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default class GitHubTabItem extends React.Component {
1313

1414
documentActiveElement: PropTypes.func,
1515

16+
changeWorkingDirectory: PropTypes.func.isRequired,
17+
onDidChangeWorkDirs: PropTypes.func.isRequired,
18+
getCurrentWorkDirs: PropTypes.func.isRequired,
1619
openCreateDialog: PropTypes.func.isRequired,
1720
openPublishDialog: PropTypes.func.isRequired,
1821
openCloneDialog: PropTypes.func.isRequired,

test/containers/github-tab-container.test.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,46 @@ import {mount} from 'enzyme';
44
import {cloneRepository} from '../helpers';
55
import GitHubTabContainer from '../../lib/containers/github-tab-container';
66
import Repository from '../../lib/models/repository';
7-
import {gitHubTabContainerProps} from '../fixtures/props/github-tab-props';
7+
import {InMemoryStrategy} from '../../lib/shared/keytar-strategy';
8+
import GithubLoginModel from '../../lib/models/github-login-model';
9+
import RefHolder from '../../lib/models/ref-holder';
810

911
describe('GitHubTabContainer', function() {
10-
let atomEnv;
12+
let atomEnv, repository;
1113

1214
beforeEach(function() {
1315
atomEnv = global.buildAtomEnvironment();
16+
repository = Repository.absent();
1417
});
1518

1619
afterEach(function() {
1720
atomEnv.destroy();
1821
});
1922

20-
function buildApp(overrideProps = {}) {
21-
const repository = Repository.absent();
22-
return <GitHubTabContainer {...gitHubTabContainerProps(atomEnv, repository, overrideProps)} />;
23+
function buildApp(props = {}) {
24+
return (
25+
<GitHubTabContainer
26+
workspace={atomEnv.workspace}
27+
repository={repository}
28+
loginModel={new GithubLoginModel(InMemoryStrategy)}
29+
rootHolder={new RefHolder()}
30+
31+
changeWorkingDirectory={() => {}}
32+
onDidChangeWorkDirs={() => {}}
33+
getCurrentWorkDirs={() => []}
34+
openCreateDialog={() => {}}
35+
openPublishDialog={() => {}}
36+
openCloneDialog={() => {}}
37+
openGitTab={() => {}}
38+
39+
{...props}
40+
/>
41+
);
2342
}
2443

2544
describe('operation state observer', function() {
2645
it('creates an observer on the current repository', function() {
27-
const repository = Repository.absent();
28-
const wrapper = mount(buildApp({repository}));
46+
const wrapper = mount(buildApp());
2947

3048
const observer = wrapper.state('remoteOperationObserver');
3149
assert.strictEqual(observer.repository, repository);
@@ -48,9 +66,9 @@ describe('GitHubTabContainer', function() {
4866

4967
describe('while loading', function() {
5068
it('passes isLoading to its view', async function() {
51-
const repository = new Repository(await cloneRepository());
52-
assert.isTrue(repository.isLoading());
53-
const wrapper = mount(buildApp({repository}));
69+
const loadingRepo = new Repository(await cloneRepository());
70+
assert.isTrue(loadingRepo.isLoading());
71+
const wrapper = mount(buildApp({repository: loadingRepo}));
5472

5573
assert.isTrue(wrapper.find('GitHubTabController').prop('isLoading'));
5674
});
@@ -59,9 +77,9 @@ describe('GitHubTabContainer', function() {
5977
describe('once loaded', function() {
6078
it('renders the controller', async function() {
6179
const workdir = await cloneRepository();
62-
const repository = new Repository(workdir);
63-
await repository.getLoadPromise();
64-
const wrapper = mount(buildApp({repository}));
80+
const presentRepo = new Repository(workdir);
81+
await presentRepo.getLoadPromise();
82+
const wrapper = mount(buildApp({repository: presentRepo}));
6583

6684
await assert.async.isFalse(wrapper.update().find('GitHubTabController').prop('isLoading'));
6785
assert.strictEqual(wrapper.find('GitHubTabController').prop('workingDirectory'), workdir);

test/controllers/github-tab-controller.test.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,60 @@
11
import React from 'react';
22
import {shallow} from 'enzyme';
33

4-
import {gitHubTabControllerProps} from '../fixtures/props/github-tab-props';
54
import GitHubTabController from '../../lib/controllers/github-tab-controller';
65
import Repository from '../../lib/models/repository';
76
import BranchSet from '../../lib/models/branch-set';
87
import Branch, {nullBranch} from '../../lib/models/branch';
98
import RemoteSet from '../../lib/models/remote-set';
109
import Remote from '../../lib/models/remote';
10+
import {InMemoryStrategy} from '../../lib/shared/keytar-strategy';
11+
import GithubLoginModel from '../../lib/models/github-login-model';
12+
import RefHolder from '../../lib/models/ref-holder';
13+
import OperationStateObserver, {PUSH, PULL, FETCH} from '../../lib/models/operation-state-observer';
14+
15+
import {buildRepository, cloneRepository} from '../helpers';
1116

1217
describe('GitHubTabController', function() {
13-
let atomEnv;
18+
let atomEnv, repository;
1419

15-
beforeEach(function() {
20+
beforeEach(async function() {
1621
atomEnv = global.buildAtomEnvironment();
22+
repository = await buildRepository(await cloneRepository());
1723
});
1824

1925
afterEach(function() {
2026
atomEnv.destroy();
2127
});
2228

23-
function buildApp(overrideProps = {}) {
24-
const props = {
25-
repository: Repository.absent(),
26-
...overrideProps,
27-
};
28-
29-
return <GitHubTabController {...gitHubTabControllerProps(atomEnv, props.repository, props)} />;
29+
function buildApp(props = {}) {
30+
const repo = props.repository || repository;
31+
32+
return (
33+
<GitHubTabController
34+
workspace={atomEnv.workspace}
35+
remoteOperationObserver={new OperationStateObserver(repo, PUSH, PULL, FETCH)}
36+
loginModel={new GithubLoginModel(InMemoryStrategy)}
37+
rootHolder={new RefHolder()}
38+
39+
workingDirectory={repo.getWorkingDirectoryPath()}
40+
repository={repo}
41+
allRemotes={new RemoteSet()}
42+
branches={new BranchSet()}
43+
pushInProgress={false}
44+
isLoading={false}
45+
currentWorkDir={repo.getWorkingDirectoryPath()}
46+
47+
changeWorkingDirectory={() => {}}
48+
onDidChangeWorkDirs={() => {}}
49+
getCurrentWorkDirs={() => []}
50+
openCreateDialog={() => {}}
51+
openPublishDialog={() => {}}
52+
openCloneDialog={() => {}}
53+
openGitTab={() => {}}
54+
55+
{...props}
56+
/>
57+
);
3058
}
3159

3260
describe('derived view props', function() {

test/fixtures/props/github-tab-props.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

test/items/github-tab-item.test.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import {mount} from 'enzyme';
33

44
import PaneItem from '../../lib/atom/pane-item';
55
import GitHubTabItem from '../../lib/items/github-tab-item';
6+
import GithubLoginModel from '../../lib/models/github-login-model';
7+
import {InMemoryStrategy} from '../../lib/shared/keytar-strategy';
8+
69
import {cloneRepository, buildRepository} from '../helpers';
7-
import {gitHubTabItemProps} from '../fixtures/props/github-tab-props';
810

911
describe('GitHubTabItem', function() {
1012
let atomEnv, repository;
@@ -20,14 +22,26 @@ describe('GitHubTabItem', function() {
2022
atomEnv.destroy();
2123
});
2224

23-
function buildApp(overrideProps = {}) {
24-
const props = gitHubTabItemProps(atomEnv, repository, overrideProps);
25+
function buildApp(props = {}) {
26+
const workspace = props.workspace || atomEnv.workspace;
2527

2628
return (
27-
<PaneItem workspace={props.workspace} uriPattern={GitHubTabItem.uriPattern}>
29+
<PaneItem workspace={workspace} uriPattern={GitHubTabItem.uriPattern}>
2830
{({itemHolder}) => (
2931
<GitHubTabItem
3032
ref={itemHolder.setter}
33+
34+
workspace={workspace}
35+
repository={repository}
36+
loginModel={new GithubLoginModel(InMemoryStrategy)}
37+
38+
changeWorkingDirectory={() => {}}
39+
onDidChangeWorkDirs={() => {}}
40+
getCurrentWorkDirs={() => []}
41+
openCreateDialog={() => {}}
42+
openPublishDialog={() => {}}
43+
openCloneDialog={() => {}}
44+
openGitTab={() => {}}
3145
{...props}
3246
/>
3347
)}

test/views/github-tab-view.test.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import React from 'react';
22
import {shallow} from 'enzyme';
33
import temp from 'temp';
44

5-
import {gitHubTabViewProps} from '../fixtures/props/github-tab-props';
65
import Repository from '../../lib/models/repository';
76
import Remote, {nullRemote} from '../../lib/models/remote';
87
import RemoteSet from '../../lib/models/remote-set';
9-
import Branch from '../../lib/models/branch';
8+
import Branch, {nullBranch} from '../../lib/models/branch';
9+
import BranchSet from '../../lib/models/branch-set';
1010
import GitHubTabView from '../../lib/views/github-tab-view';
11+
import {InMemoryStrategy} from '../../lib/shared/keytar-strategy';
12+
import GithubLoginModel from '../../lib/models/github-login-model';
13+
import RefHolder from '../../lib/models/ref-holder';
14+
import OperationStateObserver, {PUSH, PULL, FETCH} from '../../lib/models/operation-state-observer';
1115

1216
import {buildRepository, cloneRepository} from '../helpers';
1317

@@ -22,9 +26,39 @@ describe('GitHubTabView', function() {
2226
atomEnv.destroy();
2327
});
2428

25-
function buildApp(overrideProps = {}) {
26-
const props = gitHubTabViewProps(atomEnv, overrideProps.repository || Repository.absent(), overrideProps);
27-
return <GitHubTabView {...props} />;
29+
function buildApp(props) {
30+
const repo = props.repository || Repository.absent();
31+
32+
return (
33+
<GitHubTabView
34+
workspace={atomEnv.workspace}
35+
remoteOperationObserver={new OperationStateObserver(repo, PUSH, PULL, FETCH)}
36+
loginModel={new GithubLoginModel(InMemoryStrategy)}
37+
rootHolder={new RefHolder()}
38+
39+
workingDirectory={repo.getWorkingDirectoryPath()}
40+
repository={repo}
41+
branches={new BranchSet()}
42+
currentBranch={nullBranch}
43+
remotes={new RemoteSet()}
44+
currentRemote={nullRemote}
45+
manyRemotesAvailable={false}
46+
pushInProgress={false}
47+
isLoading={false}
48+
49+
handlePushBranch={() => {}}
50+
handleRemoteSelect={() => {}}
51+
changeWorkingDirectory={() => {}}
52+
onDidChangeWorkDirs={() => {}}
53+
getCurrentWorkDirs={() => []}
54+
openCreateDialog={() => {}}
55+
openPublishDialog={() => {}}
56+
openCloneDialog={() => {}}
57+
openGitTab={() => {}}
58+
59+
{...props}
60+
/>
61+
);
2862
}
2963

3064
it('renders a LoadingView if data is still loading', function() {

0 commit comments

Comments
 (0)