mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-13 10:42:09 +10:00
Controllers (#1080)
* initial * more components * fixes * Update TreePanel.java * fix boost converter * Improve wrapping of component names * Update ULN2003Driver.java * Update NRF24L01Transceiver.java * imp * updates * improvements * more components * arduino * uno * icon * cleanup * mega * mega * improveent * nano * esp boards * esp * esp32 * esp32 * Update ESP8266NodeMCU.java * d1 * Update WemosD1Mini.java * pi * consolidate esp32 * pi pico updates * pi zero * Update RaspberryPiZero.java * pi pico * cleanup * pi improvements * consolidate pins * antenna consolidation * improve solder pads * teensy * headers * teensy fix, test cleanup * s3 * Update ESP32DevKit.java * usb standardization * pico w * button standardization * arduino improvements * Update AbstractMakerBoard.java * Update RaspberryPiZero.java * Update RaspberryPi.java * pi 3 * pi 5 improvements * Update RaspberryPiZero.java * fix tests * esp pinout fix * Update ESP32DevKit.java * pin name improvements * Create tier-1-modern-boards.md * new versions * pinouts * nano improvements * sanitize node names * label improvements * minima fixes * arduino uno labels * nano labels * Update ArduinoNano.java * mega * mega * comment out future stuff * release prep * Update RaspberryPiPico.java * Refactor abstract class * labeling improvement * label offset fixes * Update Teensy.java * consolidate tests * micro variants * Update RaspberryPi.java * displays tweaks * display improvements * neopix * displays * improvements * led matrix * strip * led bar graph * jewel * tft * tft * Update maker-peripherals.md * nokia * led bar * labels * tft * cleanup * oled * cleanup * display enhancement * displays * neopixel * displays * displays * new tft * displays * icon * variants * 2-digit 0.56 inch 7 segment * Added ability to hide component categories in the component tree and toolbar from the Config menu * led bar * Update variants.xml * color selection for bar graph * Added 1.8" sd * tft fixes * Update WS2812BRing.java * neopixel improvements * netlist and node name improvements * oled tweak * cleanup * mockito fix --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,12 +2,27 @@ package org.diylc;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.Template;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.ActionFactory;
|
||||
import org.diylc.swing.actions.ComponentCategoryAction;
|
||||
import org.diylc.swing.actions.ResetCategoriesAction;
|
||||
import org.diylc.swing.plugins.tree.CustomTreeModel;
|
||||
|
||||
public class PresenterTests extends TestBase {
|
||||
|
||||
@@ -98,6 +113,114 @@ public class PresenterTests extends TestBase {
|
||||
presenter.mouseMoved(new Point(1000, 1000), false, false, false);
|
||||
Assert.assertNull(receivedTooltip[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCategoryVisibilityDefaults() {
|
||||
presenter.resetCategoryVisibility();
|
||||
Map<String, List<ComponentType>> all = presenter.getComponentTypes();
|
||||
Map<String, List<ComponentType>> visible = presenter.getVisibleComponentTypes();
|
||||
Assert.assertEquals(all.keySet(), visible.keySet());
|
||||
for (String category : all.keySet()) {
|
||||
Assert.assertTrue(presenter.isCategoryEnabled(category));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDisableAndEnableCategory() {
|
||||
presenter.resetCategoryVisibility();
|
||||
|
||||
final Set<String>[] lastEventDisabled = new Set[1];
|
||||
IPlugIn testPlugin = new IPlugIn() {
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.COMPONENT_CATEGORIES_CHANGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processMessage(EventType eventType, Object... params) {
|
||||
if (eventType == EventType.COMPONENT_CATEGORIES_CHANGED && params.length > 0) {
|
||||
lastEventDisabled[0] = (Set<String>) params[0];
|
||||
}
|
||||
}
|
||||
};
|
||||
presenter.installPlugin(() -> testPlugin);
|
||||
|
||||
// Disable "Tubes"
|
||||
presenter.setCategoryEnabled("Tubes", false);
|
||||
Assert.assertFalse(presenter.isCategoryEnabled("Tubes"));
|
||||
Assert.assertFalse(presenter.getVisibleComponentTypes().containsKey("Tubes"));
|
||||
Assert.assertTrue(presenter.getComponentTypes().containsKey("Tubes"));
|
||||
Assert.assertNotNull(lastEventDisabled[0]);
|
||||
Assert.assertTrue(lastEventDisabled[0].contains("Tubes"));
|
||||
|
||||
// Also disable "Robotics"
|
||||
presenter.setCategoryEnabled("Robotics", false);
|
||||
Assert.assertFalse(presenter.isCategoryEnabled("Robotics"));
|
||||
Assert.assertFalse(presenter.getVisibleComponentTypes().containsKey("Robotics"));
|
||||
Assert.assertTrue(lastEventDisabled[0].contains("Robotics"));
|
||||
Assert.assertTrue(lastEventDisabled[0].contains("Tubes"));
|
||||
|
||||
// Check config stores sorted list
|
||||
List<String> stored = (List<String>) InMemoryConfigurationManager.getInstance()
|
||||
.readObject(IPlugInPort.DISABLED_CATEGORIES_KEY, new ArrayList<String>());
|
||||
Assert.assertEquals(2, stored.size());
|
||||
Assert.assertEquals("Robotics", stored.get(0));
|
||||
Assert.assertEquals("Tubes", stored.get(1));
|
||||
|
||||
// Re-enable "Tubes"
|
||||
presenter.setCategoryEnabled("Tubes", true);
|
||||
Assert.assertTrue(presenter.isCategoryEnabled("Tubes"));
|
||||
Assert.assertTrue(presenter.getVisibleComponentTypes().containsKey("Tubes"));
|
||||
Assert.assertFalse(lastEventDisabled[0].contains("Tubes"));
|
||||
Assert.assertTrue(lastEventDisabled[0].contains("Robotics"));
|
||||
|
||||
// Reset all
|
||||
presenter.resetCategoryVisibility();
|
||||
Assert.assertTrue(presenter.isCategoryEnabled("Robotics"));
|
||||
Assert.assertTrue(presenter.isCategoryEnabled("Tubes"));
|
||||
Assert.assertTrue(lastEventDisabled[0].isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComponentCategoryActions() {
|
||||
Presenter prodPresenter = new Presenter(view, ConfigurationManager.getInstance());
|
||||
prodPresenter.resetCategoryVisibility();
|
||||
|
||||
ComponentCategoryAction catAction =
|
||||
ActionFactory.getInstance().createComponentCategoryAction(prodPresenter, "Tubes");
|
||||
Assert.assertEquals(true, catAction.getValue(javax.swing.AbstractAction.SELECTED_KEY));
|
||||
|
||||
// Toggle off
|
||||
catAction.putValue(javax.swing.AbstractAction.SELECTED_KEY, false);
|
||||
catAction.actionPerformed(null);
|
||||
Assert.assertFalse(prodPresenter.isCategoryEnabled("Tubes"));
|
||||
|
||||
// Reset via ResetCategoriesAction
|
||||
ResetCategoriesAction resetAction =
|
||||
ActionFactory.getInstance().createResetCategoriesAction(prodPresenter);
|
||||
resetAction.actionPerformed(null);
|
||||
Assert.assertTrue(prodPresenter.isCategoryEnabled("Tubes"));
|
||||
Assert.assertEquals(true, catAction.getValue(javax.swing.AbstractAction.SELECTED_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomTreeModelRefresh() {
|
||||
presenter.resetCategoryVisibility();
|
||||
CustomTreeModel treeModel = new CustomTreeModel(presenter);
|
||||
Assert.assertTrue(presenter.isCategoryEnabled("Tubes"));
|
||||
|
||||
presenter.setCategoryEnabled("Tubes", false);
|
||||
treeModel.refresh();
|
||||
Assert.assertFalse(presenter.getVisibleComponentTypes().containsKey("Tubes"));
|
||||
|
||||
presenter.resetCategoryVisibility();
|
||||
treeModel.refresh();
|
||||
Assert.assertTrue(presenter.getVisibleComponentTypes().containsKey("Tubes"));
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testLoadVariants() {
|
||||
|
||||
Reference in New Issue
Block a user