| 1 | package org.sophie2.dev.author; |
| 2 | |
| 3 | import java.util.Arrays; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import javax.swing.SwingUtilities; |
| 7 | |
| 8 | import org.junit.Before; |
| 9 | import org.junit.Test; |
| 10 | import org.sophie2.base.bound.BoundModule; |
| 11 | import org.sophie2.base.commons.BaseCommonsModule; |
| 12 | import org.sophie2.base.dialogs.BaseDialogsModule; |
| 13 | import org.sophie2.base.dialogs.TestingDialogManager; |
| 14 | import org.sophie2.base.halos.HaloButton; |
| 15 | import org.sophie2.base.model.resources.r4.ResourceRefR4; |
| 16 | import org.sophie2.base.model.resources.r4.changes.AutoAction; |
| 17 | import org.sophie2.base.model.text.BaseModelTextModule; |
| 18 | import org.sophie2.base.model.text.model.ImmHotText; |
| 19 | import org.sophie2.base.model.text.model.ImmText; |
| 20 | import org.sophie2.base.skins.Message; |
| 21 | import org.sophie2.core.modularity.SophieModule; |
| 22 | import org.sophie2.core.mvc.LogicR3; |
| 23 | import org.sophie2.core.mvc.events.EventR3; |
| 24 | import org.sophie2.dev.testing.SystemTestBase; |
| 25 | import org.sophie2.main.app.commons.book.BaseBookView; |
| 26 | import org.sophie2.main.app.commons.page.RootPageView; |
| 27 | import org.sophie2.main.app.halos.MainAppHalosModule; |
| 28 | import org.sophie2.main.app.halos.frame.FrameRemoveHaloButton; |
| 29 | import org.sophie2.main.app.halos.shared.MainHaloMenu; |
| 30 | import org.sophie2.main.app.layout.MainAppLayoutModule; |
| 31 | import org.sophie2.main.app.menus.MainAppMenusModule; |
| 32 | import org.sophie2.main.app.model.MainAppModelModule; |
| 33 | import org.sophie2.main.dialogs.input.ConfirmDialogInput; |
| 34 | import org.sophie2.main.func.resources.MainFuncResourcesModule; |
| 35 | import org.sophie2.main.func.text.TextFuncModule; |
| 36 | import org.sophie2.main.func.text.chaining.ChainingMode; |
| 37 | import org.sophie2.main.func.text.model.HeadTextFrameH; |
| 38 | import org.sophie2.main.func.text.utils.TextChainUtils; |
| 39 | import org.sophie2.main.func.text.view.HeadTextFrameView; |
| 40 | import org.sophie2.main.func.text.view.TextFrameView; |
| 41 | |
| 42 | /** |
| 43 | * Tests the deleting of auto chained frames. |
| 44 | * |
| 45 | * @author diana |
| 46 | * |
| 47 | */ |
| 48 | public class TestDeleteAutoChainedFrame extends SystemTestBase { |
| 49 | |
| 50 | /** |
| 51 | * Constant created for insertion of a full text frame. |
| 52 | * Constant created to be a parameter of a message of an {@link AutoAction}. |
| 53 | * Used for skinning. Used in the test. |
| 54 | */ |
| 55 | public static final String INSERT_FULL_TEXT_FRAME = "Insert a full text frame"; |
| 56 | |
| 57 | @SuppressWarnings("unchecked") |
| 58 | @Override |
| 59 | protected List<Class<? extends SophieModule>> fillDependencies() { |
| 60 | |
| 61 | List<Class<? extends SophieModule>> res = super.fillDependencies(); |
| 62 | List<Class<? extends SophieModule>> toAppend = |
| 63 | Arrays.asList( |
| 64 | BoundModule.class, |
| 65 | MainAppMenusModule.class, |
| 66 | BaseModelTextModule.class, |
| 67 | MainAppHalosModule.class, |
| 68 | TextFuncModule.class, |
| 69 | MainAppLayoutModule.class, |
| 70 | MainAppModelModule.class, |
| 71 | MainFuncResourcesModule.class, |
| 72 | BaseDialogsModule.class, |
| 73 | BaseCommonsModule.class |
| 74 | ); |
| 75 | |
| 76 | merge(res, toAppend); |
| 77 | |
| 78 | return res; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | @Before |
| 83 | protected void setUp() throws Exception { |
| 84 | super.setUp(); |
| 85 | SwingUtilities.invokeAndWait(new Runnable() { |
| 86 | |
| 87 | @SuppressWarnings("synthetic-access") |
| 88 | public void run() { |
| 89 | createNewBook(); |
| 90 | } |
| 91 | }); |
| 92 | |
| 93 | try { |
| 94 | Thread.sleep(10000); |
| 95 | } catch (InterruptedException e) { |
| 96 | //nothing |
| 97 | } |
| 98 | ImmText text = new ImmHotText( |
| 99 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean dui" + |
| 100 | " ligula, rhoncus id interdum nec, vestibulum non dolor. Suspendisse nec" + |
| 101 | " ante vitae purus pellentesque porttitor. Duis orci elit, blandit blandit" + |
| 102 | " vestibulum sed, dictum ac dolor. Donec sed blandit ante. In pretium arcu" + |
| 103 | " eleifend ligula imperdiet eget tempor nunc viverra. Maecenas interdum " + |
| 104 | "sapien id nisl dignissim pulvinar. Morbi congue, magna a tincidunt" + |
| 105 | " tincidunt, nibh tortor varius ligula, at feugiat ante neque eu nisl." + |
| 106 | " Proin at odio a elit pharetra egestas vel ac nibh. Integer nunc ipsum," + |
| 107 | " ornare quis lobortis vulputate, accumsan eu purus. Phasellus tristique" + |
| 108 | " interdum odio, id vulputate lorem pretium eu. Aenean at nulla libero," + |
| 109 | " sit amet egestas nisl. Sed metus arcu, cursus eu facilisis quis," + |
| 110 | " dignissim eget neque. Nulla facilisi. Sed quam nisl, ornare vitae blandit" + |
| 111 | " at, tristique sagittis quam." |
| 112 | + "Maecenas vel vestibulum lectus. Ut gravida pellentesque turpis at" + |
| 113 | " pharetra. Mauris luctus est nisl. Aenean egestas lectus vitae" + |
| 114 | " dolor luctus in vestibulum purus faucibus. Vivamus eros dolor," + |
| 115 | " tristique vitae tincidunt nec, ullamcorper id erat. Nunc id lorem" + |
| 116 | " lectus, sed tristique neque. Nullam imperdiet ligula ut velit" + |
| 117 | " facilisis gravida. Lorem ipsum dolor sit amet, consectetur" + |
| 118 | " adipiscing elit. Integer eget dolor ipsum. Nullam elementum" + |
| 119 | " lectus a est tincidunt ultricies tempus nisl interdum. Integer" + |
| 120 | " posuere felis eget lectus pellentesque ac vestibulum neque" + |
| 121 | " vulputate. Donec ut lectus quis eros tincidunt sagittis.", null); |
| 122 | |
| 123 | HeadTextFrameH.createTextFrameAction(curBook(), |
| 124 | curPageWorkArea().getRootPageView().model().get(), |
| 125 | text, ResourceRefR4.NONE_REF.toUri(), null, |
| 126 | Message.create(INSERT_FULL_TEXT_FRAME), true, true); |
| 127 | |
| 128 | TextFrameView frameViewToSelect = |
| 129 | curPageWorkArea().getAll(TextFrameView.class).get(0); |
| 130 | curPageWorkArea().getSel().select(frameViewToSelect, false); |
| 131 | |
| 132 | final HeadTextFrameView selectedFrameView = |
| 133 | curPageWorkArea().getSel().getSingleSelected(HeadTextFrameView.class); |
| 134 | assertNotNull(selectedFrameView); |
| 135 | |
| 136 | try { |
| 137 | Thread.sleep(5000); |
| 138 | } catch (InterruptedException e) { |
| 139 | //nothing |
| 140 | } |
| 141 | SwingUtilities.invokeAndWait(new Runnable() { |
| 142 | |
| 143 | @SuppressWarnings("synthetic-access") |
| 144 | public void run() { |
| 145 | assertEquals(ChainingMode.AUTO_CHAINING, selectedFrameView.model().get().getChainMode()); |
| 146 | assertTrue(curBook().getPageCount() >= 2); |
| 147 | |
| 148 | assertTrue(TextChainUtils.getChainedFrameViews( |
| 149 | selectedFrameView.getBookView(), selectedFrameView).size() >= 2); |
| 150 | |
| 151 | } |
| 152 | }); |
| 153 | |
| 154 | } |
| 155 | |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * Tests the deleting of chained frames. |
| 160 | */ |
| 161 | @Test |
| 162 | public void testChainingNavigationDown() { |
| 163 | |
| 164 | HeadTextFrameView selectedFrameView = |
| 165 | curPageWorkArea().getSel().getSingleSelected(HeadTextFrameView.class); |
| 166 | TextFrameView viewToSelect = TextChainUtils.getChainedFrameViews( |
| 167 | selectedFrameView.getBookView(), selectedFrameView).get(1); |
| 168 | assertNotNull(viewToSelect); |
| 169 | |
| 170 | BaseBookView bookView = curPageWorkArea().bookView().get(); |
| 171 | RootPageView page = viewToSelect.findParentElement(RootPageView.class); |
| 172 | bookView.goToPage(ResourceRefR4.getRelativeRef(bookView.getAccess().getRef(), |
| 173 | page.getAccess().getRef())); |
| 174 | curPageWorkArea().getSel().select(viewToSelect, false); |
| 175 | |
| 176 | |
| 177 | MainHaloMenu mainHaloMenu = viewToSelect.findNearestElement(null, MainHaloMenu.class); |
| 178 | FrameRemoveHaloButton removeButton = null; |
| 179 | for (HaloButton button : mainHaloMenu.buttons().get()) { |
| 180 | if (button instanceof FrameRemoveHaloButton) { |
| 181 | removeButton = (FrameRemoveHaloButton) button; |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | assert removeButton != null; |
| 186 | |
| 187 | |
| 188 | try { |
| 189 | TestingDialogManager.get().expect(ConfirmDialogInput.class, |
| 190 | ConfirmDialogInput.Response.YES); |
| 191 | |
| 192 | LogicR3.fire(new EventR3(removeButton, null, null, null, HaloButton.EventIds.HALO_CLICK)); |
| 193 | |
| 194 | } catch (Exception e) { |
| 195 | fail(); |
| 196 | } |
| 197 | |
| 198 | } |
| 199 | |
| 200 | } |