Converting Tests back to C# but still with Playwright
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
@layout PageLayout
|
||||
|
||||
@inherits BasePage
|
||||
|
||||
@page "/memory-tester"
|
||||
|
||||
<LayoutMediumContentComponent>
|
||||
<WebsiteTitleComponent>Memory Tester</WebsiteTitleComponent>
|
||||
|
||||
<PaperComponent>
|
||||
<UnitMemoryManager></UnitMemoryManager>
|
||||
</PaperComponent>
|
||||
|
||||
<ContentDividerComponent></ContentDividerComponent>
|
||||
|
||||
<PaperComponent>
|
||||
<InfoBodyComponent>
|
||||
<InfoQuestionComponent>
|
||||
What is this tool?
|
||||
</InfoQuestionComponent>
|
||||
<InfoAnswerComponent>
|
||||
A tool to test your memory of unit stats. Look at the first unit given, and fill in the remaining stats
|
||||
based on how they should compare.
|
||||
|
||||
<br/><br/>
|
||||
For example, if the first unit you see is the Masked Hunter of range 400, do you remember the range of
|
||||
the Scepter? Are they the same? Does the Scepter have double the range of the Masked Hunter? Less range
|
||||
than it? Well, enter your guess and submit!
|
||||
<SpoilerTextComponent>The range is 200 longer, so if you remember that, you know you are going to need
|
||||
more than Masked Hunters to deal with hard to reach enemy Scepters.
|
||||
</SpoilerTextComponent>
|
||||
</InfoAnswerComponent>
|
||||
</InfoBodyComponent>
|
||||
|
||||
<InfoBodyComponent>
|
||||
<InfoQuestionComponent>
|
||||
Why is this tool here?
|
||||
</InfoQuestionComponent>
|
||||
<InfoAnswerComponent>
|
||||
It was just a tool to quickly develop for fun when I didn't want to cover something larger on the
|
||||
02/27/2022 live coding stream.
|
||||
<br/><br/>
|
||||
It may get expanded upon later.
|
||||
</InfoAnswerComponent>
|
||||
</InfoBodyComponent>
|
||||
</PaperComponent>
|
||||
|
||||
</LayoutMediumContentComponent>
|
||||
@@ -0,0 +1,129 @@
|
||||
@implements IDisposable;
|
||||
@inject IMemoryTesterService MemoryTesterService;
|
||||
|
||||
<div class="unitMemoryContainer@(isCorrect ? " correct" : isWrong ? "wrong" : "")">
|
||||
<FormLayoutComponent>
|
||||
<FormDisplayComponent Label="Name">
|
||||
<Display>@EntityMemory.Name</Display>
|
||||
</FormDisplayComponent>
|
||||
|
||||
@foreach (var question in questions)
|
||||
{
|
||||
var questionWrong = hasBeenSubmitted && !question.IsRevealed && question.Guess != question.Answer;
|
||||
|
||||
<FormGuessComponent IsSubmitted="hasBeenSubmitted"
|
||||
OnChange="answerEventArgs => OnAnswerEntered(answerEventArgs, question)"
|
||||
MemoryQuestion="question"/>
|
||||
|
||||
@if (questionWrong)
|
||||
{
|
||||
<div class="wrongAnswer">The correct answer was @question.Answer</div>
|
||||
}
|
||||
}
|
||||
|
||||
</FormLayoutComponent>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.unitMemoryContainer {
|
||||
}
|
||||
|
||||
.unitMemoryContainer.correct {
|
||||
border-color: green;
|
||||
|
||||
}
|
||||
|
||||
.unitMemoryContainer.wrong {
|
||||
border-color: red;
|
||||
}
|
||||
|
||||
.wrongAnswer {
|
||||
padding: 12px;
|
||||
color: #ff2525;
|
||||
font-weight: 700;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
padding: 8px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter] public MemoryEntityModel EntityMemory { get; set; } = default!;
|
||||
|
||||
private List<MemoryQuestionModel> questions { get; set; } = default!;
|
||||
|
||||
private bool hasBeenSubmitted;
|
||||
private bool isCorrect;
|
||||
private bool isWrong;
|
||||
|
||||
public int Guess { get; set; }
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
MemoryTesterService.Subscribe(OnMemoryEvent);
|
||||
|
||||
OnRefresh();
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
MemoryTesterService.Unsubscribe(OnMemoryEvent);
|
||||
}
|
||||
|
||||
void OnMemoryEvent(MemoryTesterEvent memoryTesterEvent)
|
||||
{
|
||||
if (memoryTesterEvent == MemoryTesterEvent.OnVerify)
|
||||
{
|
||||
OnVerify();
|
||||
}
|
||||
|
||||
if (memoryTesterEvent == MemoryTesterEvent.OnRefresh)
|
||||
{
|
||||
OnRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnAnswerEntered(AnswerEventArgs answerEventArgs, MemoryQuestionModel question)
|
||||
{
|
||||
question.Guess = answerEventArgs.Guess;
|
||||
|
||||
MemoryTesterService.Update(question);
|
||||
}
|
||||
|
||||
void OnVerify()
|
||||
{
|
||||
hasBeenSubmitted = true;
|
||||
|
||||
isCorrect = true;
|
||||
|
||||
foreach (var question in questions)
|
||||
{
|
||||
if (question.Answer != question.Guess)
|
||||
{
|
||||
isCorrect = false;
|
||||
isWrong = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void OnRefresh()
|
||||
{
|
||||
hasBeenSubmitted = false;
|
||||
isCorrect = false;
|
||||
isWrong = false;
|
||||
|
||||
questions = (from question in MemoryTesterService.GetQuestions()
|
||||
where question.MemoryEntityModelId == EntityMemory.Id
|
||||
select question).ToList();
|
||||
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
@implements IDisposable;
|
||||
|
||||
@inject IMemoryTesterService MemoryTesterService;
|
||||
|
||||
<div class="quizContainer">
|
||||
<div class="quizListContainer">
|
||||
@if (entities != null && questions != null)
|
||||
{
|
||||
@foreach (var entityMemory in entities)
|
||||
{
|
||||
<UnitMemory EntityMemory="entityMemory"></UnitMemory>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="quizButtons">
|
||||
<ButtonComponent MyButtonType="MyButtonType.Secondary" OnClick="OnRefreshQuiz">Refresh</ButtonComponent>
|
||||
<ButtonComponent MyButtonType="MyButtonType.Primary" OnClick="OnSubmitQuiz">Submit</ButtonComponent>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.quizContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.quizListContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
@@media (min-width: @SupportedWebSizes.Tablet) {
|
||||
.quizContainer {
|
||||
}
|
||||
|
||||
.quizButtons {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 16px;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.quizListContainer {
|
||||
}
|
||||
}
|
||||
|
||||
@@media (min-width: @SupportedWebSizes.Desktop) {
|
||||
.quizListContainer {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@code {
|
||||
private List<MemoryEntityModel> entities = null!;
|
||||
private List<MemoryQuestionModel> questions = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
MemoryTesterService.Subscribe(OnMemoryEvent);
|
||||
|
||||
MemoryTesterService.GenerateQuiz();
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
MemoryTesterService.Unsubscribe(OnMemoryEvent);
|
||||
}
|
||||
|
||||
void OnMemoryEvent(MemoryTesterEvent memoryTesterEvent)
|
||||
{
|
||||
if (memoryTesterEvent == MemoryTesterEvent.OnVerify)
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
if (memoryTesterEvent == MemoryTesterEvent.OnRefresh)
|
||||
{
|
||||
entities = MemoryTesterService.GetEntities();
|
||||
questions = MemoryTesterService.GetQuestions();
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void OnSubmitQuiz(EventArgs eventArgs)
|
||||
{
|
||||
MemoryTesterService.Verify();
|
||||
}
|
||||
|
||||
void OnRefreshQuiz(EventArgs eventArgs)
|
||||
{
|
||||
MemoryTesterService.GenerateQuiz();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user