mirror of
https://github.com/ppy/osu.git
synced 2025-01-21 19:52:55 +08:00
Merge pull request #4511 from peppy/better-dummy-api
Fix AccountCreationOverlay tests and better complete dummy api's behaviour
This commit is contained in:
commit
9d32b97b81
@ -3,9 +3,13 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.AccountCreation;
|
using osu.Game.Overlays.AccountCreation;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual
|
namespace osu.Game.Tests.Visual
|
||||||
{
|
{
|
||||||
@ -21,12 +25,32 @@ namespace osu.Game.Tests.Visual
|
|||||||
typeof(AccountCreationScreen),
|
typeof(AccountCreationScreen),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[Cached(typeof(IAPIProvider))]
|
||||||
|
private DummyAPIAccess api = new DummyAPIAccess();
|
||||||
|
|
||||||
public TestCaseAccountCreationOverlay()
|
public TestCaseAccountCreationOverlay()
|
||||||
{
|
{
|
||||||
var accountCreation = new AccountCreationOverlay();
|
Container userPanelArea;
|
||||||
Child = accountCreation;
|
AccountCreationOverlay accountCreation;
|
||||||
|
|
||||||
accountCreation.State = Visibility.Visible;
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
api,
|
||||||
|
accountCreation = new AccountCreationOverlay(),
|
||||||
|
userPanelArea = new Container
|
||||||
|
{
|
||||||
|
Padding = new MarginPadding(10),
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
api.Logout();
|
||||||
|
api.LocalUser.BindValueChanged(user => { userPanelArea.Child = new UserPanel(user.NewValue) { Width = 200 }; }, true);
|
||||||
|
|
||||||
|
AddStep("show", () => accountCreation.State = Visibility.Visible);
|
||||||
|
AddStep("logout", () => api.Logout());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
|
Add(api);
|
||||||
|
|
||||||
AddStep("load disclaimer", () => LoadScreen(new Disclaimer()));
|
AddStep("load disclaimer", () => LoadScreen(new Disclaimer()));
|
||||||
|
|
||||||
AddStep("toggle support", () =>
|
AddStep("toggle support", () =>
|
||||||
|
@ -266,22 +266,20 @@ namespace osu.Game.Online.API
|
|||||||
get => state;
|
get => state;
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
APIState oldState = state;
|
if (state == value)
|
||||||
APIState newState = value;
|
return;
|
||||||
|
|
||||||
|
APIState oldState = state;
|
||||||
state = value;
|
state = value;
|
||||||
|
|
||||||
if (oldState != newState)
|
log.Add($@"We just went {state}!");
|
||||||
{
|
|
||||||
log.Add($@"We just went {newState}!");
|
|
||||||
Scheduler.Add(delegate
|
Scheduler.Add(delegate
|
||||||
{
|
{
|
||||||
components.ForEach(c => c.APIStateChanged(this, newState));
|
components.ForEach(c => c.APIStateChanged(this, state));
|
||||||
OnStateChange?.Invoke(oldState, newState);
|
OnStateChange?.Invoke(oldState, state);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private bool handleWebException(WebException we)
|
private bool handleWebException(WebException we)
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Online.API
|
namespace osu.Game.Online.API
|
||||||
{
|
{
|
||||||
public class DummyAPIAccess : IAPIProvider
|
public class DummyAPIAccess : Component, IAPIProvider
|
||||||
{
|
{
|
||||||
public Bindable<User> LocalUser { get; } = new Bindable<User>(new User
|
public Bindable<User> LocalUser { get; } = new Bindable<User>(new User
|
||||||
{
|
{
|
||||||
@ -20,7 +23,23 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
public string Endpoint => "http://localhost";
|
public string Endpoint => "http://localhost";
|
||||||
|
|
||||||
public APIState State => LocalUser.Value.Id == 1 ? APIState.Offline : APIState.Online;
|
private APIState state = APIState.Online;
|
||||||
|
|
||||||
|
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
|
||||||
|
|
||||||
|
public APIState State
|
||||||
|
{
|
||||||
|
get => state;
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
if (state == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
state = value;
|
||||||
|
|
||||||
|
Scheduler.Add(() => components.ForEach(c => c.APIStateChanged(this, value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Queue(APIRequest request)
|
public virtual void Queue(APIRequest request)
|
||||||
{
|
{
|
||||||
@ -28,28 +47,36 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
public void Register(IOnlineComponent component)
|
public void Register(IOnlineComponent component)
|
||||||
{
|
{
|
||||||
// todo: add support
|
Scheduler.Add(delegate { components.Add(component); });
|
||||||
|
component.APIStateChanged(this, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unregister(IOnlineComponent component)
|
public void Unregister(IOnlineComponent component)
|
||||||
{
|
{
|
||||||
// todo: add support
|
Scheduler.Add(delegate { components.Remove(component); });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Login(string username, string password)
|
public void Login(string username, string password)
|
||||||
{
|
{
|
||||||
LocalUser.Value = new User
|
LocalUser.Value = new User
|
||||||
{
|
{
|
||||||
Username = @"Dummy",
|
Username = username,
|
||||||
Id = 1001,
|
Id = 1001,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
State = APIState.Online;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Logout()
|
public void Logout()
|
||||||
{
|
{
|
||||||
LocalUser.Value = new GuestUser();
|
LocalUser.Value = new GuestUser();
|
||||||
|
State = APIState.Offline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) => null;
|
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
|
||||||
|
{
|
||||||
|
Thread.Sleep(200);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user