-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: warn players when XACT-errors are in their logs (#3290)
* feat: warn players when XACT-errors are in their logs * add unit tests * Fixed link to be clickable, added it as a button * UX flow reworked * Fixed comments * Rearrange buttons * Make info icon bigger * minor refactor * refactor: remove record class
- Loading branch information
1 parent
01f2f89
commit 74c9618
Showing
5 changed files
with
192 additions
and
13 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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/faforever/client/logging/analysis/LogAnalyzerService.java
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.faforever.client.logging.analysis; | ||
|
||
import com.faforever.client.config.ClientProperties; | ||
import com.faforever.client.fx.PlatformService; | ||
import com.faforever.client.i18n.I18n; | ||
import com.faforever.client.notification.Action; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LogAnalyzerService { | ||
private static final String GAME_MINIMIZED_TRACE = "info: Minimized true"; | ||
private static final String SND_WARNING_TRACE = "warning: SND"; | ||
private static final String SND_XACT_TRACE = "XACT"; | ||
|
||
private final I18n i18n; | ||
private final ClientProperties clientProperties; | ||
private final PlatformService platformService; | ||
|
||
@NotNull | ||
public Map<String, Action> analyzeLogContents(final String logContents) { | ||
final Map<String, Action> analysisResult = new HashMap<>(); | ||
|
||
if (StringUtils.contains(logContents, GAME_MINIMIZED_TRACE)) { | ||
analysisResult.put(i18n.get("game.log.analysis.minimized"), null); | ||
} | ||
|
||
if (StringUtils.contains(logContents, SND_WARNING_TRACE) && StringUtils.contains(logContents, SND_XACT_TRACE)) { | ||
final String moreInfoButtonCaption = i18n.get("game.log.analysis.moreInfoBtn"); | ||
final Action openSoundHelpAction = new Action(moreInfoButtonCaption, () -> platformService.showDocument( | ||
clientProperties.getLinks().get("linksSoundIssues"))); | ||
|
||
analysisResult.put(i18n.get("game.log.analysis.snd", moreInfoButtonCaption), openSoundHelpAction); | ||
} | ||
|
||
return Collections.unmodifiableMap(analysisResult); | ||
} | ||
} |
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
85 changes: 85 additions & 0 deletions
85
src/test/java/com/faforever/client/logging/analysis/LogAnalyzerServiceTest.java
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.faforever.client.logging.analysis; | ||
|
||
import com.faforever.client.config.ClientProperties; | ||
import com.faforever.client.fx.PlatformService; | ||
import com.faforever.client.i18n.I18n; | ||
import com.faforever.client.notification.Action; | ||
import com.faforever.client.test.ServiceTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class LogAnalyzerServiceTest extends ServiceTest { | ||
|
||
private static final String SOUND_EXPECTED_TEXT = "Sound issue detected"; | ||
private static final String MINIMIZED_EXPECTED_TEXT = "Game was minimized"; | ||
private static final String MORE_INFO_BUTTON = "More Info"; | ||
|
||
@Mock | ||
private I18n i18n; | ||
|
||
@Mock | ||
private ClientProperties clientProperties; | ||
|
||
@Mock | ||
private PlatformService platformService; | ||
|
||
@InjectMocks | ||
private LogAnalyzerService logAnalyzerService; | ||
|
||
@Test | ||
public void testAnalyzeLogContentsWhenGameMinimizedTrace() { | ||
final String logContents = "info: Minimized true"; | ||
|
||
when(i18n.get("game.log.analysis.minimized")).thenReturn(MINIMIZED_EXPECTED_TEXT); | ||
|
||
Map<String, Action> result = logAnalyzerService.analyzeLogContents(logContents); | ||
|
||
assertTrue(result.containsKey(MINIMIZED_EXPECTED_TEXT)); | ||
} | ||
|
||
@Test | ||
public void testAnalyzeLogContentsWhenXactTrace() { | ||
final String logContents = "warning: SND\nXACT"; | ||
|
||
when(i18n.get("game.log.analysis.moreInfoBtn")).thenReturn(MORE_INFO_BUTTON); | ||
when(i18n.get("game.log.analysis.snd", MORE_INFO_BUTTON)).thenReturn(SOUND_EXPECTED_TEXT); | ||
|
||
Map<String, Action> result = logAnalyzerService.analyzeLogContents(logContents); | ||
|
||
assertEquals(1, result.size()); | ||
assertNotNull(result.get(SOUND_EXPECTED_TEXT)); | ||
} | ||
|
||
@Test | ||
public void testAnalyzeLogContentsWhenGameMinimizedAndXactTrace() { | ||
final String logContents = "info: Minimized true\nwarning: SND\nXACT"; | ||
|
||
when(i18n.get("game.log.analysis.minimized")).thenReturn(MINIMIZED_EXPECTED_TEXT); | ||
when(i18n.get("game.log.analysis.moreInfoBtn")).thenReturn(MORE_INFO_BUTTON); | ||
when(i18n.get("game.log.analysis.snd", MORE_INFO_BUTTON)).thenReturn(SOUND_EXPECTED_TEXT); | ||
|
||
Map<String, Action> result = logAnalyzerService.analyzeLogContents(logContents); | ||
|
||
assertEquals(2, result.size()); | ||
assertNotNull(result.get(SOUND_EXPECTED_TEXT)); | ||
assertNull(result.get(MINIMIZED_EXPECTED_TEXT)); | ||
} | ||
|
||
@Test | ||
public void testAnalyzeLogContentsWhenNoRelevantTraces() { | ||
final String logContents = "Some other log content"; | ||
|
||
Map<String, Action> result = logAnalyzerService.analyzeLogContents(logContents); | ||
|
||
assertTrue(result.isEmpty()); | ||
} | ||
} |