2023-04-19 12:14:14 +02:00
using System ;
2022-08-30 15:42:25 +02:00
using System.Collections.Generic ;
using System.Linq ;
using NUnit.Framework ;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model ;
using ShareeBike.ViewModel.WhatsNew ;
2022-08-30 15:42:25 +02:00
using Xamarin.Essentials ;
2024-04-09 12:53:23 +02:00
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests
2022-08-30 15:42:25 +02:00
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestWhatsNew
{
[Test]
public void TestIsMessagesConsistent ( )
{
foreach ( AppFlavor app in Enum . GetValues ( typeof ( AppFlavor ) ) )
{
foreach ( DevicePlatform platform in new List < DevicePlatform > { DevicePlatform . iOS , DevicePlatform . Android } )
Assert . That (
( ) = > new WhatsNew (
WhatsNew . AllFlavorsAndPlatformMessages [ WhatsNew . AllFlavorsAndPlatformMessages . Count - 1 ] . Version ,
WhatsNew . AllFlavorsAndPlatformMessages [ 0 ] . Version ,
WhatsNew . AllFlavorsAndPlatformMessages [ 0 ] . Version ,
app ,
platform ) . WhatsNewText ,
Throws . Nothing ,
"Invalid entries detected." ) ;
}
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestIsShowRequired_CleanInstall ( )
{
2024-04-09 12:53:23 +02:00
Assert . That ( new WhatsNew (
2022-09-06 16:08:19 +02:00
new Version ( 2 , 4 ) , /* Current version */
null , // last version
null , /* Whats new was never shown */
AppFlavor . ShareeBike ,
2024-04-09 12:53:23 +02:00
DevicePlatform . Android ) . IsShowRequired , Is . False ) ;
2022-09-06 16:08:19 +02:00
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
2023-04-19 12:14:14 +02:00
/// This test verified old implementation which worked with the different versions to determine whenther whats new has to be shown or not.
/// Test updated to new implementation (based on filtering of AllFlavorsAndPlatformMessages)
2022-09-06 16:08:19 +02:00
/// </summary>
[Test]
public void TestIsShowRequired_Update_VersionWhichSupporsWhatsNew ( )
{
2024-04-09 12:53:23 +02:00
Assert . That (
2022-09-06 16:08:19 +02:00
new WhatsNew (
new Version ( 3 , 0 , 335 ) , /* Current version */
new Version ( 3 , 0 , 333 ) , /* last version */
new Version ( 3 , 0 , 111 ) , /* Version when whats new was shown */
AppFlavor . ShareeBike ,
2024-04-09 12:53:23 +02:00
DevicePlatform . Android ) . IsShowRequired , Is . True ,
2023-04-19 12:14:14 +02:00
"If whats new was last shown for version 3.0.111 and current version is 2.0.335 info must be shown" ) ;
2022-09-06 16:08:19 +02:00
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
2023-04-19 12:14:14 +02:00
/// This test verified old implementation which worked with the different versions to determine whenther whats new has to be shown or not.
/// Test updated to new implementation (based on filtering of AllFlavorsAndPlatformMessages)
2022-09-06 16:08:19 +02:00
/// </summary>
[Test]
public void TestIsShowRequired_Update_VersionWithoutWhatsNew ( )
{
2024-04-09 12:53:23 +02:00
Assert . That (
2022-09-06 16:08:19 +02:00
new WhatsNew (
new Version ( 3 , 0 , 335 ) , /* Current version */
new Version ( 3 , 0 , 333 ) , /* last version */
null , /* Whats new was never shown */
AppFlavor . ShareeBike ,
2024-04-09 12:53:23 +02:00
DevicePlatform . Android ) . IsShowRequired , Is . True ,
2022-09-06 16:08:19 +02:00
"If whats new was never shown but last version was 3.0.333 (not clean install) info must be shown" ) ;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestIsShowRequired_False ( )
{
2024-04-09 12:53:23 +02:00
Assert . That (
new WhatsNew ( new Version ( 2 , 5 ) , new Version ( 2 , 5 ) , new Version ( 2 , 5 ) , AppFlavor . ShareeBike , DevicePlatform . Android ) . IsShowRequired , Is . False ,
2022-09-06 16:08:19 +02:00
"Whats new must never be presented twice." ) ;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestIsShowRequired_False_Errors ( )
{
2024-04-09 12:53:23 +02:00
Assert . That ( new WhatsNew ( null , new Version ( 2 , 6 ) , new Version ( 2 , 5 ) , AppFlavor . ShareeBike , DevicePlatform . Android ) . IsShowRequired , Is . False ) ;
Assert . That ( new WhatsNew ( new Version ( 2 , 6 ) , null , new Version ( 2 , 5 ) , AppFlavor . ShareeBike , DevicePlatform . Android ) . IsShowRequired , Is . False ) ;
Assert . That ( new WhatsNew ( null , null , new Version ( 2 , 5 ) , AppFlavor . ShareeBike , DevicePlatform . Android ) . IsShowRequired , Is . False ) ;
2022-09-06 16:08:19 +02:00
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestWhatsNewText_MajorUpdate ( )
{
2024-04-09 12:53:23 +02:00
Assert . That (
WhatsNewViewModel . GetWhatNextHtmlText ( new WhatsNew ( new Version ( 3 , 0 , 120 ) , new Version ( 3 , 0 , 0 , 114 ) , new Version ( 3 , 0 , 0 , 114 ) , AppFlavor . ShareeBike , DevicePlatform . Android ) . WhatsNewText ) , Is . EqualTo ( "<p><b>3.0.0.115</b><br/>Benutzeroberfläche verbessert.\r\n\r\n" +
"</p><p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>" ) ,
2022-09-06 16:08:19 +02:00
"Current version is 30.0.120, last whats new was shown in version 3.0.0.114: Two changes to be notified about." ) ;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestWhatsNewText_MinorUpdate ( )
{
2024-04-09 12:53:23 +02:00
Assert . That (
WhatsNewViewModel . GetWhatNextHtmlText ( new WhatsNew ( new Version ( 3 , 0 , 120 ) , new Version ( 3 , 0 , 0 , 115 ) , new Version ( 3 , 0 , 0 , 115 ) , AppFlavor . ShareeBike , DevicePlatform . Android ) . WhatsNewText ) , Is . EqualTo ( "<p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>" ) ) ;
2022-09-06 16:08:19 +02:00
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestWhatsNewGetFileredMessages_GeneralMessage ( )
{
Assert . That (
new WhatsNew ( new Version ( 3 , 0 , 335 ) , new Version ( 3 , 0 ) , new Version ( 3 , 0 ) , AppFlavor . ShareeBike , DevicePlatform . iOS , new WhatsNewMessages
{
{
new Version ( 3 , 0 , 0 , 115 ) ,
"Benutzeroberfläche verbessert.\r\n\r\n"
}
} ) . WhatsNewText . Count ( ) ,
Is . EqualTo ( 1 ) ) ;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
2024-04-09 12:53:23 +02:00
public void TestWhatsNewGetFileredMessages_LastenradBayernOnly_Included ( )
2022-09-06 16:08:19 +02:00
{
Assert . That (
2024-04-09 12:53:23 +02:00
new WhatsNew ( new Version ( 3 , 0 , 335 ) , new Version ( 3 , 0 ) , new Version ( 3 , 0 ) , AppFlavor . LastenradBayern , DevicePlatform . iOS , new WhatsNewMessages
2022-09-06 16:08:19 +02:00
{
{
new Version ( 3 , 0 , 0 , 115 ) ,
"Benutzeroberfläche verbessert.\r\n\r\n" ,
2024-04-09 12:53:23 +02:00
new List < AppFlavor > { AppFlavor . LastenradBayern }
2022-09-06 16:08:19 +02:00
}
} ) . WhatsNewText . Count ( ) ,
Is . EqualTo ( 1 ) ) ;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
2024-04-09 12:53:23 +02:00
public void TestWhatsNewGetFileredMessages_LastenradBayernOnly_Excluded ( )
2022-09-06 16:08:19 +02:00
{
Assert . That (
new WhatsNew ( new Version ( 3 , 0 , 335 ) , new Version ( 3 , 0 ) , new Version ( 3 , 0 ) , AppFlavor . ShareeBike , DevicePlatform . iOS , new WhatsNewMessages
{
{
new Version ( 3 , 0 , 0 , 115 ) ,
"Benutzeroberfläche verbessert.\r\n\r\n" ,
2024-04-09 12:53:23 +02:00
new List < AppFlavor > { AppFlavor . LastenradBayern }
2022-09-06 16:08:19 +02:00
}
} ) . WhatsNewText . Count ( ) ,
Is . EqualTo ( 0 ) ) ;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestWhatsNewGetFileredMessages_iOSOnly_Included ( )
{
Assert . That (
new WhatsNew ( new Version ( 3 , 0 , 335 ) , new Version ( 3 , 0 ) , new Version ( 3 , 0 ) , AppFlavor . ShareeBike , DevicePlatform . iOS , new WhatsNewMessages
{
{
new Version ( 3 , 0 , 0 , 115 ) ,
"Benutzeroberfläche verbessert.\r\n\r\n" ,
null ,
new List < DevicePlatform > { DevicePlatform . iOS }
}
} ) . WhatsNewText . Count ( ) ,
Is . EqualTo ( 1 ) ) ;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestWhatsNewGetFileredMessages_iOSOnly_Exclued ( )
{
Assert . That (
new WhatsNew ( new Version ( 3 , 0 , 335 ) , new Version ( 3 , 0 ) , new Version ( 3 , 0 ) , AppFlavor . ShareeBike , DevicePlatform . Android , new WhatsNewMessages
{
{
new Version ( 3 , 0 , 0 , 115 ) ,
"Benutzeroberfläche verbessert.\r\n\r\n" ,
null ,
new List < DevicePlatform > { DevicePlatform . iOS }
}
} ) . WhatsNewText . Count ( ) ,
Is . EqualTo ( 0 ) ) ;
}
}
2022-08-30 15:42:25 +02:00
}