Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2a90e3c
Implement the AutoSuggestion in TextBox by using TextFieldAssist.Auto…
AbderrahmaneAhmam May 20, 2023
b3e1d3f
Fixing the code warnings about the null values
AbderrahmaneAhmam May 21, 2023
1e7552d
Fix warnings in the FieldsViewModel 0 Warning(s)
AbderrahmaneAhmam May 21, 2023
0f1bb1c
Add underscore prefix to the private properties
AbderrahmaneAhmam May 22, 2023
6d41235
Reset changes of the AutoSuggestion in the TextFieldAssist
AbderrahmaneAhmam May 27, 2023
d509195
creation of control AutoSuggestBox Based on TextBox with custom Templ…
AbderrahmaneAhmam Jun 19, 2023
dbaa4e3
Fix Warnings
AbderrahmaneAhmam Jun 19, 2023
e0d3ed0
Rebase build fixing
Keboo Aug 10, 2023
7d85d89
Adding some TODOs, starting on the UI tests
Keboo Aug 10, 2023
03ec8e4
Merge branch 'MaterialDesignInXAML:master' into feature/AutoSuggestion
AbderrahmaneAhmam Aug 12, 2023
aa7b202
Merge branch 'master' of https://github.com/AbderrahmaneAhmam/Materia…
AbderrahmaneAhmam Aug 12, 2023
0fdfbd7
Merge branch 'feature/AutoSuggestion' of https://github.com/Abderrahm…
AbderrahmaneAhmam Aug 12, 2023
829e298
Remove AutoSuggestBox from properties
AbderrahmaneAhmam Aug 12, 2023
e6b148a
Implement the tests:
AbderrahmaneAhmam Aug 12, 2023
26f2c22
WIP showing sample test for ICollectionView
Keboo Aug 13, 2023
9946cab
Merge branch 'MaterialDesignInXAML:master' into feature/AutoSuggestion
AbderrahmaneAhmam Aug 14, 2023
408708b
Merge branch 'MaterialDesignInXAML:master' into feature/AutoSuggestion
AbderrahmaneAhmam Aug 17, 2023
8d8889e
Use ICollectionView for keyboard navigation and ensure completion of …
AbderrahmaneAhmam Sep 3, 2023
d47c665
rename key
AbderrahmaneAhmam Sep 3, 2023
e1f4419
Merge branch 'MaterialDesignInXAML:master' into feature/AutoSuggestion
AbderrahmaneAhmam Sep 3, 2023
596f708
Merge branch 'master' of https://github.com/AbderrahmaneAhmam/Materia…
AbderrahmaneAhmam Sep 3, 2023
82bee7a
Merge branch 'feature/AutoSuggestion' of https://github.com/Abderrahm…
AbderrahmaneAhmam Sep 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP showing sample test for ICollectionView
  • Loading branch information
Keboo committed Aug 13, 2023
commit 26f2c22bf51285e6dcb5be5a2382f9e577c2aa98
31 changes: 0 additions & 31 deletions MaterialDesignThemes.UITests/BaseViewModel.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<UserControl x:Class="MaterialDesignThemes.UITests.Samples.AutoSuggestBoxes.AutoSuggestTextBoxWithCollectionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MaterialDesignThemes.UITests.Samples.AutoSuggestBoxes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type={x:Type local:AutoSuggestTextBoxWithCollectionViewViewModel}}"
d:DesignHeight="450" d:DesignWidth="800">
<!-- TODO: Selction Similar to SelectedItem="{Binding Suggestions/}" perhaps needing IsSynchronizedWithCurrentItem="True" -->
<StackPanel>
<materialDesign:AutoSuggestBox
materialDesign:HintAssist.HelperText="Name"
materialDesign:TextFieldAssist.HasClearButton="True"
Text="{Binding AutoSuggestText, UpdateSourceTrigger=PropertyChanged}"
Suggestions="{Binding Suggestions}">
</materialDesign:AutoSuggestBox>
<!--
<ComboBox ItemsSource="{Binding Suggestions}"
Margin="0,10"
IsSynchronizedWithCurrentItem="True"/>
<ListBox ItemsSource="{Binding Suggestions}"
IsSynchronizedWithCurrentItem="True"/>
-->

