Skip to content

Commit

Permalink
Fixed broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasstich committed Dec 13, 2023
1 parent a33e90c commit 42dee7d
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Render_Difficulty_RenderPreviewHeader([Values] QuestionDifficulty ex

var sut = GetRenderedComponent(adaptivityQuestion);

var header = sut.Find("h5");
var header = sut.Find("p");
Assert.That(header.InnerHtml, Is.EqualTo("AdaptivityQuestionPreview.Header.Question." + expectedDifficulty));
}

Expand All @@ -60,7 +60,7 @@ public void Render_MultipleChoiceQuestions_RenderQuestionText()

var sut = GetRenderedComponent(adaptivityQuestion);

var questionText = sut.Find("p.mud-typography-body1");
var questionText = sut.FindAll("p.mud-typography-body1")[1];
Assert.That(questionText.InnerHtml, Is.EqualTo(expectedQuestionText));
}

Expand All @@ -72,12 +72,12 @@ public void Render_Choices_RenderChoicesText([Values] bool hideChoices)
var expectedChoice2Text = "choice2";
var choice1 = ViewModelProvider.GetChoice(expectedChoice1Text);
var choice2 = ViewModelProvider.GetChoice(expectedChoice2Text);
adaptivityQuestion.Choices.Returns(new List<ChoiceViewModel> {choice1, choice2});
adaptivityQuestion.CorrectChoices.Returns(new List<ChoiceViewModel> {choice1});
adaptivityQuestion.Choices.Returns(new List<ChoiceViewModel> { choice1, choice2 });
adaptivityQuestion.CorrectChoices.Returns(new List<ChoiceViewModel> { choice1 });

var sut = GetRenderedComponent(adaptivityQuestion, hideChoices);

