| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using System.Linq;
- using DevilLink2.Gameplay;
- using DevilLink2.Persistence;
- using DevilLink2.UI;
- using NUnit.Framework;
- using UnityEngine;
- namespace DevilLink2.Tests
- {
- public sealed partial class UIScreenTests
- {
- private void OpenShop() { ui.ShowLobby(); ui.Lobby.ShopButton.onClick.Invoke(); }
- [Test] public void ShopOpenClosePreservesPageAndInstances()
- {
- OpenShop(); ui.OpenShop(); Assert.That(ui.Shop.IsVisible,Is.True); Assert.That(ui.CurrentPage,Is.EqualTo(UIPage.Lobby));
- Assert.That(ui.Lobby.GetComponent<CanvasGroup>().interactable,Is.False);
- Assert.That(frame.GetComponentsInChildren<ShopScreen>(true).Length,Is.EqualTo(1));
- Assert.That(root.GetComponentsInChildren<Canvas>(true).Length,Is.EqualTo(1));
- ui.Shop.CloseButton.onClick.Invoke(); Assert.That(ui.Shop.IsVisible,Is.False); Assert.That(ui.Lobby.GetComponent<CanvasGroup>().interactable,Is.True);
- }
- [Test] public void CoinsEntryOpensShop() { ui.ShowLobby(); ui.Lobby.CoinButton.onClick.Invoke(); Assert.That(ui.Shop.IsVisible,Is.True); }
- [Test] public void ShopTabsSwitchAndReopenStartsWithItems()
- {
- OpenShop(); ui.Shop.RecordsButton.onClick.Invoke(); Assert.That(ui.Shop.CurrentTab,Is.EqualTo(ShopTab.CoinRecords));
- ui.Shop.ItemsButton.onClick.Invoke(); Assert.That(ui.Shop.CurrentTab,Is.EqualTo(ShopTab.Items));
- ui.Shop.SelectTab(ShopTab.CoinRecords); ui.CloseShop(); ui.OpenShop(); Assert.That(ui.Shop.CurrentTab,Is.EqualTo(ShopTab.Items));
- }
- [TestCase(ItemType.Hint,2000)] [TestCase(ItemType.Shuffle,5000)] [TestCase(ItemType.Time,3000)]
- public void ShopShowsActualPricesAndInventory(ItemType type,int price)
- {
- OpenShop(); Assert.That(ui.Shop.PriceLabels[(int)type].text,Is.EqualTo(price.ToString("N0",System.Globalization.CultureInfo.InvariantCulture)+" COINS"));
- Assert.That(ui.Shop.StockLabels[(int)type].text,Is.EqualTo("OWNED "+player.Economy.Inventory.GetCount(type)));
- }
- [TestCase(ItemType.Hint)] [TestCase(ItemType.Shuffle)] [TestCase(ItemType.Time)]
- public void ShopPurchaseUpdatesEconomyInventoryLedgerAndDisk(ItemType type)
- {
- OpenShop(); int stock=player.Economy.Inventory.GetCount(type); ui.Shop.BuyButtons[(int)type].onClick.Invoke();
- Assert.That(player.Economy.Coins,Is.EqualTo(9876-ShopService.Price(type))); Assert.That(player.Economy.Inventory.GetCount(type),Is.EqualTo(stock+1));
- Assert.That(ui.Shop.StockLabels[(int)type].text,Is.EqualTo("OWNED "+(stock+1)));
- Assert.That(player.Economy.Ledger.Entries.Single().Delta,Is.EqualTo(-ShopService.Price(type)));
- using(var restored=new SavedPlayer(new LocalSaveService(new FileSaveStorage(directory))))
- { Assert.That(restored.Economy.Coins,Is.EqualTo(player.Economy.Coins)); Assert.That(restored.Economy.Inventory.GetCount(type),Is.EqualTo(stock+1)); }
- }
- [Test] public void ShopInsufficientCoinsDoesNotCharge()
- {
- OpenShop(); Assert.That(ui.Shop.TryPurchase(ItemType.Shuffle,Guid.NewGuid()),Is.EqualTo(PurchaseStatus.Success));
- long before=player.Economy.Coins; int stock=player.Economy.Inventory.GetCount(ItemType.Shuffle);
- Assert.That(ui.Shop.TryPurchase(ItemType.Shuffle,Guid.NewGuid()),Is.EqualTo(PurchaseStatus.InsufficientCoins));
- Assert.That(player.Economy.Coins,Is.EqualTo(before)); Assert.That(player.Economy.Inventory.GetCount(ItemType.Shuffle),Is.EqualTo(stock));
- Assert.That(player.Economy.Ledger.Entries.Count,Is.EqualTo(1)); Assert.That(ui.Shop.FeedbackLabel.text,Does.Contain("NOT ENOUGH"));
- }
- [Test] public void ShopDuplicateOperationChargesOnceEvenAfterReopen()
- {
- OpenShop(); var id=Guid.NewGuid(); ui.Shop.TryPurchase(ItemType.Hint,id); ui.CloseShop(); ui.OpenShop();
- Assert.That(ui.Shop.TryPurchase(ItemType.Hint,id),Is.EqualTo(PurchaseStatus.DuplicateTransaction));
- Assert.That(player.Economy.Coins,Is.EqualTo(7876)); Assert.That(player.Economy.Ledger.Entries.Count,Is.EqualTo(1));
- }
- [Test] public void ShopRecordsUseLedgerOrderAndRetainedSummaries()
- {
- OpenShop(); player.Economy.TryCredit(Guid.NewGuid(),100,"income first"); ui.Shop.TryPurchase(ItemType.Hint,Guid.NewGuid());
- player.Economy.TryCredit(Guid.NewGuid(),300,"income newest"); ui.Shop.SelectTab(ShopTab.CoinRecords);
- string text=ui.Shop.RecordsText; Assert.That(text.IndexOf("income newest"),Is.LessThan(text.IndexOf("Shop: Hint")));
- Assert.That(text.IndexOf("Shop: Hint"),Is.LessThan(text.IndexOf("income first")));
- Assert.That(text,Does.Contain("UTC")); Assert.That(text,Does.Contain("INCOME +300")); Assert.That(text,Does.Contain("EXPENSE -2,000"));
- Assert.That(ui.Shop.SummaryLabel.text,Does.Contain("INCOME +400")); Assert.That(ui.Shop.SummaryLabel.text,Does.Contain("SPENT -2,000"));
- }
- [Test] public void ShopRetainsAtMost200RecordsAndDoesNotInventStarterGrant()
- {
- OpenShop(); for(int i=0;i<201;i++)player.Economy.TryCredit(Guid.NewGuid(),1,"record-"+i);
- Assert.That(player.Economy.Ledger.Entries.Count,Is.EqualTo(200)); Assert.That(ui.Shop.SummaryLabel.text,Does.Contain("INCOME +200"));
- Assert.That(ui.Shop.RecordsText,Does.Not.Contain("record-0\n")); Assert.That(ui.Shop.RecordsText,Does.Contain("record-200"));
- }
- [Test] public void ShopEmptyRecordsShowEmptyState()
- { OpenShop(); ui.Shop.SelectTab(ShopTab.CoinRecords); Assert.That(ui.Shop.RecordsText,Is.EqualTo("NO COIN RECORDS YET")); Assert.That(ui.Shop.SummaryLabel.text,Does.Contain("INCOME +0")); }
- [Test] public void ShopEscapesRecordMarkup()
- { OpenShop(); player.Economy.TryCredit(Guid.NewGuid(),1,"<size=99>test</size>"); Assert.That(ui.Shop.RecordsText,Does.Contain("<size=99>")); }
- [Test] public void ShopHiddenPurchaseAndUnderlyingModeInputAreRejected()
- { Assert.That(ui.Shop.TryPurchase(ItemType.Hint,Guid.NewGuid()),Is.Not.EqualTo(PurchaseStatus.Success)); OpenShop(); Assert.That(ui.SelectMode(GameMode.Classic),Is.False); Assert.That(bootstrap.Session,Is.Null); }
- [Test] public void ShopInGameDoesNotPauseOrReplaceBoard()
- {
- ui.ShowLobby(); ui.SelectMode(GameMode.Classic); var session=bootstrap.Session; var flow=bootstrap.Flow;
- ui.GameShopButton.onClick.Invoke(); Assert.That(ui.Shop.IsVisible,Is.True); Assert.That(flow.State,Is.EqualTo(GameFlowState.Running));
- double before=flow.Runtime.Timer.RemainingTime; flow.Runtime.Timer.Advance(.5);
- Assert.That(flow.Runtime.Timer.RemainingTime,Is.EqualTo(before-.5)); ui.CloseShop();
- Assert.That(bootstrap.Session,Is.SameAs(session)); Assert.That(view.Data,Is.SameAs(session.Board)); Assert.That(ui.CurrentPage,Is.EqualTo(UIPage.Gameplay));
- }
- [Test] public void ShopClosesOnTimeoutAndCannotCoverResult()
- {
- ui.ShowLobby(); ui.SelectMode(GameMode.Classic); ui.OpenShop(); bootstrap.Flow.Runtime.Timer.Advance(1000);
- Assert.That(bootstrap.Flow.State,Is.EqualTo(GameFlowState.Defeat)); Assert.That(ui.Shop.IsVisible,Is.False); Assert.That(ui.Hud.Result.IsVisible,Is.True);
- }
- [Test] public void ShopRepeatedButtonDispatchInSameFrameDoesNotDoubleCharge()
- { OpenShop(); ui.Shop.BuyButtons[0].onClick.Invoke(); ui.Shop.BuyButtons[0].onClick.Invoke(); Assert.That(player.Economy.Coins,Is.EqualTo(7876)); }
- [Test] public void ShopRebuildDoesNotDuplicateGameplayEntry()
- {
- UnityEngine.Object.DestroyImmediate(ui.gameObject); ui=UIBuilder.Build(frame,bootstrap,view); ui.Initialize(player,bootstrap);
- Assert.That(ui.Gameplay.GetComponentsInChildren<UnityEngine.UI.Button>(true).Count(b=>b.name=="ShopEntry"),Is.EqualTo(1));
- }
- [Test] public void ShopRepeatedInitializationHasOnePurchaseListener()
- { OpenShop(); for(int i=0;i<5;i++)ui.Initialize(player,bootstrap); ui.Shop.BuyButtons[0].onClick.Invoke(); Assert.That(player.Economy.Coins,Is.EqualTo(7876)); }
- }
- }
|