</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using CommunityToolkit.Mvvm.ComponentModel;
using MaterialDesignThemes.UITests.Samples.AutoSuggestTextBoxes;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Data;

namespace MaterialDesignThemes.UITests.Samples.AutoSuggestBoxes;

/// <summary>
/// Interaction logic for AutoSuggestTextBoxWithCollectionView.xaml
/// </summary>
public partial class AutoSuggestTextBoxWithCollectionView
{
public AutoSuggestTextBoxWithCollectionView()
{
DataContext = new AutoSuggestTextBoxWithCollectionViewViewModel();
InitializeComponent();
}
}

public partial class AutoSuggestTextBoxWithCollectionViewViewModel : ObservableObject
{
private ObservableCollection<string> BaseSuggestions { get; }

public ICollectionView Suggestions { get; }

[ObservableProperty]
private string? _autoSuggestText;

partial void OnAutoSuggestTextChanged(string? oldValue, string? newValue)
{
if (!string.IsNullOrWhiteSpace(newValue))
{
Suggestions.Filter = x => IsMatch((string)x, newValue);
}
else
{
Suggestions.Filter = null;
}
base.OnPropertyChanged(nameof(Suggestions));
}

public AutoSuggestTextBoxWithCollectionViewViewModel()
{
BaseSuggestions = new()
{
"Apples",
"Bananas",
"Beans",
"Mtn Dew",
"Orange",
};
Suggestions = CollectionViewSource.GetDefaultView(BaseSuggestions);
}

private static bool IsMatch(string item, string currentText)
{
#if NET6_0_OR_GREATER
return item.Contains(currentText, StringComparison.OrdinalIgnoreCase);
#else
return item.IndexOf(currentText, StringComparison.OrdinalIgnoreCase) >= 0;
#endif
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using Google.Protobuf.WellKnownTypes;

namespace MaterialDesignThemes.UITests.Samples.AutoSuggestTextBoxes;

Expand All @@ -14,45 +16,40 @@ public AutoSuggestTextBoxWithTemplate()
}
}

