Skip to content

Commit

Permalink
item/cell trigger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Mar 11, 2024
1 parent 11e4332 commit 50bfc07
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/src/feathers/controls/ButtonBarTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package feathers.controls;

import openfl.events.TouchEvent;
import feathers.events.TriggerEvent;
import openfl.events.MouseEvent;
import feathers.events.ButtonBarEvent;
import feathers.controls.dataRenderers.IDataRenderer;
import feathers.data.ArrayCollection;
import feathers.data.ButtonBarItemState;
Expand Down Expand Up @@ -361,6 +365,36 @@ class ButtonBarTest extends Test {
Assert.notNull(button);
Assert.equals(customVariant2, button.variant);
}

private function testDispatchItemTriggerFromMouseClick():Void {
this._buttonBar.dataProvider = new ArrayCollection([{text: "One"}, {text: "Two"}, {text: "Three"}]);
var item = this._buttonBar.dataProvider.get(1);
this._buttonBar.validateNow();
var button = cast(this._buttonBar.itemToButton(item), Button);
var dispatchedTriggerCount = 0;
this._buttonBar.addEventListener(ButtonBarEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(event.state.index, 1);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromMouseEvent(button, new MouseEvent(MouseEvent.CLICK));
Assert.equals(1, dispatchedTriggerCount);
}

private function testDispatchItemTriggerFromTouchTap():Void {
this._buttonBar.dataProvider = new ArrayCollection([{text: "One"}, {text: "Two"}, {text: "Three"}]);
var item = this._buttonBar.dataProvider.get(1);
this._buttonBar.validateNow();
var button = cast(this._buttonBar.itemToButton(item), Button);
var dispatchedTriggerCount = 0;
this._buttonBar.addEventListener(ButtonBarEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(event.state.index, 1);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromTouchEvent(button, new TouchEvent(TouchEvent.TOUCH_TAP));
Assert.equals(1, dispatchedTriggerCount);
}
}

private class CustomRendererWithInterfaces extends Button implements IDataRenderer implements ILayoutIndexObject {
Expand Down
47 changes: 47 additions & 0 deletions test/src/feathers/controls/GridViewTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package feathers.controls;

import openfl.events.TouchEvent;
import openfl.events.MouseEvent;
import feathers.events.TriggerEvent;
import feathers.events.GridViewEvent;
import openfl.errors.RangeError;
import feathers.skins.RectangleSkin;
import feathers.controls.dataRenderers.ItemRenderer;
Expand Down Expand Up @@ -1121,6 +1125,49 @@ class GridViewTest extends Test {
Assert.equals(0.0, this._gridView.minScrollY);
Assert.isTrue(this._gridView.maxScrollY > 0.0);
}

private function testDispatchItemTriggerFromMouseClick():Void {
this._gridView.dataProvider = new ArrayCollection([{a: "A0", b: "B0"}, {a: "A1", b: "B1"}, {a: "A2", b: "B2"}]);
this._gridView.columns = new ArrayCollection([
new GridViewColumn("A", item -> item.a),
new GridViewColumn("B", item -> item.b),
]);
var item = this._gridView.dataProvider.get(1);
var column = this._gridView.columns.get(0);
this._gridView.validateNow();
var cellRenderer = cast(this._gridView.itemAndColumnToCellRenderer(item, column), ItemRenderer);
var dispatchedTriggerCount = 0;
this._gridView.addEventListener(GridViewEvent.CELL_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(event.state.rowIndex, 1);
Assert.equals(event.state.columnIndex, 0);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromMouseEvent(cellRenderer, new MouseEvent(MouseEvent.CLICK));
Assert.equals(1, dispatchedTriggerCount);
}

private function testDispatchItemTriggerFromTouchTap():Void {
this._gridView.dataProvider = new ArrayCollection([{a: "A0", b: "B0"}, {a: "A1", b: "B1"}, {a: "A2", b: "B2"}]);
this._gridView.columns = new ArrayCollection([
new GridViewColumn("A", item -> item.a),
new GridViewColumn("B", item -> item.b),
]);
this._gridView.dataProvider = new ArrayCollection([{text: "One"}, {text: "Two"}, {text: "Three"}]);
var item = this._gridView.dataProvider.get(1);
var column = this._gridView.columns.get(0);
this._gridView.validateNow();
var cellRenderer = cast(this._gridView.itemAndColumnToCellRenderer(item, column), ItemRenderer);
var dispatchedTriggerCount = 0;
this._gridView.addEventListener(GridViewEvent.CELL_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(event.state.rowIndex, 1);
Assert.equals(event.state.columnIndex, 0);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromTouchEvent(cellRenderer, new TouchEvent(TouchEvent.TOUCH_TAP));
Assert.equals(1, dispatchedTriggerCount);
}
}

private class CustomRendererWithInterfaces extends LayoutGroup implements IToggle implements IDataRenderer implements ILayoutIndexObject
Expand Down
40 changes: 40 additions & 0 deletions test/src/feathers/controls/GroupListViewTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package feathers.controls;

import openfl.events.TouchEvent;
import feathers.events.GroupListViewEvent;
import openfl.events.MouseEvent;
import feathers.events.TriggerEvent;
import openfl.errors.ArgumentError;
import openfl.errors.RangeError;
import feathers.data.GroupListViewItemState;
Expand Down Expand Up @@ -744,6 +748,42 @@ class GroupListViewTest extends Test {
Assert.notNull(itemRenderer);
Assert.equals(customVariant2, itemRenderer.variant);
}

private function testDispatchItemTriggerFromMouseClick():Void {
this._listView.dataProvider = new ArrayHierarchicalCollection([{text: "A", children: [{text: "One"}, {text: "Two"}, {text: "Three"}]}],
(item:Dynamic) -> item.children);
var item = this._listView.dataProvider.get([0, 1]);
this._listView.validateNow();
var itemRenderer = cast(this._listView.itemToItemRenderer(item), ItemRenderer);
var dispatchedTriggerCount = 0;
this._listView.addEventListener(GroupListViewEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(2, event.state.location.length);
Assert.equals(0, event.state.location[0]);
Assert.equals(1, event.state.location[1]);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromMouseEvent(itemRenderer, new MouseEvent(MouseEvent.CLICK));
Assert.equals(1, dispatchedTriggerCount);
}

private function testDispatchItemTriggerFromTouchTap():Void {
this._listView.dataProvider = new ArrayHierarchicalCollection([{text: "A", children: [{text: "One"}, {text: "Two"}, {text: "Three"}]}],
(item:Dynamic) -> item.children);
var item = this._listView.dataProvider.get([0, 1]);
this._listView.validateNow();
var itemRenderer = cast(this._listView.itemToItemRenderer(item), ItemRenderer);
var dispatchedTriggerCount = 0;
this._listView.addEventListener(GroupListViewEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(2, event.state.location.length);
Assert.equals(0, event.state.location[0]);
Assert.equals(1, event.state.location[1]);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromTouchEvent(itemRenderer, new TouchEvent(TouchEvent.TOUCH_TAP));
Assert.equals(1, dispatchedTriggerCount);
}
}

private class CustomRendererWithInterfaces extends LayoutGroup implements IToggle implements IDataRenderer implements ILayoutIndexObject
Expand Down
34 changes: 34 additions & 0 deletions test/src/feathers/controls/ListViewTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package feathers.controls;

import openfl.events.TouchEvent;
import feathers.events.ListViewEvent;
import openfl.events.MouseEvent;
import feathers.events.TriggerEvent;
import openfl.errors.RangeError;
import feathers.controls.dataRenderers.IDataRenderer;
import feathers.controls.dataRenderers.IListViewItemRenderer;
Expand Down Expand Up @@ -869,6 +873,36 @@ class ListViewTest extends Test {
Assert.notNull(itemRenderer);
Assert.equals(customVariant2, itemRenderer.variant);
}

private function testDispatchItemTriggerFromMouseClick():Void {
this._listView.dataProvider = new ArrayCollection([{text: "One"}, {text: "Two"}, {text: "Three"}]);
var item = this._listView.dataProvider.get(1);
this._listView.validateNow();
var itemRenderer = cast(this._listView.itemToItemRenderer(item), ItemRenderer);
var dispatchedTriggerCount = 0;
this._listView.addEventListener(ListViewEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(event.state.index, 1);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromMouseEvent(itemRenderer, new MouseEvent(MouseEvent.CLICK));
Assert.equals(1, dispatchedTriggerCount);
}

private function testDispatchItemTriggerFromTouchTap():Void {
this._listView.dataProvider = new ArrayCollection([{text: "One"}, {text: "Two"}, {text: "Three"}]);
var item = this._listView.dataProvider.get(1);
this._listView.validateNow();
var itemRenderer = cast(this._listView.itemToItemRenderer(item), ItemRenderer);
var dispatchedTriggerCount = 0;
this._listView.addEventListener(ListViewEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(event.state.index, 1);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromTouchEvent(itemRenderer, new TouchEvent(TouchEvent.TOUCH_TAP));
Assert.equals(1, dispatchedTriggerCount);
}
}

private class CustomRendererWithInterfaces extends LayoutGroup implements IToggle implements IDataRenderer implements ILayoutIndexObject
Expand Down
34 changes: 34 additions & 0 deletions test/src/feathers/controls/TabBarTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package feathers.controls;

import openfl.events.TouchEvent;
import feathers.events.TriggerEvent;
import openfl.events.MouseEvent;
import feathers.events.TabBarEvent;
import openfl.errors.RangeError;
import feathers.controls.dataRenderers.IDataRenderer;
import feathers.data.ArrayCollection;
Expand Down Expand Up @@ -738,6 +742,36 @@ class TabBarTest extends Test {
Assert.notNull(tab);
Assert.equals(customVariant2, tab.variant);
}

private function testDispatchItemTriggerFromMouseClick():Void {
this._tabBar.dataProvider = new ArrayCollection([{text: "One"}, {text: "Two"}, {text: "Three"}]);
var item = this._tabBar.dataProvider.get(1);
this._tabBar.validateNow();
var tab = cast(this._tabBar.itemToTab(item), ToggleButton);
var dispatchedTriggerCount = 0;
this._tabBar.addEventListener(TabBarEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(event.state.index, 1);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromMouseEvent(tab, new MouseEvent(MouseEvent.CLICK));
Assert.equals(1, dispatchedTriggerCount);
}

private function testDispatchItemTriggerFromTouchTap():Void {
this._tabBar.dataProvider = new ArrayCollection([{text: "One"}, {text: "Two"}, {text: "Three"}]);
var item = this._tabBar.dataProvider.get(1);
this._tabBar.validateNow();
var tab = cast(this._tabBar.itemToTab(item), ToggleButton);
var dispatchedTriggerCount = 0;
this._tabBar.addEventListener(TabBarEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(event.state.index, 1);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromTouchEvent(tab, new TouchEvent(TouchEvent.TOUCH_TAP));
Assert.equals(1, dispatchedTriggerCount);
}
}

private class CustomRendererWithInterfaces extends ToggleButton implements IDataRenderer implements ILayoutIndexObject {
Expand Down
47 changes: 47 additions & 0 deletions test/src/feathers/controls/TreeGridViewTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package feathers.controls;

import openfl.events.MouseEvent;
import feathers.events.TriggerEvent;
import openfl.events.TouchEvent;
import feathers.events.TreeGridViewEvent;
import openfl.errors.RangeError;
import feathers.data.TreeGridViewCellState;
import feathers.controls.dataRenderers.HierarchicalItemRenderer;
Expand Down Expand Up @@ -883,6 +887,49 @@ import utest.Test;
Assert.equals(0, itemRenderer2.parent.getChildIndex(itemRenderer2));
Assert.equals(1, itemRenderer1.parent.getChildIndex(itemRenderer1));
}

private function testDispatchItemTriggerFromMouseClick():Void {
var item1 = {a: "A0-a"};
var item2 = {a: "A0-b"};
var item3 = {a: "A0-c"};
var branch = {a: "A0", children: [item1, item2, item3]};
this._treeGridView.dataProvider = new ArrayHierarchicalCollection([branch, {a: "A1"}], (item:Dynamic) -> item.children);
this._treeGridView.columns = new ArrayCollection([new TreeGridViewColumn("A", item -> item.a)]);
var item = this._treeGridView.dataProvider.get([1]);
var column = this._treeGridView.columns.get(0);
this._treeGridView.validateNow();
var itemRenderer = cast(this._treeGridView.itemAndColumnToCellRenderer(item, column), HierarchicalItemRenderer);
var dispatchedTriggerCount = 0;
this._treeGridView.addEventListener(TreeGridViewEvent.CELL_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(1, event.state.rowLocation.length);
Assert.equals(1, event.state.rowLocation[0]);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromMouseEvent(itemRenderer, new MouseEvent(MouseEvent.CLICK));
Assert.equals(1, dispatchedTriggerCount);
}

private function testDispatchItemTriggerFromTouchTap():Void {
this._treeGridView.dataProvider = new ArrayHierarchicalCollection([
{text: "A", children: [{text: "One"}, {text: "Two"}, {text: "Three"}]},
{text: "B"}
], (item:Dynamic) -> item.children);
this._treeGridView.columns = new ArrayCollection([new TreeGridViewColumn("A", item -> item.a)]);
var item = this._treeGridView.dataProvider.get([1]);
var column = this._treeGridView.columns.get(0);
this._treeGridView.validateNow();
var itemRenderer = cast(this._treeGridView.itemAndColumnToCellRenderer(item, column), HierarchicalItemRenderer);
var dispatchedTriggerCount = 0;
this._treeGridView.addEventListener(TreeGridViewEvent.CELL_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(1, event.state.rowLocation.length);
Assert.equals(1, event.state.rowLocation[0]);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromTouchEvent(itemRenderer, new TouchEvent(TouchEvent.TOUCH_TAP));
Assert.equals(1, dispatchedTriggerCount);
}
}

private class CustomRendererWithInterfaces extends LayoutGroup implements IToggle implements IOpenCloseToggle implements IDataRenderer
Expand Down
42 changes: 42 additions & 0 deletions test/src/feathers/controls/TreeViewTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package feathers.controls;

import feathers.events.TriggerEvent;
import openfl.events.TouchEvent;
import openfl.events.MouseEvent;
import feathers.events.TreeViewEvent;
import openfl.errors.RangeError;
import feathers.controls.dataRenderers.HierarchicalItemRenderer;
import feathers.controls.dataRenderers.IDataRenderer;
Expand Down Expand Up @@ -792,6 +796,44 @@ import utest.Test;
Assert.notNull(itemRenderer);
Assert.equals(customVariant2, itemRenderer.variant);
}

private function testDispatchItemTriggerFromMouseClick():Void {
this._treeView.dataProvider = new ArrayHierarchicalCollection([
{text: "A", children: [{text: "One"}, {text: "Two"}, {text: "Three"}]},
{text: "B"}
], (item:Dynamic) -> item.children);
var item = this._treeView.dataProvider.get([1]);
this._treeView.validateNow();
var itemRenderer = cast(this._treeView.itemToItemRenderer(item), HierarchicalItemRenderer);
var dispatchedTriggerCount = 0;
this._treeView.addEventListener(TreeViewEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(1, event.state.location.length);
Assert.equals(1, event.state.location[0]);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromMouseEvent(itemRenderer, new MouseEvent(MouseEvent.CLICK));
Assert.equals(1, dispatchedTriggerCount);
}

private function testDispatchItemTriggerFromTouchTap():Void {
this._treeView.dataProvider = new ArrayHierarchicalCollection([
{text: "A", children: [{text: "One"}, {text: "Two"}, {text: "Three"}]},
{text: "B"}
], (item:Dynamic) -> item.children);
var item = this._treeView.dataProvider.get([1]);
this._treeView.validateNow();
var itemRenderer = cast(this._treeView.itemToItemRenderer(item), HierarchicalItemRenderer);
var dispatchedTriggerCount = 0;
this._treeView.addEventListener(TreeViewEvent.ITEM_TRIGGER, event -> {
dispatchedTriggerCount++;
Assert.equals(1, event.state.location.length);
Assert.equals(1, event.state.location[0]);
});
Assert.equals(0, dispatchedTriggerCount);
TriggerEvent.dispatchFromTouchEvent(itemRenderer, new TouchEvent(TouchEvent.TOUCH_TAP));
Assert.equals(1, dispatchedTriggerCount);
}
}

private class CustomRendererWithInterfaces extends LayoutGroup implements IToggle implements IOpenCloseToggle implements IDataRenderer
Expand Down

0 comments on commit 50bfc07

Please sign in to comment.