Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingel committed Apr 18, 2024
2 parents 07a8d96 + 3954db0 commit d64e5f2
Show file tree
Hide file tree
Showing 44 changed files with 1,270 additions and 763 deletions.
9 changes: 9 additions & 0 deletions .idea/.idea.JishoTangoAssistant/.idea/avalonia.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

191 changes: 187 additions & 4 deletions JishoTangoAssistant.Tests/ObservableVocabularyListTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using JishoTangoAssistant.Models;

namespace JishoTangoAssistant.Tests
Expand All @@ -25,15 +27,36 @@ public void EmptyListTest()
{
Assert.AreEqual(0, list.Count);
}

[Test]
public void AssignmentTest()
{
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));
list[0] = new VocabularyItem("飲む", false, "のむ", "to drink");
Assert.AreEqual(1, list.Count);
Assert.AreEqual(new VocabularyItem("飲む", false, "のむ", "to drink"), list[0]);
}

[Test]
public void AddTest()
{
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));
Assert.AreEqual(1, list.Count);
list.Add(new VocabularyItem("飲む", false, "のむ", "to drink"));
Assert.AreEqual(2, list.Count);
}

[Test]
public void InsertTest()
{
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));
list.Add(new VocabularyItem("飲む", false, "のむ", "to drink"));
list.Insert(1, new VocabularyItem("ある", true, "ある", "to be"));

Assert.AreEqual(3, list.Count);
Assert.AreEqual(new VocabularyItem("食べる", false, "たべる", "to eat"), list[0]);
Assert.AreEqual(new VocabularyItem("ある", true, "ある", "to be"), list[1]);
Assert.AreEqual(new VocabularyItem("飲む", false, "のむ", "to drink"), list[2]);
}

[Test]
public void GetTest()
Expand All @@ -53,8 +76,8 @@ public void ClearTest()
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));
list.Add(new VocabularyItem("飲む", false, "のむ", "to drink"));
list.Add(new VocabularyItem("ある", true, "ある", "to be"));

list.Clear();

Assert.AreEqual(0, list.Count);
}

Expand All @@ -65,10 +88,24 @@ public void RemoveAtTest()
list.Add(new VocabularyItem("飲む", false, "のむ", "to drink"));
list.Add(new VocabularyItem("ある", true, "ある", "to be"));
list.Add(new VocabularyItem("いる", true, "いる", "to be"));

list.Clear();

Assert.AreEqual(0, list.Count);
}

[Test]
public void RemoveTest()
{
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));
list.Add(new VocabularyItem("飲む", false, "のむ", "to drink"));
list.Add(new VocabularyItem("ある", true, "ある", "to be"));
list.Remove(new VocabularyItem("飲む", false, "のむ", "to drink"));

Assert.AreEqual(2, list.Count);
Assert.IsTrue(list.ContainsWord("食べる"));
Assert.IsTrue(list.ContainsWord("ある"));
Assert.IsFalse(list.ContainsWord("飲む"));
}

[Test]
public void ContainsTest()
Expand All @@ -84,6 +121,25 @@ public void ContainsTest()
Assert.IsTrue(list.Contains(new VocabularyItem("いる", true, "いる", "to be")));
Assert.IsFalse(list.Contains(new VocabularyItem("ある", false, "いる", "to be")));
}

[Test]
public void AddRangeTest()
{
var itemsToAdd = new List<VocabularyItem>()
{
new("飲む", false, "のむ", "to drink"),
new("ある", true, "ある", "to be"),
new("いる", true, "いる", "to be")
};
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));

list.AddRange(itemsToAdd);

Assert.IsTrue(list.ContainsWord("食べる"));
Assert.IsTrue(list.ContainsWord("飲む"));
Assert.IsTrue(list.ContainsWord("ある"));
Assert.IsTrue(list.ContainsWord("いる"));
}

[Test]
public void ContainsWordTest()
Expand Down Expand Up @@ -111,5 +167,132 @@ public void ContainsWordTest()
Assert.IsFalse(list.ContainsWord(""));
Assert.IsTrue(list.ContainsWord("する"));
}

[Test]
public void UndoEmptyListTest()
{
list.Undo();

Assert.IsEmpty(list);
}

[Test]
public void UndoAssignmentTest()
{
list.Add(new VocabularyItem("ある", true, "ある", "to be"));
list[0] = new VocabularyItem("いる", true, "いる", "to be");

list.Undo();

Assert.AreEqual(new VocabularyItem("ある", true, "ある", "to be"), list[0]);
}

[Test]
public void UndoAddTest()
{
list.Add(new VocabularyItem("ある", true, "ある", "to be"));
list.Add(new VocabularyItem("いる", true, "いる", "to be"));

list.Undo();

Assert.IsFalse(list.ContainsWord("いる"));
Assert.AreEqual(new VocabularyItem("ある", true, "ある", "to be"), list.Last());
}

[Test]
public void UndoRemoveTest()
{
list.Add(new VocabularyItem("いる", true, "いる", "to be"));
list.Remove(new VocabularyItem("いる", true, "いる", "to be"));

list.Undo();

Assert.IsTrue(list.ContainsWord("いる"));
}

[Test]
public void UndoClearTest()
{
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));
list.Add(new VocabularyItem("飲む", false, "のむ", "to drink"));
list.Add(new VocabularyItem("ある", true, "ある", "to be"));
list.Add(new VocabularyItem("いる", true, "いる", "to be"));

