2020-11-23 14:51:50 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
using osu.Game.Overlays.Profile.Sections.Historical;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-11-04 17:02:44 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-11-23 14:51:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
|
{
|
2020-11-24 03:59:04 +08:00
|
|
|
|
public class TestScenePlayHistorySubsection : OsuTestScene
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
|
|
|
|
[Cached]
|
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Red);
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private readonly Bindable<APIUser> user = new Bindable<APIUser>();
|
2020-11-23 14:51:50 +08:00
|
|
|
|
private readonly PlayHistorySubsection section;
|
|
|
|
|
|
2020-11-24 03:59:04 +08:00
|
|
|
|
public TestScenePlayHistorySubsection()
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
|
|
|
|
AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colourProvider.Background4
|
|
|
|
|
},
|
|
|
|
|
section = new PlayHistorySubsection(user)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestNullValues()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Load user", () => user.Value = user_with_null_values);
|
|
|
|
|
AddAssert("Section is hidden", () => section.Alpha == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestEmptyValues()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Load user", () => user.Value = user_with_empty_values);
|
|
|
|
|
AddAssert("Section is hidden", () => section.Alpha == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-11-24 03:51:38 +08:00
|
|
|
|
public void TestOneValue()
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
|
|
|
|
AddStep("Load user", () => user.Value = user_with_one_value);
|
|
|
|
|
AddAssert("Section is hidden", () => section.Alpha == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestTwoValues()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Load user", () => user.Value = user_with_two_values);
|
|
|
|
|
AddAssert("Section is visible", () => section.Alpha == 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 05:12:32 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestConstantValues()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Load user", () => user.Value = user_with_constant_values);
|
|
|
|
|
AddAssert("Section is visible", () => section.Alpha == 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestConstantZeroValues()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Load user", () => user.Value = user_with_zero_values);
|
|
|
|
|
AddAssert("Section is visible", () => section.Alpha == 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 14:51:50 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestFilledValues()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Load user", () => user.Value = user_with_filled_values);
|
|
|
|
|
AddAssert("Section is visible", () => section.Alpha == 1);
|
2021-12-10 13:15:00 +08:00
|
|
|
|
AddAssert("Array length is the same", () => user_with_filled_values.MonthlyPlayCounts.Length == getChartValuesLength());
|
2020-11-23 14:51:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestMissingValues()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Load user", () => user.Value = user_with_missing_values);
|
|
|
|
|
AddAssert("Section is visible", () => section.Alpha == 1);
|
|
|
|
|
AddAssert("Array length is 7", () => getChartValuesLength() == 7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getChartValuesLength() => this.ChildrenOfType<ProfileLineChart>().Single().Values.Length;
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private static readonly APIUser user_with_null_values = new APIUser
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
|
|
|
|
Id = 1
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private static readonly APIUser user_with_empty_values = new APIUser
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
|
|
|
|
Id = 2,
|
2021-12-10 13:15:00 +08:00
|
|
|
|
MonthlyPlayCounts = Array.Empty<APIUserHistoryCount>()
|
2020-11-23 14:51:50 +08:00
|
|
|
|
};
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private static readonly APIUser user_with_one_value = new APIUser
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
|
|
|
|
Id = 3,
|
2021-12-10 13:15:00 +08:00
|
|
|
|
MonthlyPlayCounts = new[]
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 5, 1), Count = 100 }
|
2020-11-23 14:51:50 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private static readonly APIUser user_with_two_values = new APIUser
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
|
|
|
|
Id = 4,
|
2021-12-10 13:15:00 +08:00
|
|
|
|
MonthlyPlayCounts = new[]
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 5, 1), Count = 1 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 2 }
|
2020-11-23 14:51:50 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private static readonly APIUser user_with_constant_values = new APIUser
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
|
|
|
|
Id = 5,
|
2021-12-10 13:15:00 +08:00
|
|
|
|
MonthlyPlayCounts = new[]
|
2020-11-24 05:12:32 +08:00
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 5, 1), Count = 5 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 5 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 7, 1), Count = 5 }
|
2020-11-24 05:12:32 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private static readonly APIUser user_with_zero_values = new APIUser
|
2020-11-24 05:12:32 +08:00
|
|
|
|
{
|
|
|
|
|
Id = 6,
|
2021-12-10 13:15:00 +08:00
|
|
|
|
MonthlyPlayCounts = new[]
|
2020-11-24 05:12:32 +08:00
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 5, 1), Count = 0 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 0 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 7, 1), Count = 0 }
|
2020-11-24 05:12:32 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private static readonly APIUser user_with_filled_values = new APIUser
|
2020-11-24 05:12:32 +08:00
|
|
|
|
{
|
|
|
|
|
Id = 7,
|
2021-12-10 13:15:00 +08:00
|
|
|
|
MonthlyPlayCounts = new[]
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 5, 1), Count = 1000 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 6, 1), Count = 20 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 7, 1), Count = 20000 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 8, 1), Count = 30 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 9, 1), Count = 50 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 10, 1), Count = 2000 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2010, 11, 1), Count = 2100 }
|
2020-11-23 14:51:50 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-04 17:02:44 +08:00
|
|
|
|
private static readonly APIUser user_with_missing_values = new APIUser
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
2020-11-24 05:12:32 +08:00
|
|
|
|
Id = 8,
|
2021-12-10 13:15:00 +08:00
|
|
|
|
MonthlyPlayCounts = new[]
|
2020-11-23 14:51:50 +08:00
|
|
|
|
{
|
2021-11-04 17:02:44 +08:00
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2020, 1, 1), Count = 100 },
|
|
|
|
|
new APIUserHistoryCount { Date = new DateTime(2020, 7, 1), Count = 200 }
|
2020-11-23 14:51:50 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|