var choices = sut.FindAll("p.mud-typography-body2");
var choices = sut.FindAll("p.mud-typography-body1.choice");
if (hideChoices)
{
Assert.That(choices, Is.Empty);
Expand All @@ -100,12 +100,12 @@ public void Render_HasCommentAction_RenderCommentActionWithHeader()
var rule = Substitute.For<IAdaptivityRuleViewModel>();
rule.Action.Returns(commentAction);
var adaptivityQuestion = Substitute.For<IAdaptivityQuestionViewModel>();
adaptivityQuestion.Rules.Returns(new List<IAdaptivityRuleViewModel> {rule});
adaptivityQuestion.Rules.Returns(new List<IAdaptivityRuleViewModel> { rule });

var sut = GetRenderedComponent(adaptivityQuestion);

var commentHeader = sut.Find("h6");
var comment = sut.Find("p.mud-typography-body1");
var commentHeader = sut.FindAll("p")[1];
var comment = sut.FindAll("p")[2];
Assert.Multiple(() =>
{
Assert.That(commentHeader.InnerHtml, Is.EqualTo("AdaptivityQuestionPreview.Header.Comment"));
Expand All @@ -120,12 +120,12 @@ public void Render_HasContentReferenceAction_RenderContentReferenceActionWithHea
var rule = Substitute.For<IAdaptivityRuleViewModel>();
rule.Action.Returns(contentReferenceAction);
var adaptivityQuestion = Substitute.For<IAdaptivityQuestionViewModel>();
adaptivityQuestion.Rules.Returns(new List<IAdaptivityRuleViewModel> {rule});
adaptivityQuestion.Rules.Returns(new List<IAdaptivityRuleViewModel> { rule });

var sut = GetRenderedComponent(adaptivityQuestion);

var commentHeader = sut.Find("h6");
var contentReference = sut.Find("p.mud-typography-body1");
var commentHeader = sut.FindAll("p")[1];
var contentReference = sut.FindAll("p")[5];
Assert.Multiple(() =>
{
Assert.That(commentHeader.InnerHtml, Is.EqualTo("AdaptivityQuestionPreview.Header.ContentReference"));
Expand All @@ -140,26 +140,38 @@ public void Render_HasElementReferenceAction_RenderElementReferenceActionWithHea
var elementId = elementReferenceAction.ElementId;
const string elementName = "expected";
_learningElementNamesProvider.ElementNames.Returns(doesElementExist
? new List<(Guid, string)> {(elementId, elementName)}
? new List<(Guid, string)> { (elementId, elementName) }
: new List<(Guid, string)>());
var rule = Substitute.For<IAdaptivityRuleViewModel>();
rule.Action.Returns(elementReferenceAction);
var adaptivityQuestion = Substitute.For<IAdaptivityQuestionViewModel>();
adaptivityQuestion.Rules.Returns(new List<IAdaptivityRuleViewModel> {rule});
adaptivityQuestion.Rules.Returns(new List<IAdaptivityRuleViewModel> { rule });

var sut = GetRenderedComponent(adaptivityQuestion);

var commentHeader = sut.Find("h6");
var elementReference = sut.Find("p.mud-typography-body1");
Assert.Multiple(() =>
if (doesElementExist)
{
var commentHeader = sut.FindAll("p")[1];
var elementReference = sut.FindAll("p")[6];
Assert.Multiple(() =>
{
Assert.That(commentHeader.InnerHtml, Is.EqualTo("AdaptivityQuestionPreview.Header.ElementReference"));
Assert.That(elementReference.InnerHtml, Is.Not.Empty);
});
Assert.That(elementReference.InnerHtml, Is.EqualTo(elementName));
}
else
{
Assert.That(commentHeader.InnerHtml, Is.EqualTo("AdaptivityQuestionPreview.Header.ElementReference"));
Assert.That(elementReference.InnerHtml, Is.Not.Empty);
var commentHeader = sut.FindAll("p")[1];
var elementReference = sut.FindAll("p")[2];
Assert.Multiple(() =>
{
Assert.That(commentHeader.InnerHtml, Is.EqualTo("AdaptivityQuestionPreview.Header.ElementReference"));
Assert.That(elementReference.InnerHtml, Is.Not.Empty);
});
Assert.That(elementReference.InnerHtml,
doesElementExist
? Is.EqualTo(elementName)
: Is.EqualTo("AdaptivityQuestionPreview.ElementReference.NotFound" + elementId));
});
Is.EqualTo("AdaptivityQuestionPreview.ElementReference.NotFound" + elementId));
}
}

private IRenderedComponent<AdaptivityQuestionPreview> GetRenderedComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ private async Task GetDialogAsync()
{
var dialogParameters = new DialogParameters
{
{nameof(AdaptivityContentDialog.MyContent), AdaptivityContent},
{nameof(AdaptivityContentDialog.DebounceInterval), 10}
{ nameof(AdaptivityContentDialog.MyContent), AdaptivityContent },
{ nameof(AdaptivityContentDialog.DebounceInterval), 10 }
};
Dialog = await OpenDialogAndGetDialogReferenceAsync(options: new DialogOptions(),
parameters: dialogParameters);
Expand Down Expand Up @@ -107,12 +107,13 @@ public async Task RenameTask_CallsPresentationLogic()
var button = DialogProvider.FindComponent<MudIconButton>().Find("button");
await button.ClickAsync(new MouseEventArgs());
var textFields = DialogProvider.FindComponents<MudTextField<string>>();
var textField = textFields[0].Find("input");
var textField = textFields[0].Find("textarea");
textField.Input("NewName");
// Wait for debounce
await Task.Delay(500);
DialogProvider.WaitForAssertion(() => PresentationLogic.Received(1)
.EditAdaptivityTask(Tasks.First(), "NewName", Tasks.First().MinimumRequiredDifficulty), TimeSpan.FromSeconds(2));
.EditAdaptivityTask(Tasks.First(), "NewName", Tasks.First().MinimumRequiredDifficulty),
TimeSpan.FromSeconds(2));
PresentationLogic.ClearReceivedCalls();

textField.Input("");
Expand All @@ -128,7 +129,7 @@ public async Task ChangeRequiredDifficulty_CallsPresentationLogic([Values] bool
var task = Substitute.For<IAdaptivityTaskViewModel>();
var question = Substitute.For<IAdaptivityQuestionViewModel>();
question.Difficulty.Returns(QuestionDifficulty.Medium);
task.Questions.Returns(new List<IAdaptivityQuestionViewModel> {question});
task.Questions.Returns(new List<IAdaptivityQuestionViewModel> { question });
task.MinimumRequiredDifficulty.Returns(wasSelectedAsRequired
? QuestionDifficulty.Medium
: null);
Expand All @@ -147,7 +148,7 @@ public async Task DeleteQuestionButtonClicked_CallsPresentationLogic()
var task = Substitute.For<IAdaptivityTaskViewModel>();
var question = Substitute.For<IAdaptivityQuestionViewModel>();
question.Difficulty.Returns(QuestionDifficulty.Medium);
task.Questions.Returns(new List<IAdaptivityQuestionViewModel> {question});
task.Questions.Returns(new List<IAdaptivityQuestionViewModel> { question });
AdaptivityContent.Tasks.Add(task);
await GetDialogAsync();
var iconButtons = DialogProvider.FindComponents<MudIconButton>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ private async Task GetDialogAsync()
{
var dialogParameters = new DialogParameters
{
{nameof(AdaptivityQuestionDialog.Task), Task},
{nameof(AdaptivityQuestionDialog.Difficulty), Difficulty}
{ nameof(AdaptivityQuestionDialog.Task), Task },
{ nameof(AdaptivityQuestionDialog.Difficulty), Difficulty }
};
Dialog = await OpenDialogAndGetDialogReferenceAsync("title", new DialogOptions(),
dialogParameters);
Expand All @@ -69,7 +69,7 @@ public async Task RenderDialog_ShowsMultipleChoiceQuestionForm([Values] bool has
question.Difficulty.Returns(Difficulty);
if (hasQuestionToEdit)
{
Task.Questions.Returns(new List<IAdaptivityQuestionViewModel> {question});
Task.Questions.Returns(new List<IAdaptivityQuestionViewModel> { question });
}

await GetDialogAsync();
Expand All @@ -95,7 +95,7 @@ public async Task RenderDialog_ShowsAdaptivityQuestionPreviewOfOtherQuestionsInT
questionHard.Difficulty.Returns(QuestionDifficulty.Hard);
if (hasOtherQuestions)
{
Task.Questions.Returns(new List<IAdaptivityQuestionViewModel> {questionEasy, questionHard});
Task.Questions.Returns(new List<IAdaptivityQuestionViewModel> { questionEasy, questionHard });
}

await GetDialogAsync();
Expand All @@ -116,7 +116,7 @@ public async Task RenderDialog_ShowsAdaptivityQuestionPreviewOfOtherQuestionsInT
Assert.Multiple(() =>
{
Assert.That(textComponents[0].Find("h6").InnerHtml, Is.EqualTo("title"));
Assert.That(textComponents[1].Find("h6").InnerHtml,
Assert.That(textComponents[1].Find("p").InnerHtml,
Is.EqualTo(hasOtherQuestions
? "AdaptivityQuestionDialog.Sidebar.Header.ExistingQuestions"
: "AdaptivityQuestionDialog.Sidebar.Header.NoQuestions"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Presentation.PresentationLogic.LearningContent.AdaptivityContent.Action;
using Presentation.PresentationLogic.LearningContent.AdaptivityContent.Question;
using Presentation.PresentationLogic.LearningContent.AdaptivityContent.Trigger;
using PresentationTest;
using Shared.Adaptivity;
using TestHelpers;

Expand All @@ -19,24 +18,6 @@ namespace IntegrationTest.Components.Adaptivity.Dialogues;
[TestFixture]
public class CreateEditCommentActionDialogIt : MudDialogTestFixture<CreateEditCommentActionDialog>
{
private IDialogReference Dialog { get; set; }
private CommentActionViewModel? ExistingAction { get; set; }
private IAdaptivityQuestionViewModel Question { get; set; }
private IPresentationLogic PresentationLogic { get; set; }

private async Task GetDialogAsync()
{
var dialogParameters = new DialogParameters
{
{ nameof(CreateEditCommentActionDialog.Question), Question },

};
if(ExistingAction != null)
dialogParameters.Add(nameof(CreateEditCommentActionDialog.ExistingAction), ExistingAction);
Dialog = await OpenDialogAndGetDialogReferenceAsync("title", new DialogOptions(),
dialogParameters);
}

[SetUp]
public async Task Setup()
{
Expand All @@ -53,11 +34,28 @@ public void Teardown()
DialogProvider.Dispose();
}

private IDialogReference Dialog { get; set; }
private CommentActionViewModel? ExistingAction { get; set; }
private IAdaptivityQuestionViewModel Question { get; set; }
private IPresentationLogic PresentationLogic { get; set; }

private async Task GetDialogAsync()
{
var dialogParameters = new DialogParameters
{
{ nameof(CreateEditCommentActionDialog.Question), Question },
};
if (ExistingAction != null)
dialogParameters.Add(nameof(CreateEditCommentActionDialog.ExistingAction), ExistingAction);
Dialog = await OpenDialogAndGetDialogReferenceAsync("title", new DialogOptions(),
dialogParameters);
}

[Test]
public async Task NoExistingAction_TextSet_CallsCreateAdaptivityRule()
{
var textField = DialogProvider.FindComponent<MudTextField<string>>();
textField.Find("input").Change("foo");
textField.Find("textarea").Change("foo");

await DialogProvider.FindComponent<MudButton>().Find("button").ClickAsync(new MouseEventArgs());

Expand All @@ -73,13 +71,13 @@ public async Task ExistingAction_TextSet_CallsEditCommentAction()
await GetDialogAsync();

var textField = DialogProvider.FindComponent<MudTextField<string>>();
textField.Find("input").Change("foo");
textField.Find("textarea").Change("foo");

await DialogProvider.FindComponent<MudButton>().Find("button").ClickAsync(new MouseEventArgs());

PresentationLogic.Received(1).EditCommentAction(ExistingAction, "foo");
}

[Test]
public async Task ExistingAction_SameTextSet_DoesNotCallEditCommentAction()
{
Expand All @@ -88,7 +86,7 @@ public async Task ExistingAction_SameTextSet_DoesNotCallEditCommentAction()
await GetDialogAsync();

var textField = DialogProvider.FindComponent<MudTextField<string>>();
textField.Find("input").Change(ExistingAction.Comment);
textField.Find("textarea").Change(ExistingAction.Comment);

await DialogProvider.FindComponent<MudButton>().Find("button").ClickAsync(new MouseEventArgs());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ namespace IntegrationTest.Components.Adaptivity.Dialogues;
[TestFixture]
public class CreateEditReferenceActionDialogIt : MudDialogTestFixture<CreateEditReferenceActionDialog>
{
private IDialogReference Dialog { get; set; }
private IAdaptivityActionViewModel? ExistingAction { get; set; }
private IAdaptivityQuestionViewModel Question { get; set; }
private IPresentationLogic PresentationLogic { get; set; }
private ILearningWorldPresenter LearningWorldPresenter { get; set; }
private ILearningWorldViewModel World { get; set; }
private ILearningContentViewModel[] Contents { get; set; }

private async Task GetDialogAsync()
{
var dialogParameters = new DialogParameters
{
{ nameof(CreateEditReferenceActionDialog.Question), Question },
};
if (ExistingAction != null)
dialogParameters.Add(nameof(CreateEditReferenceActionDialog.ExistingAction), ExistingAction);
Dialog = await OpenDialogAndGetDialogReferenceAsync("title", new DialogOptions(),
dialogParameters);
}

[SetUp]
public async Task Setup()
{
Expand All @@ -69,6 +49,26 @@ public void Teardown()
DialogProvider.Dispose();
}

private IDialogReference Dialog { get; set; }
private IAdaptivityActionViewModel? ExistingAction { get; set; }
private IAdaptivityQuestionViewModel Question { get; set; }
private IPresentationLogic PresentationLogic { get; set; }
private ILearningWorldPresenter LearningWorldPresenter { get; set; }
private ILearningWorldViewModel World { get; set; }
private ILearningContentViewModel[] Contents { get; set; }

private async Task GetDialogAsync()
{
var dialogParameters = new DialogParameters
{
{ nameof(CreateEditReferenceActionDialog.Question), Question },
};
if (ExistingAction != null)
dialogParameters.Add(nameof(CreateEditReferenceActionDialog.ExistingAction), ExistingAction);
Dialog = await OpenDialogAndGetDialogReferenceAsync("title", new DialogOptions(),
dialogParameters);
}

[Test]
[Ignore("Broken as long as ContentReference is blocked", Until = "2024-01-01")]
public async Task NoExistingAction_ContentSelected_CallsCreateAdaptivityRuleWithContentReferenceAction()
Expand Down Expand Up @@ -108,24 +108,25 @@ public async Task ExistingAction_ContentSelected_CallsUpdateContentReferenceActi
cravm.Content = Contents.First();
ExistingAction = cravm;
await GetDialogAsync();

await DialogProvider.Find("input").ChangeAsync(new ChangeEventArgs { Value = "foo" });

await DialogProvider.FindComponent<MudButton>().Find("button").ClickAsync(new MouseEventArgs());

PresentationLogic.Received().EditContentReferenceAction(cravm, cravm.Content, "foo");
}

[Test]
public async Task ExistingAction_ElementSelected_CallsUpdateElementReferenceAction()
{
var eravm = ViewModelProvider.GetElementReferenceAction();
eravm.ElementId = World.AllLearningElements.First().Id;
ExistingAction = eravm;
await GetDialogAsync();

await DialogProvider.Find("input").ChangeAsync(new ChangeEventArgs { Value = "foo" });


await DialogProvider.FindComponent<MudTextField<string>>().Find("textarea")
.ChangeAsync(new ChangeEventArgs { Value = "foo" });

await DialogProvider.FindComponent<MudButton>().Find("button").ClickAsync(new MouseEventArgs());

PresentationLogic.Received().EditElementReferenceAction(eravm, eravm.ElementId, "foo");
Expand All @@ -138,20 +139,20 @@ public async Task ExistingAction_ElementSelected_NoChange_CallsNothing()
cravm.Content = Contents.First();
ExistingAction = cravm;
await GetDialogAsync();

await DialogProvider.FindComponent<MudButton>().Find("button").ClickAsync(new MouseEventArgs());

PresentationLogic.DidNotReceiveWithAnyArgs().EditContentReferenceAction(cravm, cravm.Content, "foo");
}

[Test]
public async Task ExistingAction_ContentSelected_NoChange_CallsNothing()
{
var eravm = ViewModelProvider.GetElementReferenceAction();
eravm.ElementId = World.AllLearningElements.First().Id;
ExistingAction = eravm;
await GetDialogAsync();

await DialogProvider.FindComponent<MudButton>().Find("button").ClickAsync(new MouseEventArgs());

PresentationLogic.DidNotReceiveWithAnyArgs().EditElementReferenceAction(eravm, eravm.ElementId, "foo");
Expand Down
Loading

0 comments on commit 42dee7d

Please sign in to comment.