Skip to content

Commit

Permalink
fix cancel action on StudioWindow closure
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Dec 30, 2023
1 parent 7910a2f commit 74ec51d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/studio/ui/StudioWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,9 @@ public void close() {
if (allWindows.size() == 1) {
quit();
} else {
execute(editorTab -> editorTab.getEditorsPanel().closeTab(editorTab));
// closing the last tab would triger this code again
boolean result = execute(editorTab -> editorTab.getEditorsPanel().closeTab(editorTab));
if (!result) return;
// closing the last tab would trigger this code again
if (allWindows.contains(this)) {
allWindows.remove(this);
dispose();
Expand Down
23 changes: 23 additions & 0 deletions test-integration/studio/ui/EditorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package studio.ui;

import org.assertj.swing.core.GenericTypeMatcher;
import org.assertj.swing.finder.WindowFinder;
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.fixture.JMenuItemFixture;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -94,6 +97,26 @@ public void testUndoActionEnable() {

frameFixture.menuItem("Undo").requireEnabled();
frameFixture.button("toolbarUndo").requireEnabled();
}

@Test
public void testCancelOnFrameClosure() {
frameFixture.menuItem("New Window").click();
FrameFixture newFrameFixture = WindowFinder.findFrame(
new GenericTypeMatcher<StudioWindow>(StudioWindow.class, true) {
@Override
protected boolean isMatching(StudioWindow f) {
return f != studioWindow;
}
}).using(robot());
newFrameFixture.textBox("editor1").enterText("x");
newFrameFixture.menuItem("Close Window").click();
optionPaneButtonClick("Cancel");
newFrameFixture.requireVisible();

//tear down
newFrameFixture.close();
optionPaneButtonClick("No");
newFrameFixture.requireNotVisible();

Check failure on line 120 in test-integration/studio/ui/EditorTest.java

View workflow job for this annotation

GitHub Actions / JUnit Tests

studio.ui.EditorTest ► testCancelOnFrameClosure

Failed test found in: build/test-results/integrationTest/TEST-studio.ui.EditorTest.xml Error: org.junit.ComparisonFailure: [studio.ui.StudioWindow[name='studioWindow2', title='Script2 (not saved) Studio for kdb+ dz3.0.1', enabled=true, visible=true, showing=true] - property:'visible'] expected:<[fals]e> but was:<[tru]e>
Raw output
org.junit.ComparisonFailure: [studio.ui.StudioWindow[name='studioWindow2', title='Script2 (not saved) Studio for kdb+ dz3.0.1', enabled=true, visible=true, showing=true] - property:'visible'] expected:<[fals]e> but was:<[tru]e>
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at studio.ui.EditorTest.testCancelOnFrameClosure(EditorTest.java:120)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
}
}
13 changes: 13 additions & 0 deletions test-integration/studio/ui/StudioTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import org.assertj.swing.annotation.GUITest;
import org.assertj.swing.core.EmergencyAbortListener;
import org.assertj.swing.core.MouseButton;
import org.assertj.swing.finder.JOptionPaneFinder;
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.fixture.JOptionPaneFixture;
import org.assertj.swing.fixture.JTabbedPaneFixture;
import org.assertj.swing.fixture.JTextComponentFixture;
import org.assertj.swing.junit.runner.GUITestRunner;
Expand Down Expand Up @@ -235,4 +237,15 @@ protected void waitForQueryExecution(Runnable runQuery) {
waitForQueryExecution(runQuery,1);
}


protected void optionPaneButtonClick(FrameFixture frameFixture, String btnText) {
JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane().using(robot());
optionPane.buttonWithText(btnText).click();

}

protected void optionPaneButtonClick(String btnText) {
optionPaneButtonClick(frameFixture, btnText);
}

}

0 comments on commit 74ec51d

Please sign in to comment.