@@ -57,7 +57,7 @@ describe('ChangedFileItem', function() {
5757 ) ;
5858 }
5959
60- function open ( wrapper , options = { } ) {
60+ function open ( options = { } ) {
6161 const opts = {
6262 relPath : 'a.txt' ,
6363 workingDirectory : repository . getWorkingDirectoryPath ( ) ,
@@ -70,37 +70,37 @@ describe('ChangedFileItem', function() {
7070
7171 it ( 'locates the repository from the context pool' , async function ( ) {
7272 const wrapper = mount ( buildPaneApp ( ) ) ;
73- await open ( wrapper ) ;
73+ await open ( ) ;
7474
7575 assert . strictEqual ( wrapper . update ( ) . find ( 'ChangedFileContainer' ) . prop ( 'repository' ) , repository ) ;
7676 } ) ;
7777
7878 it ( 'passes an absent repository if the working directory is unrecognized' , async function ( ) {
7979 const wrapper = mount ( buildPaneApp ( ) ) ;
80- await open ( wrapper , { workingDirectory : '/nope' } ) ;
80+ await open ( { workingDirectory : '/nope' } ) ;
8181
8282 assert . isTrue ( wrapper . update ( ) . find ( 'ChangedFileContainer' ) . prop ( 'repository' ) . isAbsent ( ) ) ;
8383 } ) ;
8484
8585 it ( 'passes other props to the container' , async function ( ) {
8686 const other = Symbol ( 'other' ) ;
8787 const wrapper = mount ( buildPaneApp ( { other} ) ) ;
88- await open ( wrapper ) ;
88+ await open ( ) ;
8989
9090 assert . strictEqual ( wrapper . update ( ) . find ( 'ChangedFileContainer' ) . prop ( 'other' ) , other ) ;
9191 } ) ;
9292
9393 describe ( 'getTitle()' , function ( ) {
9494 it ( 'renders an unstaged title' , async function ( ) {
95- const wrapper = mount ( buildPaneApp ( ) ) ;
96- const item = await open ( wrapper , { stagingStatus : 'unstaged' } ) ;
95+ mount ( buildPaneApp ( ) ) ;
96+ const item = await open ( { stagingStatus : 'unstaged' } ) ;
9797
9898 assert . strictEqual ( item . getTitle ( ) , 'Unstaged Changes: a.txt' ) ;
9999 } ) ;
100100
101101 it ( 'renders a staged title' , async function ( ) {
102- const wrapper = mount ( buildPaneApp ( ) ) ;
103- const item = await open ( wrapper , { stagingStatus : 'staged' } ) ;
102+ mount ( buildPaneApp ( ) ) ;
103+ const item = await open ( { stagingStatus : 'staged' } ) ;
104104
105105 assert . strictEqual ( item . getTitle ( ) , 'Staged Changes: a.txt' ) ;
106106 } ) ;
@@ -150,23 +150,23 @@ describe('ChangedFileItem', function() {
150150 } ) ;
151151
152152 it ( 'serializes itself as a FilePatchControllerStub' , async function ( ) {
153- const wrapper = mount ( buildPaneApp ( ) ) ;
154- const item0 = await open ( wrapper , { relPath : 'a.txt' , workingDirectory : '/dir0' , stagingStatus : 'unstaged' } ) ;
153+ mount ( buildPaneApp ( ) ) ;
154+ const item0 = await open ( { relPath : 'a.txt' , workingDirectory : '/dir0' , stagingStatus : 'unstaged' } ) ;
155155 assert . deepEqual ( item0 . serialize ( ) , {
156156 deserializer : 'FilePatchControllerStub' ,
157157 uri : 'atom-github://file-patch/a.txt?workdir=%2Fdir0&stagingStatus=unstaged' ,
158158 } ) ;
159159
160- const item1 = await open ( wrapper , { relPath : 'b.txt' , workingDirectory : '/dir1' , stagingStatus : 'staged' } ) ;
160+ const item1 = await open ( { relPath : 'b.txt' , workingDirectory : '/dir1' , stagingStatus : 'staged' } ) ;
161161 assert . deepEqual ( item1 . serialize ( ) , {
162162 deserializer : 'FilePatchControllerStub' ,
163163 uri : 'atom-github://file-patch/b.txt?workdir=%2Fdir1&stagingStatus=staged' ,
164164 } ) ;
165165 } ) ;
166166
167167 it ( 'has some item-level accessors' , async function ( ) {
168- const wrapper = mount ( buildPaneApp ( ) ) ;
169- const item = await open ( wrapper , { relPath : 'a.txt' , workingDirectory : '/dir' , stagingStatus : 'unstaged' } ) ;
168+ mount ( buildPaneApp ( ) ) ;
169+ const item = await open ( { relPath : 'a.txt' , workingDirectory : '/dir' , stagingStatus : 'unstaged' } ) ;
170170
171171 assert . strictEqual ( item . getStagingStatus ( ) , 'unstaged' ) ;
172172 assert . strictEqual ( item . getFilePath ( ) , 'a.txt' ) ;
@@ -178,16 +178,18 @@ describe('ChangedFileItem', function() {
178178 let sub , editor ;
179179
180180 beforeEach ( function ( ) {
181- editor = Symbol ( 'editor' ) ;
181+ editor = {
182+ isAlive ( ) { return true ; } ,
183+ } ;
182184 } ) ;
183185
184186 afterEach ( function ( ) {
185187 sub && sub . dispose ( ) ;
186188 } ) ;
187189
188- it ( 'calls its callback immediately if an editor is present' , async function ( ) {
190+ it ( 'calls its callback immediately if an editor is present and alive ' , async function ( ) {
189191 const wrapper = mount ( buildPaneApp ( ) ) ;
190- const item = await open ( wrapper ) ;
192+ const item = await open ( ) ;
191193
192194 wrapper . update ( ) . find ( 'ChangedFileContainer' ) . prop ( 'refEditor' ) . setter ( editor ) ;
193195
@@ -196,15 +198,37 @@ describe('ChangedFileItem', function() {
196198 assert . isTrue ( cb . calledWith ( editor ) ) ;
197199 } ) ;
198200
201+ it ( 'does not call its callback if an editor is present but destroyed' , async function ( ) {
202+ const wrapper = mount ( buildPaneApp ( ) ) ;
203+ const item = await open ( ) ;
204+
205+ wrapper . update ( ) . find ( 'ChangedFileContainer' ) . prop ( 'refEditor' ) . setter ( { isAlive ( ) { return false ; } } ) ;
206+
207+ const cb = sinon . spy ( ) ;
208+ sub = item . observeEmbeddedTextEditor ( cb ) ;
209+ assert . isFalse ( cb . called ) ;
210+ } ) ;
211+
199212 it ( 'calls its callback later if the editor changes' , async function ( ) {
200213 const wrapper = mount ( buildPaneApp ( ) ) ;
201- const item = await open ( wrapper ) ;
214+ const item = await open ( ) ;
202215
203216 const cb = sinon . spy ( ) ;
204217 sub = item . observeEmbeddedTextEditor ( cb ) ;
205218
206219 wrapper . update ( ) . find ( 'ChangedFileContainer' ) . prop ( 'refEditor' ) . setter ( editor ) ;
207220 assert . isTrue ( cb . calledWith ( editor ) ) ;
208221 } ) ;
222+
223+ it ( 'does not call its callback after its editor is destroyed' , async function ( ) {
224+ const wrapper = mount ( buildPaneApp ( ) ) ;
225+ const item = await open ( ) ;
226+
227+ const cb = sinon . spy ( ) ;
228+ sub = item . observeEmbeddedTextEditor ( cb ) ;
229+
230+ wrapper . update ( ) . find ( 'ChangedFileContainer' ) . prop ( 'refEditor' ) . setter ( { isAlive ( ) { return false ; } } ) ;
231+ assert . isFalse ( cb . called ) ;
232+ } ) ;
209233 } ) ;
210234} ) ;
0 commit comments