Skip to content

Commit

Permalink
Apply some changes based on IDE inspection results
Browse files Browse the repository at this point in the history
  • Loading branch information
picimako committed Jun 3, 2024
1 parent 16e21d0 commit 5d8e6d9
Show file tree
Hide file tree
Showing 22 changed files with 321 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ private String buildDocumentation(String viewport) {
+ CONTENT_END;
}

private static final class Breakpoint {
private final String minimumValue;
private final String mediaQuery;
private final String description;

Breakpoint(String minimumValue, String mediaQuery, String description) {
this.minimumValue = minimumValue;
this.mediaQuery = mediaQuery;
this.description = description;
}
private record Breakpoint(String minimumValue, String mediaQuery, String description) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public boolean isModified() {
}

@Override
public void apply() throws ConfigurationException {
public void apply() {
var settings = TerraApplicationState.getInstance();
settings.wdioRootPaths = component.getWdioRootPaths();
settings.showConfirmationBeforeScreenshotDeletion = component.isScreenshotDeletionConfirmationCheckboxSelected();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/picimako/terra/wdio/TerraWdioFolders.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
Expand Down Expand Up @@ -46,6 +47,7 @@ public final class TerraWdioFolders {
private static final String LATEST_RELATIVE_PATH = "/" + SNAPSHOTS + "/" + LATEST;

//TODO: this might be problematic with multiple projects having different wdio paths
@Setter
private static String wdioTestRootPath;

/**
Expand Down Expand Up @@ -358,10 +360,6 @@ public static String diffPath() {
return wdioTestRootPath + DIFF_RELATIVE_PATH;
}

public static void setWdioTestRootPath(String path) {
wdioTestRootPath = path;
}

@TestOnly
public static String getWdioTestRootPath() {
return wdioTestRootPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ public void addPropertyChangeListener(@NotNull PropertyChangeListener listener)
public void removePropertyChangeListener(@NotNull PropertyChangeListener listener) {
}

@Override
public @Nullable FileEditorLocation getCurrentLocation() {
return null;
}

@Override
public void dispose() {
var imageEditorCache = ImageEditorCache.getInstance(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.ui.TreeUIHelper;
import com.intellij.ui.components.JBScrollPane;
import lombok.Getter;

import com.picimako.terra.wdio.toolwindow.event.KeyboardListeningPopupMenuInvoker;
import com.picimako.terra.wdio.toolwindow.event.MouseListeningPopupMenuInvoker;
Expand All @@ -36,6 +37,7 @@ public class TerraWdioScreenshotsPanel extends JPanel {

private static final String SCREENSHOT_ACTIONS_GROUP = "terra.wdio.toolwindow.ScreenshotActionsGroup";
private final transient Project project;
@Getter
private TerraWdioTree tree;

public TerraWdioScreenshotsPanel(Project project) {
Expand All @@ -55,10 +57,6 @@ private void buildGUI() {
TreeUIHelper.getInstance().installTreeSpeedSearch(tree);
}

public TerraWdioTree getTree() {
return tree;
}

/**
* Registers actions and listeners to the tool window tree.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.SmartList;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -24,6 +25,7 @@
* (called references in this context), so that the file system resources can be reached and manipulated easier.
*/
public abstract class AbstractTerraWdioTreeNode implements TerraWdioTreeNode {
@Getter
protected final List<VirtualFile> references = new SmartList<>();
protected final String displayName;
protected final Project project;
Expand All @@ -47,10 +49,6 @@ public void addReference(VirtualFile virtualFile) {
references.add(virtualFile);
}

public List<VirtualFile> getReferences() {
return references;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/com/picimako/terra/DirectoryPsiUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ protected String getTestDataPath() {

public void testNotReturnDirectoryWhenDirectoryPathIsNull() {
myFixture.configureByFile("tests/wdio/MissingScreenshots-spec.js");
PsiDirectory tests = DirectoryPsiUtil.findDirectory(getProject(), null);

assertThat(tests).isNull();
assertThat(DirectoryPsiUtil.findDirectory(getProject(), null)).isNull();
}

public void testNotReturnDirectorySubDirectoryIsNull() {
myFixture.configureByFile("tests/wdio/MissingScreenshots-spec.js");
PsiDirectory tests = DirectoryPsiUtil.findDirectory(getProject(), "tests/jest");

assertThat(tests).isNull();
assertThat(DirectoryPsiUtil.findDirectory(getProject(), "tests/jest")).isNull();
}

public void testReturnDirectoryForName() {
Expand Down
77 changes: 40 additions & 37 deletions src/test/java/com/picimako/terra/JavaScriptTestFileSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,48 @@
*/
public final class JavaScriptTestFileSupport {

public static final String FILE_WITH_IMPORT = "import React, { useState } from 'react';\n" +
"import Placeholder from '@cerner/terra-docs';\n" +
"import ResponsiveElement from 'terra-responsive-element';\n" +
"import SomeNotTerraComponent from 'not-terra-component';\n" +
"const BreakpointExample = () => {\n" +
" const [breakpoint, setBreakpoint] = useState('');\n" +
" return (\n" +
" <ResponsiveElement onChange={value => setBreakpoint(value)}>\n" +
" <Placeholder title={breakpoint} />\n" +
" </ResponsiveElement>\n" +
" <SomeNotTerraComponent />\n" +
" );\n" +
"};\n" +
"export default BreakpointExample;";
public static final String FILE_WITH_IMPORT = """
import React, { useState } from 'react';
import Placeholder from '@cerner/terra-docs';
import ResponsiveElement from 'terra-responsive-element';
import SomeNotTerraComponent from 'not-terra-component';
const BreakpointExample = () => {
const [breakpoint, setBreakpoint] = useState('');
return (
<ResponsiveElement onChange={value => setBreakpoint(value)}>
<Placeholder title={breakpoint} />
</ResponsiveElement>
<SomeNotTerraComponent />
);
};
export default BreakpointExample;""";

public static final String FILE_WITHOUT_IMPORT = "import React, { useState } from 'react';\n" +
"import Placeholder from '@cerner/terra-docs';\n" +
"const BreakpointExample = () => {\n" +
" const [breakpoint, setBreakpoint] = useState('');\n" +
" return (\n" +
" <ResponsiveElement onChange={value => setBreakpoint(value)}>\n" +
" <Placeholder title={breakpoint} />\n" +
" </ResponsiveElement>\n" +
" );\n" +
"};\n" +
"export default BreakpointExample;";
public static final String FILE_WITHOUT_IMPORT = """
import React, { useState } from 'react';
import Placeholder from '@cerner/terra-docs';
const BreakpointExample = () => {
const [breakpoint, setBreakpoint] = useState('');
return (
<ResponsiveElement onChange={value => setBreakpoint(value)}>
<Placeholder title={breakpoint} />
</ResponsiveElement>
);
};
export default BreakpointExample;""";

public static final String FILE_WITHOUT_IMPORT_FROM_CLAUSE = "import React, { useState } from 'react';\n" +
"import Placeholder from '@cerner/terra-docs';\n" +
"import ResponsiveElement;\n" +
"const BreakpointExample = () => {\n" +
" const [breakpoint, setBreakpoint] = useState('');\n" +
" return (\n" +
" <ResponsiveElement onChange={value => setBreakpoint(value)}>\n" +
" <Placeholder title={breakpoint} />\n" +
" </ResponsiveElement>\n" +
" );\n" +
"};\n" +
"export default BreakpointExample;";
public static final String FILE_WITHOUT_IMPORT_FROM_CLAUSE = """
import React, { useState } from 'react';
import Placeholder from '@cerner/terra-docs';
import ResponsiveElement;
const BreakpointExample = () => {
const [breakpoint, setBreakpoint] = useState('');
return (
<ResponsiveElement onChange={value => setBreakpoint(value)}>
<Placeholder title={breakpoint} />
</ResponsiveElement>
);
};
export default BreakpointExample;""";

/**
* Creates a {@link PsiFile} object from the argument file content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,44 @@
*/
public class DocumentationComponentsTest {

private static final String DOCUMENTATION = "{\n" +
" \"components\": [\n" +
" {\n" +
" \"componentName\": \"ActionFooter\",\n" +
" \"properties\": [\n" +
" {\n" +
" \"importPath\": \"terra-action-footer\",\n" +
" \"relativeUrl\": \"/terra-action-footer/action-footer/standard\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"componentName\": \"ActionHeader\",\n" +
" \"properties\": [\n" +
" {\n" +
" \"importPath\": \"terra-action-header\",\n" +
" \"relativeUrl\": \"/terra-action-header/action-header/action-header\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"componentName\": \"Item\",\n" +
" \"properties\": [\n" +
" {\n" +
" \"family\": \"Dropdown Button\",\n" +
" \"importPath\": \"terra-dropdown-button\",\n" +
" \"relativeUrl\": \"/terra-dropdown-button/dropdown-button/dropdown-button\"\n" +
" },\n" +
" {\n" +
" \"family\": \"List\",\n" +
" \"importPath\": \"terra-list/lib/index\",\n" +
" \"relativeUrl\": \"/terra-list/list/list-item\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" ]\n" +
"}";
private static final String DOCUMENTATION = """
{
"components": [
{
"componentName": "ActionFooter",
"properties": [
{
"importPath": "terra-action-footer",
"relativeUrl": "/terra-action-footer/action-footer/standard"
}
]
},
{
"componentName": "ActionHeader",
"properties": [
{
"importPath": "terra-action-header",
"relativeUrl": "/terra-action-header/action-header/action-header"
}
]
},
{
"componentName": "Item",
"properties": [
{
"family": "Dropdown Button",
"importPath": "terra-dropdown-button",
"relativeUrl": "/terra-dropdown-button/dropdown-button/dropdown-button"
},
{
"family": "List",
"importPath": "terra-list/lib/index",
"relativeUrl": "/terra-list/list/list-item"
}
]
}
]
}""";
private static final DocumentationComponents COMPONENTS = new Gson().fromJson(DOCUMENTATION, DocumentationComponents.class);

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ public void testShouldReturnNullWhenInputElementIsLiteralButNotStringInDescribeT

public void testShouldReturnNullWhenTheStringLiteralIsNotInTerraDescribeViewportsOrDescribeTests() {
myFixture.configureByText("WdioDocumentation-spec.js",
"Terra.describeViewports('viewports', ['huge'], () => {\n" +
" describe('terra screenshot', () => {\n" +
" Terra.validates.element('coll<caret>ect');\n" +
" });" +
"});");
"""
Terra.describeViewports('viewports', ['huge'], () => {
describe('terra screenshot', () => {
Terra.validates.element('coll<caret>ect');
});\
});""");

PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@
*/
public class TerraUIComponentDocumentationUrlProviderTest extends BasePlatformTestCase {

private static final String DOCUMENTATION = "{\n" +
" \"components\": [\n" +
" {\n" +
" \"componentName\": \"ResponsiveElement\",\n" +
" \"properties\": [\n" +
" {\n" +
" \"importPath\": \"terra-responsive-element\",\n" +
" \"relativeUrl\": \"/terra-responsive-element/responsive-element/responsive-element\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" ]\n" +
"}";
private static final String DOCUMENTATION = """
{
"components": [
{
"componentName": "ResponsiveElement",
"properties": [
{
"importPath": "terra-responsive-element",
"relativeUrl": "/terra-responsive-element/responsive-element/responsive-element"
}
]
}
]
}""";

private static final String DOCUMENTATION_HTML = "<code>C:\\projects\\plugindev\\somefilename.js</code>" +
"<br>" +
Expand Down
Loading

0 comments on commit 5d8e6d9

Please sign in to comment.