2019-06-29 12:26:37 +05:30
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-10-06 05:49:18 +09:00
|
|
|
|
using System.Linq;
|
2019-06-29 12:26:37 +05:30
|
|
|
|
using NUnit.Framework;
|
2019-06-29 10:55:30 +05:30
|
|
|
|
using osu.Framework.Graphics;
|
2019-06-29 12:26:37 +05:30
|
|
|
|
using osu.Game.Online;
|
2019-12-03 15:28:10 +09:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-10-06 05:27:36 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2022-01-03 17:31:12 +09:00
|
|
|
|
using osu.Framework.Extensions;
|
2021-10-06 05:49:18 +09:00
|
|
|
|
using osu.Framework.Testing;
|
2022-01-17 14:40:06 +09:00
|
|
|
|
using osu.Game.Beatmaps;
|
2021-11-06 16:45:27 +09:00
|
|
|
|
using osu.Game.Database;
|
2021-10-06 05:49:18 +09:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-11-01 09:14:02 +01:00
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2022-01-17 14:40:06 +09:00
|
|
|
|
using osu.Game.Scoring;
|
2020-03-17 17:43:16 +09:00
|
|
|
|
using osu.Game.Screens.Ranking;
|
2022-01-17 14:40:06 +09:00
|
|
|
|
using osu.Game.Tests.Resources;
|
2021-10-06 05:27:36 +09:00
|
|
|
|
using osuTK.Input;
|
2021-11-04 18:02:44 +09:00
|
|
|
|
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
|
2019-06-29 10:55:30 +05:30
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2022-11-24 14:32:20 +09:00
|
|
|
|
public partial class TestSceneReplayDownloadButton : OsuManualInputManagerTestScene
|
2019-06-29 10:55:30 +05:30
|
|
|
|
{
|
2022-04-12 18:01:29 +09:00
|
|
|
|
private const long online_score_id = 2553163309;
|
|
|
|
|
|
2019-06-29 12:26:37 +05:30
|
|
|
|
private TestReplayDownloadButton downloadButton;
|
2019-06-29 10:55:30 +05:30
|
|
|
|
|
2022-01-17 14:40:06 +09:00
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private ScoreManager scoreManager { get; set; }
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 18:01:29 +09:00
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public void SetUpSteps()
|
|
|
|
|
{
|
|
|
|
|
AddStep("delete previous imports", () =>
|
|
|
|
|
{
|
|
|
|
|
scoreManager.Delete(s => s.OnlineID == online_score_id);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 05:27:36 +09:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestDisplayStates()
|
2019-06-29 10:55:30 +05:30
|
|
|
|
{
|
2021-10-06 05:27:36 +09:00
|
|
|
|
AddStep(@"create button with replay", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(true))
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
|
|
|
|
|
2019-06-29 12:26:37 +05:30
|
|
|
|
AddStep(@"downloading state", () => downloadButton.SetDownloadState(DownloadState.Downloading));
|
|
|
|
|
AddStep(@"locally available state", () => downloadButton.SetDownloadState(DownloadState.LocallyAvailable));
|
|
|
|
|
AddStep(@"not downloaded state", () => downloadButton.SetDownloadState(DownloadState.NotDownloaded));
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 05:27:36 +09:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestButtonWithReplayStartsDownload()
|
|
|
|
|
{
|
|
|
|
|
bool downloadStarted = false;
|
|
|
|
|
bool downloadFinished = false;
|
|
|
|
|
|
|
|
|
|
AddStep(@"create button with replay", () =>
|
|
|
|
|
{
|
|
|
|
|
downloadStarted = false;
|
|
|
|
|
downloadFinished = false;
|
|
|
|
|
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(true))
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
downloadButton.State.BindValueChanged(state =>
|
|
|
|
|
{
|
|
|
|
|
switch (state.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
downloadStarted = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (state.OldValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
downloadFinished = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
|
|
|
|
|
2022-11-30 17:07:57 +09:00
|
|
|
|
checkState(DownloadState.NotDownloaded);
|
2021-10-06 05:27:36 +09:00
|
|
|
|
|
|
|
|
|
AddStep("click button", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.MoveMouseTo(downloadButton);
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddAssert("state entered downloading", () => downloadStarted);
|
|
|
|
|
AddUntilStep("state left downloading", () => downloadFinished);
|
2024-07-26 05:08:13 +03:00
|
|
|
|
|
|
|
|
|
AddStep("change score to null", () => downloadButton.Score.Value = null);
|
|
|
|
|
AddUntilStep("state changed to unknown", () => downloadButton.State.Value, () => Is.EqualTo(DownloadState.Unknown));
|
2021-10-06 05:27:36 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestButtonWithoutReplay()
|
2019-06-29 12:26:37 +05:30
|
|
|
|
{
|
2021-10-06 05:27:36 +09:00
|
|
|
|
AddStep("create button without replay", () =>
|
2019-06-29 10:55:30 +05:30
|
|
|
|
{
|
2021-10-06 05:27:36 +09:00
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(false))
|
2019-06-29 12:49:03 +05:30
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
2019-06-29 10:55:30 +05:30
|
|
|
|
});
|
2020-05-28 21:46:02 +09:00
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
2021-10-06 05:49:18 +09:00
|
|
|
|
|
2022-11-30 17:07:57 +09:00
|
|
|
|
checkState(DownloadState.NotDownloaded);
|
2021-10-06 05:49:18 +09:00
|
|
|
|
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
2020-05-28 21:46:02 +09:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 16:12:06 +09:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestLocallyAvailableWithoutReplay()
|
|
|
|
|
{
|
|
|
|
|
Live<ScoreInfo> imported = null;
|
|
|
|
|
|
|
|
|
|
AddStep("import score", () => imported = scoreManager.Import(getScoreInfo(false, false)));
|
|
|
|
|
|
|
|
|
|
AddStep("create button without replay", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(imported.Value)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
|
|
|
|
|
2022-11-30 17:07:57 +09:00
|
|
|
|
checkState(DownloadState.NotDownloaded);
|
2022-04-12 16:12:06 +09:00
|
|
|
|
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-06 16:45:27 +09:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestScoreImportThenDelete()
|
|
|
|
|
{
|
2022-01-26 13:37:33 +09:00
|
|
|
|
Live<ScoreInfo> imported = null;
|
2021-11-06 16:45:27 +09:00
|
|
|
|
|
|
|
|
|
AddStep("create button without replay", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(false))
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
2022-11-30 17:07:57 +09:00
|
|
|
|
checkState(DownloadState.NotDownloaded);
|
2021-11-06 16:45:27 +09:00
|
|
|
|
|
2022-01-25 15:23:51 +09:00
|
|
|
|
AddStep("import score", () => imported = scoreManager.Import(getScoreInfo(true)));
|
2021-11-06 16:45:27 +09:00
|
|
|
|
|
2022-11-30 17:07:57 +09:00
|
|
|
|
checkState(DownloadState.LocallyAvailable);
|
2022-04-05 01:00:33 -07:00
|
|
|
|
AddAssert("button is enabled", () => downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
2021-11-06 16:45:27 +09:00
|
|
|
|
|
|
|
|
|
AddStep("delete score", () => scoreManager.Delete(imported.Value));
|
|
|
|
|
|
2022-11-30 17:07:57 +09:00
|
|
|
|
checkState(DownloadState.NotDownloaded);
|
2022-04-05 01:00:33 -07:00
|
|
|
|
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
2021-11-06 16:45:27 +09:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 05:27:36 +09:00
|
|
|
|
[Test]
|
|
|
|
|
public void CreateButtonWithNoScore()
|
2020-05-28 21:46:02 +09:00
|
|
|
|
{
|
|
|
|
|
AddStep("create button with null score", () =>
|
|
|
|
|
{
|
|
|
|
|
Child = downloadButton = new TestReplayDownloadButton(null)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => downloadButton.IsLoaded);
|
2021-10-06 05:49:18 +09:00
|
|
|
|
|
2022-11-30 17:07:57 +09:00
|
|
|
|
checkState(DownloadState.Unknown);
|
2021-10-06 05:49:18 +09:00
|
|
|
|
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
|
2019-06-29 10:55:30 +05:30
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 17:07:57 +09:00
|
|
|
|
private void checkState(DownloadState expectedState) =>
|
|
|
|
|
AddUntilStep($"state is {expectedState}", () => downloadButton.State.Value, () => Is.EqualTo(expectedState));
|
|
|
|
|
|
2022-07-25 13:03:06 +03:00
|
|
|
|
private ScoreInfo getScoreInfo(bool replayAvailable, bool hasOnlineId = true) => new ScoreInfo
|
2019-06-29 10:55:30 +05:30
|
|
|
|
{
|
2022-07-25 13:03:06 +03:00
|
|
|
|
OnlineID = hasOnlineId ? online_score_id : 0,
|
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo,
|
|
|
|
|
BeatmapInfo = beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First(),
|
2023-10-27 12:39:54 +02:00
|
|
|
|
HasOnlineReplay = replayAvailable,
|
2022-07-25 13:03:06 +03:00
|
|
|
|
User = new APIUser
|
2019-06-29 10:55:30 +05:30
|
|
|
|
{
|
2022-07-25 13:03:06 +03:00
|
|
|
|
Id = 39828,
|
|
|
|
|
Username = @"WubWoofWolf",
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-06-29 12:26:37 +05:30
|
|
|
|
|
2022-11-24 14:32:20 +09:00
|
|
|
|
private partial class TestReplayDownloadButton : ReplayDownloadButton
|
2019-06-29 12:26:37 +05:30
|
|
|
|
{
|
|
|
|
|
public void SetDownloadState(DownloadState state) => State.Value = state;
|
|
|
|
|
|
2021-10-06 05:27:36 +09:00
|
|
|
|
public new Bindable<DownloadState> State => base.State;
|
|
|
|
|
|
2019-06-29 12:29:12 +05:30
|
|
|
|
public TestReplayDownloadButton(ScoreInfo score)
|
|
|
|
|
: base(score)
|
2019-06-29 12:26:37 +05:30
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-29 10:55:30 +05:30
|
|
|
|
}
|
|
|
|
|
}
|