@@ -198,6 +198,86 @@ QUnit.module('linkTools', function(hooks) {
198198 } ) ;
199199
200200
201+ QUnit . test ( 'a tool hidden right after addTools() stays hidden when the update is deferred' , function ( assert ) {
202+ // https://github.com/clientIO/joint/issues/1445
203+ paper . freeze ( ) ;
204+ const button = new joint . linkTools . Button ( ) ;
205+ const remove = new joint . linkTools . Remove ( ) ;
206+ const toolsView = new joint . dia . ToolsView ( { tools : [ button , remove ] } ) ;
207+ linkView . addTools ( toolsView ) ;
208+ remove . hide ( ) ;
209+ paper . unfreeze ( ) ;
210+ assert . ok ( toolsView . isMounted ( ) ) ;
211+ assert . notEqual ( getComputedStyle ( button . el ) . display , 'none' ) ;
212+ assert . ok ( button . isVisible ( ) ) ;
213+ assert . equal ( getComputedStyle ( remove . el ) . display , 'none' ) ;
214+ assert . notOk ( remove . isVisible ( ) ) ;
215+ assert . notOk ( remove . isExplicitlyVisible ( ) ) ;
216+ } ) ;
217+
218+ QUnit . test ( 'a tool hidden right after addTools() stays hidden in an async paper' , function ( assert ) {
219+ // https://github.com/clientIO/joint/issues/1445
220+ const done = assert . async ( ) ;
221+ const asyncPaperEl = document . createElement ( 'div' ) ;
222+ paperEl . parentNode . appendChild ( asyncPaperEl ) ;
223+ const asyncPaper = new joint . dia . Paper ( {
224+ el : asyncPaperEl ,
225+ model : graph ,
226+ cellViewNamespace : joint . shapes ,
227+ async : true
228+ } ) ;
229+ asyncPaper . once ( 'render:done' , ( ) => {
230+ const asyncLinkView = link . findView ( asyncPaper ) ;
231+ const button = new joint . linkTools . Button ( ) ;
232+ const remove = new joint . linkTools . Remove ( ) ;
233+ const toolsView = new joint . dia . ToolsView ( { tools : [ button , remove ] } ) ;
234+ asyncLinkView . addTools ( toolsView ) ;
235+ remove . hide ( ) ;
236+ asyncPaper . once ( 'render:done' , ( ) => {
237+ assert . ok ( toolsView . isMounted ( ) ) ;
238+ assert . notEqual ( getComputedStyle ( button . el ) . display , 'none' ) ;
239+ assert . equal ( getComputedStyle ( remove . el ) . display , 'none' ) ;
240+ assert . notOk ( remove . isVisible ( ) ) ;
241+ asyncPaper . remove ( ) ;
242+ done ( ) ;
243+ } ) ;
244+ } ) ;
245+ } ) ;
246+
247+ QUnit . test ( 'tools hidden by focusTool() are visible again when the tools view is re-added' , function ( assert ) {
248+ // https://github.com/clientIO/joint/pull/1410
249+ // e.g. an arrowhead is dragged and the tools are removed on `link:mouseleave`
250+ // before the drag ends (so `blurTool()` is never called)
251+ const arrowhead = new joint . linkTools . TargetArrowhead ( ) ;
252+ const remove = new joint . linkTools . Remove ( ) ;
253+ const toolsView = new joint . dia . ToolsView ( { tools : [ arrowhead , remove ] } ) ;
254+ linkView . addTools ( toolsView ) ;
255+ toolsView . focusTool ( arrowhead ) ;
256+ assert . equal ( getComputedStyle ( remove . el ) . display , 'none' ) ;
257+ linkView . removeTools ( ) ;
258+ linkView . addTools ( toolsView ) ;
259+ assert . notEqual ( getComputedStyle ( arrowhead . el ) . display , 'none' ) ;
260+ assert . notEqual ( getComputedStyle ( remove . el ) . display , 'none' ) ;
261+ assert . ok ( remove . isVisible ( ) ) ;
262+ assert . ok ( remove . isExplicitlyVisible ( ) ) ;
263+ } ) ;
264+
265+ QUnit . test ( 'tools hidden by focusTool() are visible again when the tools view is re-added (deferred update)' , function ( assert ) {
266+ // https://github.com/clientIO/joint/pull/1410
267+ const arrowhead = new joint . linkTools . TargetArrowhead ( ) ;
268+ const remove = new joint . linkTools . Remove ( ) ;
269+ const toolsView = new joint . dia . ToolsView ( { tools : [ arrowhead , remove ] } ) ;
270+ linkView . addTools ( toolsView ) ;
271+ toolsView . focusTool ( arrowhead ) ;
272+ linkView . removeTools ( ) ;
273+ paper . freeze ( ) ;
274+ linkView . addTools ( toolsView ) ;
275+ paper . unfreeze ( ) ;
276+ assert . notEqual ( getComputedStyle ( arrowhead . el ) . display , 'none' ) ;
277+ assert . notEqual ( getComputedStyle ( remove . el ) . display , 'none' ) ;
278+ assert . ok ( remove . isVisible ( ) ) ;
279+ } ) ;
280+
201281 QUnit . test ( 'show()' , function ( assert ) {
202282 paper . freeze ( ) ;
203283 const remove = new joint . linkTools . Vertices ( ) ;
0 commit comments