-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The plugin is now implemented as a Service and it now loads any activ…
…e entry on load-up.
1 parent
4b059ff
commit e9b0aae
Showing
11 changed files
with
179 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
src/main/kotlin/io/github/ricardormdev/clockifyplugin/PluginFactory.kt
This file was deleted.
Oops, something went wrong.
5 changes: 4 additions & 1 deletion
5
src/main/kotlin/io/github/ricardormdev/clockifyplugin/PluginLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,40 +9,64 @@ | |
<name>Clockify</name> | ||
|
||
<!-- Indicate this plugin can be loaded in all IntelliJ Platform-based products. --> | ||
<depends>com.intellij.modules.all</depends> | ||
<depends>com.intellij.modules.lang</depends> | ||
|
||
<!-- Text to display as description on Preferences/Settings | Plugin page --> | ||
<description> | ||
<![CDATA[ | ||
Track your working time from JetBrains on Clockify! | ||
<br /> | ||
<b> Features: </b> | ||
<ul> | ||
<li> Start & Stop your time directly on the IDE. </li> | ||
<li> Track your working time. </li> | ||
<li> Select and define session description. </li> | ||
</ul> | ||
<br /> | ||
<b> Getting Started: </b> | ||
<br /> | ||
Go into <i> Other Settings > Clockify </i>, then write your Clockify login details. | ||
<br /> | ||
Start tracking your time by clicking on the low-right corner (on the status bar) and click again to stop tracking. | ||
<br /> | ||
<img src="https://i.imgur.com/4cRCHEr.png" alt="Clockify at status bar" /><br /> | ||
<img src="https://i.imgur.com/tmq3GcF.png" alt="Tracking time" /><br /> | ||
<img src="https://i.imgur.com/JYdWs5R.png" alt="Stop tracking your time" /><br /> | ||
<br /> | ||
Assign session descriptions when starting to track your time. | ||
<br /> | ||
<img src="https://i.imgur.com/xKHH0c2.png" alt="Add your session description"> | ||
]]> | ||
</description> | ||
<change-notes> | ||
<![CDATA[ | ||
<ul> | ||
<li><b>1.0</b> Release 1.0.0</li> | ||
<li><b>1.0.1</b> It now loads any active entry on loading the IDE.</li> | ||
<li><b>1.0</b> Initial Release 1.0.0</li> | ||
</ul> | ||
]]> | ||
</change-notes> | ||
|
||
<!-- Text to display as company information on Preferences/Settings | Plugin page --> | ||
<vendor url="https://ricardormdev.github.io">Ricardo Rodriguez Medina</vendor> | ||
<vendor url="https://ricardormdev.github.io" email="[email protected]">Ricardo Rodriguez Medina</vendor> | ||
|
||
<idea-version since-build="201" /> | ||
<idea-version since-build="201.6668.113" /> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
|
||
<preloadingActivity implementation="io.github.ricardormdev.clockifyplugin.PluginLoader" /> | ||
<postStartupActivity implementation="io.github.ricardormdev.clockifyplugin.PluginFactory" /> | ||
<applicationService serviceImplementation="io.github.ricardormdev.clockifyplugin.settings.ApplicationSettingsState" /> | ||
<statusBarWidgetFactory implementation="io.github.ricardormdev.clockifyplugin.widget.WidgetFactory" /> | ||
<applicationConfigurable | ||
parentId="tools" | ||
groupId="other" | ||
groupWeight="200" | ||
instance="io.github.ricardormdev.clockifyplugin.settings.AppSettingsConfigurable" | ||
id="io.github.ricardormdev.clockifyplugin.settings.AppSettingsConfigurable" | ||
displayName="Clockify Plugin"> | ||
displayName="Clockify"> | ||
</applicationConfigurable> | ||
|
||
<applicationService serviceImplementation="io.github.ricardormdev.clockifyplugin.Plugin" /> | ||
|
||
</extensions> | ||
|
||
|
||
|
90 changes: 82 additions & 8 deletions
90
src/test/kotlin/io/github/ricardormdev/clockifyplugin/RepositoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,98 @@ | ||
package io.github.ricardormdev.clockifyplugin | ||
|
||
import io.github.ricardormdev.clockifyplugin.api.API | ||
import io.github.ricardormdev.clockifyplugin.api.models.Project | ||
import io.github.ricardormdev.clockifyplugin.api.models.Tag | ||
import io.github.ricardormdev.clockifyplugin.api.models.UserInterface | ||
import io.github.ricardormdev.clockifyplugin.api.models.Workspace | ||
import io.github.ricardormdev.clockifyplugin.api.websocket.authentication.AuthenticateTokens | ||
import io.github.ricardormdev.clockifyplugin.api.websocket.authentication.UserLogin | ||
import io.github.ricardormdev.clockifyplugin.settings.ApplicationSettingsState | ||
import io.github.ricardormdev.clockifyplugin.settings.settingsState | ||
import io.mockk.* | ||
import org.junit.Before | ||
import org.junit.Test | ||
import kotlin.test.assertTrue | ||
|
||
class RepositoryTest { | ||
|
||
@Test | ||
fun testLogin() { | ||
fun testWorking() { | ||
val plugin = buildPlugin() | ||
|
||
assertTrue(plugin.getStatusMessage().contains("You are not working."), "The message should mention is not working") | ||
plugin.startWorking("workspaceA", "a", true, "Random Description") | ||
assertTrue(plugin.logged, "The user should be logged.") | ||
assertTrue(plugin.working, "The status should be working.") | ||
val timer : PluginTimer = getField("timer", plugin) | ||
assertTrue(plugin.getStatusMessage().contains("You've worked for:"), "The message should mention is working") | ||
Thread.sleep(1000) | ||
assertTrue(timer.getTiming() > 0, "The timer should be started.") | ||
} | ||
|
||
fun buildPlugin() : Plugin { | ||
val plugin = Plugin() | ||
val auther = mockAuthenticator() | ||
val controller = mockController() | ||
val api = mockAPI() | ||
|
||
assignVarToObj("user", controller, api.getUser("user")) | ||
assignVarToObj("dataController", plugin, controller) | ||
assignVarToObj("api", plugin, api) | ||
assignVarToObj("timer", plugin, PluginTimer(plugin)) | ||
assignVarToObj("authenticator", plugin, auther) | ||
plugin.logged = true | ||
|
||
return plugin | ||
} | ||
|
||
@Test | ||
fun testWorking() { | ||
val plugin = Plugin() | ||
val timer = PluginTimer(plugin) | ||
fun assignVarToObj(name: String, target: Any, value: Any) { | ||
val field = target::class.java.getDeclaredField(name) | ||
field.isAccessible = true | ||
field.set(target, value) | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T> getField(fieldName: String, target: Any) : T { | ||
val field = target::class.java.getDeclaredField(fieldName) | ||
field.isAccessible = true | ||
return field.get(target) as T | ||
} | ||
|
||
fun mockController() : PluginDataController { | ||
return PluginDataController(mockAPI()) | ||
} | ||
|
||
fun mockAuthenticator(): AuthenticateTokens { | ||
return mockkClass(AuthenticateTokens::class) { | ||
every { retrieveFullUser() } returns UserLogin("user", "[email protected]", "UserName", "token", "refreshToken", arrayOf()) | ||
} | ||
} | ||
|
||
fun mockAPI(): API { | ||
return mockkClass(API::class) { | ||
every { getWorkspaces() } returns arrayOf( | ||
Workspace("workspaceA", "workspaceA"), | ||
Workspace("workspaceB", "workspaceB") | ||
) | ||
|
||
every { getProjects("workspaceA") } returns | ||
arrayOf(Project("a", "Project A"), Project("b", "Project B"), Project("b", "Project B")) | ||
|
||
every { getProjects("workspaceB") } returns arrayOf( | ||
Project("a", "Project A"), | ||
Project("b", "Project B"), | ||
Project("b", "Project B")) | ||
|
||
every { getUser("user") } returns | ||
UserInterface("user", "UserName", "workspaceA") | ||
|
||
every { getTags(any()) } returns | ||
arrayOf(Tag("TagA", "TagNameA"), Tag("TagB", "TagNameB")) | ||
|
||
|
||
timer.startTimer() | ||
println(timer.getTiming()) | ||
assert(timer.getTiming() > 0) | ||
every { startWorking(any(), any(), any(), any()) } returns Unit | ||
} | ||
} | ||
|
||
} |