Skip to content

Commit

Permalink
fix(tests): test public interface for visibility icons and move test …
Browse files Browse the repository at this point in the history
…reset to before block

Signed-off-by: thelooter <[email protected]>
  • Loading branch information
thelooter committed Nov 18, 2024
1 parent e7f5888 commit 5dafe56
Showing 1 changed file with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import com.github.catppuccin.jetbrains_icons.Icons
import com.github.catppuccin.jetbrains_icons.providers.JavaIconProvider
import com.github.catppuccin.jetbrains_icons.settings.PluginSettingsState
import com.intellij.icons.AllIcons
import com.intellij.ide.projectView.ProjectView
import com.intellij.ide.projectView.impl.ProjectViewState
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase5
import com.intellij.testFramework.runInEdtAndGet
import com.intellij.ui.LayeredIcon
import com.intellij.ui.RowIcon
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
Expand All @@ -28,6 +32,12 @@ class JavaIconProviderTest : LightJavaCodeInsightFixtureTestCase5() {
private val icons = Icons("mocha")
private val provider = JavaIconProvider()

@BeforeEach
fun setUp() {
PluginSettingsState.instance.javaSupport = true
ProjectViewState.getInstance(fixture.project).showVisibilityIcons = false
}

@Test
@DisplayName("Test icon provision for a standard Java class")
fun getIcon_javaClass() {
Expand Down Expand Up @@ -256,15 +266,11 @@ class JavaIconProviderTest : LightJavaCodeInsightFixtureTestCase5() {
)

// Temporarily disable Java support
val originalSetting = PluginSettingsState.instance.javaSupport
PluginSettingsState.instance.javaSupport = false

val icon = runInEdtAndGet { provider.getIcon(fixture.findClass("SomeClass"), 1) }

assertEquals(icons.java, icon)

// Restore original setting
PluginSettingsState.instance.javaSupport = originalSetting
}

@Test
Expand All @@ -278,9 +284,11 @@ class JavaIconProviderTest : LightJavaCodeInsightFixtureTestCase5() {
.trimIndent(),
)

val icon = runInEdtAndGet { provider.getVisibilityIcon(fixture.findClass("PublicClass")) }
ProjectViewState.getInstance(fixture.project).showVisibilityIcons = true

val icon = runInEdtAndGet { provider.getIcon(fixture.findClass("PublicClass"),1) }

assertEquals(AllIcons.Nodes.Public, icon)
assertEquals(AllIcons.Nodes.Public, (icon as RowIcon).getIcon(1))
}

@Test
Expand All @@ -296,11 +304,13 @@ class JavaIconProviderTest : LightJavaCodeInsightFixtureTestCase5() {
.trimIndent(),
)

ProjectViewState.getInstance(fixture.project).showVisibilityIcons = true

val icon = runInEdtAndGet {
provider.getVisibilityIcon(fixture.findClass("OuterClass.PrivateClass"))
provider.getIcon(fixture.findClass("OuterClass.PrivateClass"),1)
}

assertEquals(AllIcons.Nodes.Private, icon)
assertEquals(AllIcons.Nodes.Private, (icon as RowIcon).getIcon(1))
}

@Test
Expand All @@ -316,11 +326,13 @@ class JavaIconProviderTest : LightJavaCodeInsightFixtureTestCase5() {
.trimIndent(),
)

ProjectViewState.getInstance(fixture.project).showVisibilityIcons = true

val icon = runInEdtAndGet {
provider.getVisibilityIcon(fixture.findClass("OuterClass.ProtectedClass"))
provider.getIcon(fixture.findClass("OuterClass.ProtectedClass"),1)
}

assertEquals(AllIcons.Nodes.Protected, icon)
assertEquals(AllIcons.Nodes.Protected, (icon as RowIcon).getIcon(1))
}

@Test
Expand All @@ -334,10 +346,12 @@ class JavaIconProviderTest : LightJavaCodeInsightFixtureTestCase5() {
.trimIndent(),
)

ProjectViewState.getInstance(fixture.project).showVisibilityIcons = true

val icon = runInEdtAndGet {
provider.getVisibilityIcon(fixture.findClass("PackagePrivateClass"))
provider.getIcon(fixture.findClass("PackagePrivateClass"),1)
}

assertEquals(AllIcons.Nodes.PackageLocal, icon)
assertEquals(AllIcons.Nodes.PackageLocal, (icon as RowIcon).getIcon(1))
}
}

0 comments on commit 5dafe56

Please sign in to comment.