chat commands: add pets command
Co-authored-by: Illya Myshakov <imyshako@uwaterloo.ca>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
package net.runelite.client.plugins.chatcommands;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
@@ -43,6 +44,7 @@ import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID;
|
||||
import static net.runelite.api.widgets.WidgetID.COLLECTION_LOG_ID;
|
||||
import static net.runelite.api.widgets.WidgetID.GENERIC_SCROLL_GROUP_ID;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.chat.ChatCommandManager;
|
||||
@@ -50,6 +52,7 @@ import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ChatColorConfig;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.config.RuneLiteConfig;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.http.api.chat.ChatClient;
|
||||
import net.runelite.http.api.hiscore.HiscoreClient;
|
||||
import net.runelite.http.api.hiscore.HiscoreSkill;
|
||||
@@ -118,6 +121,8 @@ public class ChatCommandsPluginTest
|
||||
@Inject
|
||||
ChatCommandsPlugin chatCommandsPlugin;
|
||||
|
||||
final Gson gson = RuneLiteAPI.GSON;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
@@ -952,6 +957,135 @@ public class ChatCommandsPluginTest
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 42.6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerPetList()
|
||||
{
|
||||
Widget logEntryHeaderWidget = mock(Widget.class);
|
||||
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget);
|
||||
|
||||
Widget[] logEntryHeaderItemsWidget = new Widget[1];
|
||||
when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget);
|
||||
|
||||
Widget logEntryHeaderTitleWidget = mock(Widget.class);
|
||||
when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX))
|
||||
.thenReturn(logEntryHeaderTitleWidget);
|
||||
when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets");
|
||||
|
||||
Widget logEntryItemsWidget = mock(Widget.class);
|
||||
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget);
|
||||
|
||||
Widget[] logPetEntriesWidget = new Widget[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
logPetEntriesWidget[i] = mock(Widget.class);
|
||||
when(logPetEntriesWidget[i].getOpacity()).thenReturn(175);
|
||||
}
|
||||
|
||||
when(logPetEntriesWidget[1].getName()).thenReturn("<col=ff9040>Ikkle hydra</col>");
|
||||
when(logPetEntriesWidget[1].getOpacity()).thenReturn(0);
|
||||
|
||||
when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget);
|
||||
|
||||
WidgetLoaded logEvent = new WidgetLoaded();
|
||||
logEvent.setGroupId(COLLECTION_LOG_ID);
|
||||
chatCommandsPlugin.onWidgetLoaded(logEvent);
|
||||
|
||||
chatCommandsPlugin.onGameTick(new GameTick());
|
||||
|
||||
Pet[] playerPetList = new Pet[1];
|
||||
playerPetList[0] = Pet.IKKLE_HYDRA;
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyPlayerPetList()
|
||||
{
|
||||
Widget logEntryHeaderWidget = mock(Widget.class);
|
||||
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget);
|
||||
|
||||
Widget[] logEntryHeaderItemsWidget = new Widget[1];
|
||||
when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget);
|
||||
|
||||
Widget logEntryHeaderTitleWidget = mock(Widget.class);
|
||||
when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX))
|
||||
.thenReturn(logEntryHeaderTitleWidget);
|
||||
when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets");
|
||||
|
||||
Widget logEntryItemsWidget = mock(Widget.class);
|
||||
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget);
|
||||
|
||||
Widget[] logPetEntriesWidget = new Widget[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
logPetEntriesWidget[i] = mock(Widget.class);
|
||||
when(logPetEntriesWidget[i].getOpacity()).thenReturn(175);
|
||||
}
|
||||
|
||||
when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget);
|
||||
|
||||
WidgetLoaded logEvent = new WidgetLoaded();
|
||||
logEvent.setGroupId(COLLECTION_LOG_ID);
|
||||
chatCommandsPlugin.onWidgetLoaded(logEvent);
|
||||
|
||||
chatCommandsPlugin.onGameTick(new GameTick());
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(new Pet[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePlayerPetList()
|
||||
{
|
||||
Widget logEntryHeaderWidget = mock(Widget.class);
|
||||
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget);
|
||||
|
||||
Widget[] logEntryHeaderItemsWidget = new Widget[1];
|
||||
when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget);
|
||||
|
||||
Widget logEntryHeaderTitleWidget = mock(Widget.class);
|
||||
when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX))
|
||||
.thenReturn(logEntryHeaderTitleWidget);
|
||||
when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets");
|
||||
|
||||
Widget logEntryItemsWidget = mock(Widget.class);
|
||||
when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget);
|
||||
|
||||
Widget[] logPetEntriesWidget = new Widget[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
logPetEntriesWidget[i] = mock(Widget.class);
|
||||
when(logPetEntriesWidget[i].getOpacity()).thenReturn(175);
|
||||
}
|
||||
|
||||
when(logPetEntriesWidget[1].getName()).thenReturn("<col=ff9040>Ikkle hydra</col>");
|
||||
when(logPetEntriesWidget[1].getOpacity()).thenReturn(0);
|
||||
|
||||
when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget);
|
||||
|
||||
WidgetLoaded logEvent = new WidgetLoaded();
|
||||
logEvent.setGroupId(COLLECTION_LOG_ID);
|
||||
chatCommandsPlugin.onWidgetLoaded(logEvent);
|
||||
|
||||
chatCommandsPlugin.onGameTick(new GameTick());
|
||||
|
||||
Pet[] playerPetList = new Pet[1];
|
||||
playerPetList[0] = Pet.IKKLE_HYDRA;
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList));
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage();
|
||||
chatMessage.setMessage("New item added to your collection log: Chompy chick");
|
||||
chatMessage.setType(GAMEMESSAGE);
|
||||
when(configManager.getRSProfileConfiguration("chatcommands", "pets",
|
||||
String.class)).thenReturn(gson.toJson(playerPetList));
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
playerPetList = new Pet[2];
|
||||
playerPetList[0] = Pet.IKKLE_HYDRA;
|
||||
playerPetList[1] = Pet.CHOMPY_CHICK;
|
||||
verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeStringToSeconds()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user