forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-package.test.js
More file actions
182 lines (149 loc) · 8.5 KB
/
Copy pathgithub-package.test.js
File metadata and controls
182 lines (149 loc) · 8.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/** @babel */
import fs from 'fs'
import path from 'path'
import temp from 'temp'
import {copyRepositoryDir} from './helpers'
import FilePatch from '../lib/models/file-patch'
import GithubPackage from '../lib/github-package'
describe('GithubPackage', () => {
let atomEnv, workspace, project, githubPackage
beforeEach(() => {
atomEnv = global.buildAtomEnvironment()
workspace = atomEnv.workspace
project = atomEnv.project
githubPackage = new GithubPackage(workspace, project)
})
afterEach(() => {
atomEnv.destroy()
})
describe('activate', () => {
it('updates the active repository', async () => {
const workdirPath1 = copyRepositoryDir()
const workdirPath2 = copyRepositoryDir()
project.setPaths([workdirPath1, workdirPath2])
fs.writeFileSync(path.join(workdirPath1, 'a.txt'), 'change 1', 'utf8')
fs.writeFileSync(path.join(workdirPath1, 'b.txt'), 'change 2', 'utf8')
await workspace.open(path.join(workdirPath1, 'a.txt'))
await githubPackage.activate()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath1))
assert.equal(githubPackage.commitPanelView.repository, githubPackage.getActiveRepository())
})
})
describe('didChangeProjectPaths', () => {
it('updates the active repository', async () => {
const workdirPath1 = copyRepositoryDir()
const workdirPath2 = copyRepositoryDir()
project.setPaths([workdirPath1, workdirPath2])
fs.writeFileSync(path.join(workdirPath1, 'a.txt'), 'change 1', 'utf8')
await workspace.open(path.join(workdirPath1, 'a.txt'))
await githubPackage.didChangeProjectPaths()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath1))
assert.equal(githubPackage.commitPanelView.repository, githubPackage.getActiveRepository())
project.setPaths([workdirPath2])
await githubPackage.didChangeProjectPaths()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath2))
assert.equal(githubPackage.commitPanelView.repository, githubPackage.getActiveRepository())
})
it('destroys all the repositories associated with the removed project folders', async () => {
const workdirPath1 = copyRepositoryDir()
const workdirPath2 = copyRepositoryDir()
const workdirPath3 = copyRepositoryDir()
project.setPaths([workdirPath1, workdirPath2, workdirPath3])
const repository1 = await githubPackage.repositoryForWorkdirPath(workdirPath1)
const repository2 = await githubPackage.repositoryForWorkdirPath(workdirPath2)
const repository3 = await githubPackage.repositoryForWorkdirPath(workdirPath3)
assert(repository1)
assert(repository2)
assert(repository3)
project.removePath(workdirPath1)
project.removePath(workdirPath3)
githubPackage.didChangeProjectPaths()
assert.notEqual(await githubPackage.repositoryForProjectDirectory(repository1.getWorkingDirectory()), repository1)
assert.notEqual(await githubPackage.repositoryForProjectDirectory(repository3.getWorkingDirectory()), repository3)
assert.equal(await githubPackage.repositoryForProjectDirectory(repository2.getWorkingDirectory()), repository2)
})
})
describe('didChangeActivePaneItem', () => {
it('updates the active repository', async () => {
const workdirPath1 = copyRepositoryDir()
const workdirPath2 = copyRepositoryDir()
project.setPaths([workdirPath1, workdirPath2])
fs.writeFileSync(path.join(workdirPath1, 'a.txt'), 'change 1', 'utf8')
fs.writeFileSync(path.join(workdirPath2, 'b.txt'), 'change 2', 'utf8')
await workspace.open(path.join(workdirPath1, 'a.txt'))
await githubPackage.didChangeActivePaneItem()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath1))
assert.equal(githubPackage.commitPanelView.repository, githubPackage.getActiveRepository())
await workspace.open(path.join(workdirPath2, 'b.txt'))
await githubPackage.didChangeActivePaneItem()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath2))
assert.equal(githubPackage.commitPanelView.repository, githubPackage.getActiveRepository())
})
})
describe('updateActiveRepository', () => {
it('updates the active repository based on the most recent active item with a path unless its directory has been removed from the project', async () => {
const workdirPath1 = copyRepositoryDir()
const workdirPath2 = copyRepositoryDir()
const nonRepositoryPath = temp.mkdirSync()
fs.writeFileSync(path.join(nonRepositoryPath, 'c.txt'))
project.setPaths([workdirPath1, workdirPath2, nonRepositoryPath])
await workspace.open(path.join(workdirPath1, 'a.txt'))
await workspace.open(path.join(workdirPath2, 'b.txt'))
assert.isNull(githubPackage.getActiveRepository())
await githubPackage.updateActiveRepository()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath2))
await workspace.open(path.join(workdirPath1, 'a.txt'))
await githubPackage.updateActiveRepository()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath1))
await workspace.open(path.join(workdirPath2, 'b.txt'))
await githubPackage.updateActiveRepository()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath2))
workspace.getActivePane().activateItem({})
await githubPackage.updateActiveRepository()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath2))
project.removePath(workdirPath2)
await githubPackage.updateActiveRepository()
assert.equal(githubPackage.getActiveRepository(), await githubPackage.repositoryForWorkdirPath(workdirPath1))
project.removePath(workdirPath1)
await githubPackage.updateActiveRepository()
assert.isNull(githubPackage.getActiveRepository())
await workspace.open(path.join(nonRepositoryPath, 'c.txt'))
await githubPackage.updateActiveRepository()
assert.isNull(githubPackage.getActiveRepository())
})
})
describe('when a FilePatch is selected in the staging panel', () => {
it('shows a FilePatchView for the selected patch as a pane item', () => {
let dummyActiveRepository = {}
githubPackage.getActiveRepository = function () { return dummyActiveRepository }
const filePatch1 = new FilePatch('a.txt', 'a.txt', 1234, 1234, 'modified', [])
const filePatch2 = new FilePatch('b.txt', 'b.txt', 1234, 1234, 'modified', [])
assert.isNull(githubPackage.filePatchView)
githubPackage.commitPanelView.didSelectFilePatch(filePatch1, 'unstaged')
assert(githubPackage.filePatchView)
assert.equal(githubPackage.filePatchView.filePatch, filePatch1)
assert.equal(githubPackage.filePatchView.repository, dummyActiveRepository)
assert.equal(githubPackage.filePatchView.stagingStatus, 'unstaged')
assert.equal(workspace.getActivePaneItem(), githubPackage.filePatchView)
const existingFilePatchView = githubPackage.filePatchView
workspace.getActivePane().splitRight() // activate a different pane
assert.isUndefined(workspace.getActivePaneItem())
dummyActiveRepository = {}
githubPackage.commitPanelView.didSelectFilePatch(filePatch2, 'staged')
assert.equal(githubPackage.filePatchView, existingFilePatchView)
assert.equal(githubPackage.filePatchView.filePatch, filePatch2)
assert.equal(githubPackage.filePatchView.repository, dummyActiveRepository)
assert.equal(githubPackage.filePatchView.stagingStatus, 'staged')
assert.equal(workspace.getActivePaneItem(), githubPackage.filePatchView)
workspace.getActivePaneItem().destroy()
assert.isUndefined(workspace.getActivePaneItem())
assert.isNull(githubPackage.filePatchView)
githubPackage.commitPanelView.didSelectFilePatch(filePatch2, 'staged')
assert.notEqual(githubPackage.filePatchView, existingFilePatchView)
assert.equal(githubPackage.filePatchView.filePatch, filePatch2)
assert.equal(githubPackage.filePatchView.repository, dummyActiveRepository)
assert.equal(githubPackage.filePatchView.stagingStatus, 'staged')
assert.equal(workspace.getActivePaneItem(), githubPackage.filePatchView)
})
})
})