This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for paginatedlistview
- Loading branch information
1 parent
b0003d0
commit 2a061cc
Showing
8 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Improbable.Gdk.Debug.WorkerInspector.Codegen.EditmodeTests")] |
3 changes: 3 additions & 0 deletions
3
workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/AssemblyInfo.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
workers/unity/Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/Tests.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...Inspector/Codegen/Tests/Improbable.Gdk.Debug.WorkerInspector.Codegen.EditmodeTests.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "Improbable.Gdk.Debug.WorkerInspector.Codegen.EditmodeTests", | ||
"references": [ | ||
"Improbable.Gdk.Debug.WorkerInspector.Codegen" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
7 changes: 7 additions & 0 deletions
7
...ctor/Codegen/Tests/Improbable.Gdk.Debug.WorkerInspector.Codegen.EditmodeTests.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
181 changes: 181 additions & 0 deletions
181
.../Packages/io.improbable.gdk.debug/WorkerInspector/Codegen/Tests/PaginatedListViewTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using UnityEngine.UIElements; | ||
|
||
namespace Improbable.Gdk.Debug.WorkerInspector.Codegen.EditmodeTests | ||
{ | ||
[TestFixture] | ||
public class PaginatedListViewTests | ||
{ | ||
[Test] | ||
public void Only_up_to_elementsPerPage_are_rendered_at_once() | ||
{ | ||
var data = GetDummyData(10); | ||
var observer = new PaginatedListViewObserver(5); | ||
|
||
observer.UpdateData(data); | ||
|
||
var elements = observer.VisibleElements.ToList(); | ||
|
||
Assert.AreEqual(5, elements.Count); | ||
} | ||
|
||
[Test] | ||
public void Correct_list_slice_is_rendered_in_order() | ||
{ | ||
var data = GetDummyData(10); | ||
var observer = new PaginatedListViewObserver(5); | ||
|
||
observer.UpdateData(data); | ||
|
||
var elements = observer.VisibleElements.ToList(); | ||
|
||
for (var i = 0; i < elements.Count; i++) | ||
{ | ||
Assert.AreEqual(i, ((PaginatedListViewObserver.DummyElement) elements[i]).Index); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Forward_button_is_disabled_when_no_more_pages() | ||
{ | ||
var data = GetDummyData(5); | ||
var observer = new PaginatedListViewObserver(5); | ||
observer.UpdateData(data); | ||
Assert.IsFalse(observer.IsPageForwardButtonEnabled); | ||
} | ||
|
||
[Test] | ||
public void Back_button_is_disabled_when_no_more_pages() | ||
{ | ||
var data = GetDummyData(5); | ||
var observer = new PaginatedListViewObserver(5); | ||
observer.UpdateData(data); | ||
Assert.IsFalse(observer.IsPageBackButtonEnabled); | ||
} | ||
|
||
[Test] | ||
public void Forward_button_is_enabled_if_more_pages() | ||
{ | ||
var data = GetDummyData(10); | ||
var observer = new PaginatedListViewObserver(5); | ||
observer.UpdateData(data); | ||
Assert.IsTrue(observer.IsPageForwardButtonEnabled); | ||
} | ||
|
||
[Test] | ||
public void Back_button_is_enabled_if_more_pages() | ||
{ | ||
var data = GetDummyData(10); | ||
var observer = new PaginatedListViewObserver(5); | ||
observer.UpdateData(data); | ||
observer.TryPageForward(); | ||
Assert.IsTrue(observer.IsPageBackButtonEnabled); | ||
} | ||
|
||
[Test] | ||
public void Paging_forward_updates_rendered_data() | ||
{ | ||
var data = GetDummyData(15); | ||
var observer = new PaginatedListViewObserver(5); | ||
|
||
observer.UpdateData(data); | ||
observer.TryPageForward(); | ||
|
||
var elements = observer.VisibleElements.ToList(); | ||
|
||
for (var i = 0; i < elements.Count; i++) | ||
{ | ||
var expectedIndex = i + 5; // We expect to be on the second page. | ||
Assert.AreEqual(expectedIndex, ((PaginatedListViewObserver.DummyElement) elements[i]).Index); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Paging_backwards_updates_rendered_data() | ||
{ | ||
var data = GetDummyData(15); | ||
var observer = new PaginatedListViewObserver(5); | ||
|
||
observer.UpdateData(data); | ||
observer.TryPageForward(); | ||
observer.TryPageBackwards(); | ||
|
||
var elements = observer.VisibleElements.ToList(); | ||
|
||
for (var i = 0; i < elements.Count; i++) | ||
{ | ||
Assert.AreEqual(i, ((PaginatedListViewObserver.DummyElement) elements[i]).Index); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Sub_slice_of_list_can_be_rendered() | ||
{ | ||
var data = GetDummyData(8); | ||
var observer = new PaginatedListViewObserver(5); | ||
|
||
observer.UpdateData(data); | ||
observer.TryPageForward(); | ||
|
||
var elements = observer.VisibleElements.ToList(); | ||
|
||
Assert.AreEqual(3, elements.Count); | ||
|
||
for (var i = 0; i < elements.Count; i++) | ||
{ | ||
var expectedIndex = i + 5; // We expect to be on the second page. | ||
Assert.AreEqual(expectedIndex, ((PaginatedListViewObserver.DummyElement) elements[i]).Index); | ||
} | ||
} | ||
|
||
private class PaginatedListViewObserver | ||
{ | ||
public bool IsPageForwardButtonEnabled => listView.Q<Button>(name: "forward-button").enabledSelf; | ||
public bool IsPageBackButtonEnabled => listView.Q<Button>(name: "back-button").enabledSelf; | ||
|
||
public IEnumerable<VisualElement> VisibleElements => | ||
listView | ||
.Q<VisualElement>(className: "user-defined-type-container-data") | ||
.Children(); | ||
|
||
private readonly PaginatedListView<DummyElement, int> listView; | ||
|
||
public PaginatedListViewObserver(int elementsPerPage) | ||
{ | ||
listView = new PaginatedListView<DummyElement, int>("My List", | ||
() => new DummyElement(), | ||
(index, _, element) => | ||
{ | ||
element.Index = index; | ||
}, elementsPerPage); | ||
} | ||
|
||
public void TryPageForward() | ||
{ | ||
listView.ChangePageCount(1); | ||
} | ||
|
||
public void TryPageBackwards() | ||
{ | ||
listView.ChangePageCount(-1); | ||
} | ||
|
||
public void UpdateData(List<int> data) | ||
{ | ||
listView.Update(data); | ||
} | ||
|
||
public class DummyElement : VisualElement | ||
{ | ||
public int Index; | ||
} | ||
} | ||
|
||
private static List<int> GetDummyData(int count) | ||
{ | ||
return Enumerable.Repeat(0, count).ToList(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ages/io.improbable.gdk.debug/WorkerInspector/Codegen/Tests/PaginatedListViewTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.