list.Clear();

list.Undo();

Assert.IsTrue(list.ContainsWord("食べる"));
Assert.IsTrue(list.ContainsWord("飲む"));
Assert.IsTrue(list.ContainsWord("ある"));
Assert.IsTrue(list.ContainsWord("いる"));
}

[Test]
public void UndoRemoveAtTest()
{
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));
list.Add(new VocabularyItem("飲む", false, "のむ", "to drink"));
list.Add(new VocabularyItem("ある", true, "ある", "to be"));
list.Add(new VocabularyItem("いる", true, "いる", "to be"));

list.RemoveAt(1);

list.Undo();

Assert.AreEqual(new VocabularyItem("食べる", false, "たべる", "to eat"), list[0]);
Assert.AreEqual(new VocabularyItem("飲む", false, "のむ", "to drink"), list[1]);
Assert.AreEqual(new VocabularyItem("ある", true, "ある", "to be"), list[2]);
Assert.AreEqual(new VocabularyItem("いる", true, "いる", "to be"), list[3]);
}

[Test]
public void UndoInsertTest()
{
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));
list.Add(new VocabularyItem("ある", true, "ある", "to be"));
list.Add(new VocabularyItem("いる", true, "いる", "to be"));

list.Insert(1, new VocabularyItem("飲む", false, "のむ", "to drink"));

list.Undo();

Assert.AreEqual(new VocabularyItem("食べる", false, "たべる", "to eat"), list[0]);
Assert.AreEqual(new VocabularyItem("ある", true, "ある", "to be"), list[1]);
Assert.AreEqual(new VocabularyItem("いる", true, "いる", "to be"), list[2]);
Assert.IsFalse(list.ContainsWord("飲む"));
}

[Test]
public void UndoAddRangeTest()
{
var itemsToAdd = new List<VocabularyItem>()
{
new("飲む", false, "のむ", "to drink"),
new("ある", true, "ある", "to be"),
new("いる", true, "いる", "to be")
};
list.Add(new VocabularyItem("食べる", false, "たべる", "to eat"));

list.AddRange(itemsToAdd);

list.Undo();

Assert.IsTrue(list.ContainsWord("食べる"));
Assert.IsFalse(list.ContainsWord("飲む"));
Assert.IsFalse(list.ContainsWord("ある"));
Assert.IsFalse(list.ContainsWord("いる"));
}

[Test]
public void UndoMoreOperationsThanOtherOperationsTest()
{
list.Add(new VocabularyItem("ある", true, "ある", "to be"));

list.Undo();
list.Undo();

Assert.IsEmpty(list);
}
}
}
5 changes: 5 additions & 0 deletions JishoTangoAssistant/App.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:JishoTangoAssistant.UI"
x:Class="JishoTangoAssistant.App"
RequestedThemeVariant="Dark">
<Application.DataTemplates>
<ui:ViewLocator />
</Application.DataTemplates>

<Application.Styles>
<SimpleTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Simple.xaml"/>
Expand Down
21 changes: 18 additions & 3 deletions JishoTangoAssistant/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using JishoTangoAssistant.UI.View;
using JishoTangoAssistant.UI;
using JishoTangoAssistant.UI.Views;
using JishoTangoAssistant.UI.ViewModels;
using Microsoft.Extensions.DependencyInjection;

namespace JishoTangoAssistant
{
public partial class App : Application
public class App : Application
{
private readonly IServiceProvider serviceCollection;

public App(IServiceProvider serviceCollection)
{
this.serviceCollection = serviceCollection;
}

public override void Initialize()
{
Resources[typeof(IServiceProvider)] = serviceCollection;
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new JishoTangoAssistantWindow();
desktop.MainWindow = new JishoTangoAssistantWindowView
{
DataContext = serviceCollection.GetRequiredService<JishoTangoAssistantWindowViewModel>(),
};
}

base.OnFrameworkInitializationCompleted();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using JishoTangoAssistant.Models;

namespace JishoTangoAssistant.Interfaces;

public interface ICurrentJapaneseUserInputSelectionService
{
ObservableCollection<string> GetWords();
ObservableCollection<string> GetOtherForms();
ObservableRangeCollection<SimilarMeaningsGroup> GetMeanings();
int GetSelectedWordsIndex();
void SetSelectedWordsIndex(int value);
int GetSelectedOtherFormsIndex();
void SetSelectedOtherFormsIndex(int value);
string GetReadingOutput();
string GetAdditionalComments();
void SetAdditionalComments(string value);
bool GetWriteInKana();
public void SetWriteInKana(bool value);
public bool GetItemAdditionPossible();
Task UpdateSelectionAsync(string preprocessedInput);
VocabularyItem? CreateVocabularyItem();
void UpdateOtherForms();
bool OnlyOneMeaningInSelection();
void ChangeIsEnabledForAllMeanings(bool isEnabled);
}
10 changes: 5 additions & 5 deletions JishoTangoAssistant/JishoTangoAssistant.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<TrimmableAssembly Include="Avalonia.Themes.Default" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.9" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.9" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.9" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.9" />
<PackageReference Include="Avalonia.Themes.Simple" Version="11.0.9" />
<PackageReference Include="Avalonia" Version="11.0.10" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.10" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
<PackageReference Include="Avalonia.Themes.Simple" Version="11.0.10" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
Expand Down
Loading

0 comments on commit d64e5f2

Please sign in to comment.