public partial class AutoSuggestTextBoxWithTemplateViewModel : BaseViewModel
public partial class AutoSuggestTextBoxWithTemplateViewModel : ObservableObject
{
private List<SuggestionThing> _baseSuggestions { get; }
private List<SuggestionThing> BaseSuggestions { get; }

[ObservableProperty]
private ObservableCollection<SuggestionThing> _suggestions = new();
public ObservableCollection<SuggestionThing> Suggestions
{
get => _suggestions;
set => SetProperty(ref _suggestions, value);
}

[ObservableProperty]
private string? _autoSuggestText;

public string? AutoSuggestText
partial void OnAutoSuggestTextChanged(string? oldValue, string? newValue)
{
get => _autoSuggestText;
set
if (!string.IsNullOrWhiteSpace(newValue))
{
if (SetProperty(ref _autoSuggestText, value) && !string.IsNullOrEmpty(value))
{
var searchResult = _baseSuggestions.Where(x => IsMatch(x.Name, value));
//MessageBox.Show(searchResult.Count().ToString(), "Test");
Suggestions = new(searchResult);
}
var searchResult = BaseSuggestions.Where(x => IsMatch(x.Name, newValue));
Suggestions = new(searchResult);
}
else
{
Suggestions = new(BaseSuggestions);
}
}


public AutoSuggestTextBoxWithTemplateViewModel()
{
_baseSuggestions = new()
BaseSuggestions = new()
{
new("Apples"),
new("Bananas"),
new("Beans"),
new("Mtn Dew"),
new("Orange"),
};
Suggestions = new ObservableCollection<SuggestionThing>(_baseSuggestions);
Suggestions = new ObservableCollection<SuggestionThing>(BaseSuggestions);
}

private static bool IsMatch(string item, string currentText)
Expand Down
3 changes: 2 additions & 1 deletion MaterialDesignThemes.UITests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace MaterialDesignThemes.UITests;

public abstract class TestBase : IAsyncLifetime
{
protected bool AttachedDebugger { get; set; } = true;
protected ITestOutputHelper Output { get; }

[NotNull]
Expand Down Expand Up @@ -43,7 +44,7 @@ protected async Task<IVisualElement> LoadUserControl<TControl>()
public async Task InitializeAsync() =>
App = await XamlTest.App.StartRemote(new AppOptions
{
AllowVisualStudioDebuggerAttach = true,
AllowVisualStudioDebuggerAttach = AttachedDebugger,
LogMessage = Output.WriteLine
});
public async Task DisposeAsync() => await App.DisposeAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.Collections.ObjectModel;
using System.Windows.Controls;
using MaterialDesignThemes.UITests.Samples.AutoSuggestBoxes;
using MaterialDesignThemes.UITests.Samples.AutoSuggestTextBoxes;
using XamlTest;
using static System.Net.Mime.MediaTypeNames;
using Xunit.Sdk;

namespace MaterialDesignThemes.UITests.WPF.AutoSuggestBoxes;

public class AutoSuggestBoxTests : TestBase
{
public AutoSuggestBoxTests(ITestOutputHelper output)
: base(output)
{ }
{
}

[Fact]
public async Task CanFilterItems_WithSuggestionsAndDisplayMember_FiltersSuggestions()
Expand Down Expand Up @@ -44,10 +43,10 @@ public async Task CanFilterItems_WithSuggestionsAndDisplayMember_FiltersSuggesti
}

[Fact]
public async Task CanChoiseItem_FromTheSuggestions_AssertTheTextUpdated()
public async Task CanChoiceItem_FromTheSuggestions_AssertTheTextUpdated()
{
await using var recorder = new TestRecorder(App);

//Arrange
IVisualElement<AutoSuggestBox> suggestBox = (await LoadUserControl<AutoSuggestTextBoxWithTemplate>()).As<AutoSuggestBox>();
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
Expand All @@ -61,7 +60,7 @@ public async Task CanChoiseItem_FromTheSuggestions_AssertTheTextUpdated()
Assert.True(await suggestBox.GetIsSuggestionOpen());
Assert.True(await popup.GetIsOpen());

//Choise Item from the list
//Choose Item from the list
var bananas = await suggestionListBox.GetElement<ListBoxItem>("/ListBoxItem[0]");
await Task.Delay(100);
await bananas.LeftClick();
Expand All @@ -72,18 +71,50 @@ public async Task CanChoiseItem_FromTheSuggestions_AssertTheTextUpdated()
recorder.Success();
}

[Fact(Skip = "This needs ICollectionView")]
public async Task CanFilterItems_WithCollectionView_FiltersSuggestions()
{
await using var recorder = new TestRecorder(App);

//Arrange
IVisualElement userControl = await LoadUserControl<AutoSuggestTextBoxWithCollectionView>();
IVisualElement<AutoSuggestBox> suggestBox = await userControl.GetElement<AutoSuggestBox>();
IVisualElement<Popup> popup = await suggestBox.GetElement<Popup>();
IVisualElement<ListBox> suggestionListBox = await popup.GetElement<ListBox>();

//Act
await suggestBox.MoveKeyboardFocus();
await suggestBox.SendInput(new KeyboardInput("B"));


//Assert
Assert.True(await suggestBox.GetIsSuggestionOpen());
Assert.True(await popup.GetIsOpen());

//Validates these elements are found
await AssertExists(suggestionListBox, "Bananas");
await AssertExists(suggestionListBox, "Beans");

//Validate other items are hidden
await AssertExists(suggestionListBox, "Apples", false);
await AssertExists(suggestionListBox, "Mtn Dew", false);
await AssertExists(suggestionListBox, "Orange", false);

recorder.Success();
}

//TODO: Test case with ICollectionSource

private async Task AssertExists(IVisualElement<ListBox> suggestionListBox, string text, bool existsOrNotCheck = true)
private static async Task AssertExists(IVisualElement<ListBox> suggestionListBox, string text, bool existsOrNotCheck = true)
{
try
{
_ = await suggestionListBox.GetElement(ElementQuery.PropertyExpression<TextBlock>(x => x.Text, text));
Assert.True(existsOrNotCheck);
}
catch (Exception)
catch (Exception e) when (e is not TrueException)
{
Assert.True(!existsOrNotCheck);
Assert.False(existsOrNotCheck);
}
}
}