AnalyzeSizeToolWindow { public JPanel getContent() { window.validate(); return window; } AnalyzeSizeToolWindow(
      ToolWindow toolWindow,
      Project project,
      ImmutableListMultimap<Category, Suggestion> categorizedSuggestions,
      ImmutableList<Category> categoryDisplayOrder); JPanel getContent(); void setCategorizedSuggestions(
      ImmutableListMultimap<Category, Suggestion> categorizedSuggestions); void setCategoryDisplayOrder(ImmutableList<Category> categoryDisplayOrder);  }
@Test public void selectingTreeNodeChangesDescriptionPanel() { JPanel toolPanel = toolWindow.getContent(); Component[] components = toolPanel.getComponents(); OnePixelSplitter splitter = (OnePixelSplitter) components[0]; JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent(); JViewport leftView = leftPane.getViewport(); Tree suggestionTree = (Tree) leftView.getView(); JPanel rightPane = (JPanel) splitter.getSecondComponent(); assertThat(suggestionTree.getSelectionCount()).isEqualTo(0); for (Component component : rightPane.getComponents()) { if (component instanceof JButton || component instanceof JBLabel || component instanceof HyperlinkLabel) { assertThat(component.isVisible()).isFalse(); } } TreePath webPPath = getTreePathWithString(suggestionTree, webPSuggestionData.toString()); suggestionTree.addSelectionPath(webPPath); assertThat(suggestionTree.getSelectionCount()).isEqualTo(1); for (Component component : rightPane.getComponents()) { if (component instanceof JButton || component instanceof JBLabel || component instanceof HyperlinkLabel) { assertThat(component.isVisible()).isTrue(); } if (component instanceof JButton) { assertThat(((JButton) component).getText()).isEqualTo(webPSuggestionData.getAutoFixTitle()); } if (component instanceof JBLabel) { assertThat(((JBLabel) component).getText()) .containsMatch( "(" + webPSuggestionData.getTitle() + "|" + webPSuggestionData.getDesc() + ")"); } } }
@Test public void selectingCategoryNodeChangesCategoryPanel() { JPanel toolPanel = toolWindow.getContent(); Component[] components = toolPanel.getComponents(); OnePixelSplitter splitter = (OnePixelSplitter) components[0]; JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent(); JViewport leftView = leftPane.getViewport(); Tree suggestionTree = (Tree) leftView.getView(); assertThat(suggestionTree.getSelectionCount()).isEqualTo(0); TreePath webPPath = getTreePathWithString(suggestionTree, webPCategoryData.toString()); suggestionTree.addSelectionPath(webPPath); JPanel rightPane = (JPanel) splitter.getSecondComponent(); assertThat(suggestionTree.getSelectionCount()).isEqualTo(1); for (Component component : rightPane.getComponents()) { if (component instanceof SimpleColoredComponent) { assertThat(component.toString()).contains(webPCategoryData.toString()); assertThat(component.toString()).contains("Estimated savings: 29.30 KB"); } else if (component instanceof JPanel) { Component[] suggestionPanelComponents = ((JPanel) component).getComponents(); assertThat(suggestionPanelComponents).hasLength(1); for (Component linkLabel : suggestionPanelComponents) { assertThat(((LinkLabel<?>) linkLabel).getText()).isEqualTo(SuggestionDataFactory.issueTypeNodeNames.get(IssueType.WEBP)); } } } }
@Test public void categoryNodesHaveCorrectExtraInformation() { JPanel toolPanel = toolWindow.getContent(); Component[] components = toolPanel.getComponents(); OnePixelSplitter splitter = (OnePixelSplitter) components[0]; JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent(); JViewport leftView = leftPane.getViewport(); Tree suggestionTree = (Tree) leftView.getView(); TreePath webPPath = getTreePathWithString(suggestionTree, webPCategoryData.toString()); TreeCellRenderer treeCellRenderer = suggestionTree.getCellRenderer(); Component renderedNode = treeCellRenderer.getTreeCellRendererComponent( suggestionTree, webPPath.getLastPathComponent(), false, false, false, suggestionTree.getRowForPath(webPPath), false); assertThat(renderedNode.toString()).contains("2 recommendations"); assertThat(renderedNode.toString()).contains("29.30 KB"); }
@Test public void multipleSuggestionsCreateIssueTypeNode() { JPanel toolPanel = toolWindow.getContent(); Component[] components = toolPanel.getComponents(); OnePixelSplitter splitter = (OnePixelSplitter) components[0]; JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent(); JViewport leftView = leftPane.getViewport(); Tree suggestionTree = (Tree) leftView.getView(); TreePath webPIssuePath = getTreePathWithString( suggestionTree, SuggestionDataFactory.issueTypeNodeNames.get(IssueType.WEBP)); DefaultMutableTreeNode webPIssueNode = (DefaultMutableTreeNode) webPIssuePath.getLastPathComponent(); assertThat(webPIssueNode.getChildCount()).isEqualTo(2); }
@Test public void autofixIsNotShownWhenNull() { JPanel toolPanel = toolWindow.getContent(); Component[] components = toolPanel.getComponents(); OnePixelSplitter splitter = (OnePixelSplitter) components[0]; JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent(); JViewport leftView = leftPane.getViewport(); Tree suggestionTree = (Tree) leftView.getView(); JPanel rightPane = (JPanel) splitter.getSecondComponent(); TreePath streamingPath = getTreePathWithString(suggestionTree, streamingSuggestionData.toString()); suggestionTree.addSelectionPath(streamingPath); for (Component component : rightPane.getComponents()) { if (component instanceof JButton) { assertThat(component.isVisible()).isFalse(); } } }