Merge remote-tracking branch 'upstream/master' into master
This commit is contained in:
@@ -145,4 +145,41 @@ public class ChatMessageManagerTest
|
||||
|
||||
verify(messageNode).setName("<col=b20000>" + friendName + "</col>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultFriendsChatInfoColors()
|
||||
{
|
||||
// no color is configured for opaqueFriendsChatInfo
|
||||
when(chatColorConfig.opaqueFriendsChatInfoHighlight()).thenReturn(Color.RED);
|
||||
|
||||
// rebuild color cache
|
||||
ConfigChanged configChanged = new ConfigChanged();
|
||||
configChanged.setGroup("textrecolor");
|
||||
chatMessageManager.onConfigChanged(configChanged);
|
||||
|
||||
String chatMessage = new ChatMessageBuilder()
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append("Total points: ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append("42")
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append(", Personal points: ")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append("43")
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append(" (")
|
||||
.append(ChatColorType.HIGHLIGHT)
|
||||
.append("44")
|
||||
.append(ChatColorType.NORMAL)
|
||||
.append("%)")
|
||||
.build();
|
||||
|
||||
MessageNode messageNode = mock(MessageNode.class);
|
||||
when(messageNode.getType()).thenReturn(ChatMessageType.FRIENDSCHATNOTIFICATION);
|
||||
when(messageNode.getRuneLiteFormatMessage()).thenReturn(chatMessage);
|
||||
|
||||
chatMessageManager.update(messageNode);
|
||||
|
||||
verify(messageNode).setValue("<col=000000>Total points: <col=ff0000>42<col=000000>, Personal points: <col=ff0000>43<col=000000> (<col=ff0000>44<col=000000>%)");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Jordan Atwood <nightfirecat@protonmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.menus;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
import static net.runelite.api.MenuAction.CC_OP;
|
||||
import static net.runelite.api.MenuAction.RUNELITE;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import static net.runelite.api.widgets.WidgetInfo.WORLD_MAP_OPTION;
|
||||
import net.runelite.client.util.Text;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MenuManagerTest
|
||||
{
|
||||
private static final MenuEntry CANCEL = new MenuEntry();
|
||||
|
||||
@Inject
|
||||
private MenuManager menuManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private Client client;
|
||||
|
||||
private MenuEntry[] clientMenuEntries = {CANCEL};
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass()
|
||||
{
|
||||
CANCEL.setOption("Cancel");
|
||||
CANCEL.setType(MenuAction.CANCEL.getId());
|
||||
CANCEL.setParam1(WORLD_MAP_OPTION.getPackedId());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
|
||||
|
||||
doAnswer((Answer<Void>) invocationOnMock ->
|
||||
{
|
||||
clientMenuEntries = invocationOnMock.getArgument(0, MenuEntry[].class);
|
||||
return null;
|
||||
}).when(client).setMenuEntries(ArgumentMatchers.any(MenuEntry[].class));
|
||||
when(client.getMenuEntries()).thenAnswer((Answer<MenuEntry[]>) invocationMock -> clientMenuEntries);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagedMenuOrder()
|
||||
{
|
||||
final MenuEntry first = new MenuEntry();
|
||||
final MenuEntry second = new MenuEntry();
|
||||
final MenuEntry third = new MenuEntry();
|
||||
first.setOption("Test");
|
||||
first.setTarget("First Entry");
|
||||
first.setParam1(WORLD_MAP_OPTION.getPackedId());
|
||||
first.setType(RUNELITE.getId());
|
||||
second.setOption("Test");
|
||||
second.setTarget("Second Entry");
|
||||
second.setParam1(WORLD_MAP_OPTION.getPackedId());
|
||||
second.setType(RUNELITE.getId());
|
||||
third.setOption("Test");
|
||||
third.setTarget("Third Entry");
|
||||
third.setParam1(WORLD_MAP_OPTION.getPackedId());
|
||||
third.setType(RUNELITE.getId());
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(first.getOption(), first.getTarget(), WORLD_MAP_OPTION));
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(second.getOption(), second.getTarget(), WORLD_MAP_OPTION));
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(third.getOption(), third.getTarget(), WORLD_MAP_OPTION));
|
||||
|
||||
menuManager.onMenuEntryAdded(new MenuEntryAdded(
|
||||
CANCEL.getOption(),
|
||||
CANCEL.getTarget(),
|
||||
CC_OP.getId(),
|
||||
CANCEL.getIdentifier(),
|
||||
CANCEL.getParam0(),
|
||||
CANCEL.getParam1()));
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> captor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client, atLeastOnce()).setMenuEntries(captor.capture());
|
||||
|
||||
final MenuEntry[] resultMenuEntries = captor.getValue();
|
||||
// Strip color tags from menu options before array comparison
|
||||
for (MenuEntry resultEntry : resultMenuEntries)
|
||||
{
|
||||
final String resultTarget = resultEntry.getTarget();
|
||||
if (resultTarget != null)
|
||||
{
|
||||
resultEntry.setTarget(Text.removeTags(resultEntry.getTarget()));
|
||||
}
|
||||
}
|
||||
|
||||
assertArrayEquals(new MenuEntry[]{CANCEL, third, second, first}, resultMenuEntries);
|
||||
}
|
||||
}
|
||||
@@ -906,6 +906,50 @@ public class ChatCommandsPluginTest
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 59.2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemporossNewPb()
|
||||
{
|
||||
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in <col=ef1020>6:35</col> (new personal best).", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: <col=ff0000>60</col>.", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("killcount", "tempoross", 60);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 6 * 60 + 35.0);
|
||||
|
||||
// Precise times
|
||||
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in <col=ef1020>5:20.60</col> (new personal best).", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: <col=ff0000>60</col>.", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 20.6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemporossNoPb()
|
||||
{
|
||||
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in <col=ef1020>7:40</col>. Personal best: 5:38.", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: <col=ff0000>55</col>.", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("killcount", "tempoross", 55);
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 38.0);
|
||||
|
||||
// Precise times
|
||||
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in <col=ef1020>6:19.80</col>. Personal best: 5:42.60.", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: <col=ff0000>55</col>.", null, 0);
|
||||
chatCommandsPlugin.onChatMessage(chatMessage);
|
||||
|
||||
verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 42.6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeStringToSeconds()
|
||||
{
|
||||
|
||||
@@ -33,10 +33,12 @@ import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NullObjectID;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
@@ -45,6 +47,8 @@ import net.runelite.client.plugins.cluescrolls.clues.hotcold.HotColdLocation;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -168,4 +172,47 @@ public class ClueScrollPluginTest
|
||||
verify(client, times(++clueSetupHintArrowClears)).clearHintArrow();
|
||||
verify(client, times(1)).setHintArrow(any(WorldPoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSTASHMarkerPersistence()
|
||||
{
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[] {});
|
||||
|
||||
// Set up emote clue
|
||||
final Widget clueWidget = mock(Widget.class);
|
||||
when(clueWidget.getText()).thenReturn("Spin in the Varrock Castle courtyard. Equip a black axe, a coif and a ruby ring.");
|
||||
when(client.getWidget(WidgetInfo.CLUE_SCROLL_TEXT)).thenReturn(clueWidget);
|
||||
plugin.onGameTick(new GameTick());
|
||||
|
||||
// Simulate clicking on the STASH
|
||||
MenuOptionClicked menuOptionClicked = new MenuOptionClicked();
|
||||
menuOptionClicked.setMenuOption("Search");
|
||||
menuOptionClicked.setMenuTarget("<col=ffff>STASH unit (easy)");
|
||||
menuOptionClicked.setId(NullObjectID.NULL_28983);
|
||||
plugin.onMenuOptionClicked(menuOptionClicked);
|
||||
|
||||
// Check that the STASH is stored after withdrawing
|
||||
ChatMessage withdrawMessage = new ChatMessage();
|
||||
withdrawMessage.setType(ChatMessageType.GAMEMESSAGE);
|
||||
withdrawMessage.setMessage("You withdraw your items from the STASH unit.");
|
||||
plugin.onChatMessage(withdrawMessage);
|
||||
assertNotNull(plugin.getActiveSTASHClue());
|
||||
|
||||
// Complete the step and get a new step, check that the clue is stored for rendering
|
||||
when(clueWidget.getText()).thenReturn("Talk to the bartender of the Rusty Anchor in Port Sarim.");
|
||||
plugin.onGameTick(new GameTick());
|
||||
assertNotNull(plugin.getActiveSTASHClue());
|
||||
|
||||
// Simulate depositing the emote items, make sure it's cleared the stored clue
|
||||
ChatMessage depositMessage = new ChatMessage();
|
||||
depositMessage.setType(ChatMessageType.GAMEMESSAGE);
|
||||
depositMessage.setMessage("You deposit your items into the STASH unit.");
|
||||
plugin.onChatMessage(depositMessage);
|
||||
assertNull(plugin.getActiveSTASHClue());
|
||||
|
||||
// Make sure that the STASH won't get re-marked if it's not part of the active clue.
|
||||
plugin.onMenuOptionClicked(menuOptionClicked);
|
||||
plugin.onChatMessage(withdrawMessage);
|
||||
assertNull(plugin.getActiveSTASHClue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user