浏览代码

Fix up StepPanel to properly link the Instruction pane

Sam Jaffe 5 年之前
父节点
当前提交
fba9dfb52f

+ 0 - 1
src/main/lombok/org/leumasjaffe/recipe/view/PhasePanel.java

@@ -36,7 +36,6 @@ public class PhasePanel extends JPanel {
 				step -> {
 					steps.add(step);
 					listener.setObserved(phase, allChildren(phase));
-					ObserverDispatch.notifySubscribers(phase);
 				},
 				i -> {
 					steps.remove(i);

+ 4 - 1
src/main/lombok/org/leumasjaffe/recipe/view/StepPanel.java

@@ -32,6 +32,7 @@ import java.awt.Dimension;
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
 public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenable {
 	ForwardingObservableListener<Step> listener = new ForwardingObservableListener<>();
+	ObservableListener<JTextPane, Step> intructionListener;
 	ObservableListener<JFormattedTextField, Step> durationListener;
 
 	@Getter(AccessLevel.PACKAGE) JLabel lblIndex;
@@ -101,17 +102,19 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
 		
 		txtpnInstructions = new JTextPane();
 		txtpnInstructions.setPreferredSize(new Dimension(200, 30));
-		txtpnInstructions.setText(step.getInstruction());
 		GridBagConstraints gbc_txtpnInstructions = new GridBagConstraints();
 		gbc_txtpnInstructions.fill = GridBagConstraints.BOTH;
 		gbc_txtpnInstructions.gridx = 1;
 		gbc_txtpnInstructions.gridy = 0;
 		add(txtpnInstructions, gbc_txtpnInstructions);
 		
+		intructionListener = ObservableController.from(txtpnInstructions,
+				Step::getInstruction, Step::setInstruction);
 		durationListener = ObservableController.from(panelDuration.txtTime,
 				Step::getDuration, Step::setDuration);
 		
 		listener.setObserved(step, ingredients);
+		intructionListener.setObserved(step);
 		durationListener.setObserved(step);
 	}
 

+ 19 - 3
src/test/java/org/leumasjaffe/recipe/view/StepPanelTest.java

@@ -33,9 +33,8 @@ class StepPanelTest extends SwingTestCase {
 
 	@BeforeEach
 	void setUp() {
-		Duration dur = new Duration(Duration.Display.SECONDS, 0, 30);
 		ingredients = new ArrayList<>(Arrays.asList(new Ingredient("Onion", "Sliced", new Amount("100 g"))));
-		doReturn(dur).when(stuff).getDuration();
+		doReturn(new Duration("30 s")).when(stuff).getDuration();
 		doReturn("These are test instructions").when(stuff).getInstruction();
 		doReturn(ingredients).when(stuff).getIngredients();
 		
@@ -50,7 +49,24 @@ class StepPanelTest extends SwingTestCase {
 				arrayWithSize(greaterThanOrEqualTo(1)));
 	}
 	
-	// TODO: Write tests for modifying the txtpnInstructions
+	// TODO: Test added ingredients regenerate AutoGrowPanel... ?
+	
+	@Test
+	void testUpdatesContentOnNotification() {
+		doReturn("New instructions").when(stuff).getInstruction();
+		ObserverDispatch.notifySubscribers(stuff);
+		
+		assertEquals("New instructions", panel.getTxtpnInstructions().getText());
+	}
+	
+
+	@Test
+	void testViewUpdatesAltersModel() {
+		panel.getTxtpnInstructions().setText("New instructions");
+		waitForSwing();
+		
+		verify(stuff).setInstruction(eq("New instructions"));
+	}
 
 	@Test
 	void testPropogatesNotifications() {