Exemple #1
0
        public void RadioButtonTest()
        {
            string value    = null;
            string selected = null;

            var app = new RadioButtonApp(new RadioButtonAppProps
            {
                OnValueSet     = v => value = v,
                OnSelectionSet = v => selected = v,
                Items          = { "Foo", "Bar", "Gra", "Hoh" }
            });

            TestUIDriver driver = new TestUIDriver(app);

            driver.Press(Buttons.DPadRight);
            driver.Press(Buttons.A);

            value.Should().Be("Bar");
            selected.Should().Be("Bar");

            driver.Press(Buttons.DPadRight);

            value.Should().Be("Bar");
            selected.Should().Be("Gra");
        }
Exemple #2
0
        public void SkipDisabledMenuItems()
        {
            var menu = new Window(new WindowProps
            {
                Children =
                {
                    new Window(new WindowProps
                    {
                        Children =
                        {
                            new Button(new ButtonProps {
                                Text = "Hello"
                            }),
                            new Button(new ButtonProps {
                                Text = "Some"
                            }),
                            new Button(new ButtonProps {
                                Text = "Items", Enabled = false,
                            }),
                            new Button(new ButtonProps {
                                Text = "Are"
                            }),
                            new Button(new ButtonProps {
                                Text = "Disabled", Enabled = false
                            }),
                        }
                    }),
                    new Window(new WindowProps
                    {
                        Children =
                        {
                            new Button(new ButtonProps {
                                Text = "Testing if we"
                            }),
                            new Button(new ButtonProps {
                                Text = "Can navigate out"
                            }),
                            new Button(new ButtonProps {
                                Text = "of a menu who's last"
                            }),
                            new Button(new ButtonProps {
                                Text = "item is disabled."
                            }),
                        }
                    })
                }
            });

            TestUIDriver driver = new TestUIDriver(menu);

            driver.Press(Buttons.DPadDown);
            FocusItemHasText(driver, "Some");

            driver.Press(Buttons.DPadDown);
            FocusItemHasText(driver, "Are");

            driver.Press(Buttons.DPadDown);
            FocusItemHasText(driver, "Testing if we");
        }
        public void RowSingleChildFixedWidthSecondChildResized(int mainWidth, int leftWidth)
        {
            ElementReference fixedLabel = new ElementReference();
            ElementReference fillLabel  = new ElementReference();

            Window box = new Window(new WindowProps
            {
                Name  = "thewindow",
                Style = new InlineElementStyle
                {
                    Flex = new FlexStyle
                    {
                        Direction  = FlexDirection.Row,
                        AlignItems = AlignItems.Stretch,
                    },
                    Size = new SizeConstraints
                    {
                        MinWidth  = mainWidth,
                        MaxWidth  = mainWidth,
                        MinHeight = 400,
                        MaxHeight = 400,
                    }
                },
                Children =
                {
                    new Label(new LabelProps
                    {
                        Style = new InlineElementStyle
                        {
                            Size = new SizeConstraints
                            {
                                MinWidth = leftWidth,
                                MaxWidth = leftWidth,
                            }
                        },
                        Text = $"This is a fixed size label. It will only be {leftWidth} pixels wide.",
                        Ref  = fixedLabel,
                    }),
                    new Label(new LabelProps
                    {
                        Text = "This is some really long text that should be forced to wrap. There should be some extra juicy details in this text string that will require wrapping for the user to enjoy reading them.",
                        Ref  = fillLabel,
                    }),
                }
            });

            TestUIDriver driver = new TestUIDriver(CreateApp(box),
                                                   styleConfigurator,
                                                   contentLayoutEngine: contentLayoutEngine);

            driver.DoLayout();

            fixedLabel.Current.Display.ContentRect.Should().Be(new Rectangle(0, 0, leftWidth, 400));
            fillLabel.Current.Display.ContentRect.Should().Be(new Rectangle(leftWidth, 0, mainWidth - leftWidth, 400));
        }
Exemple #4
0
        public void DoubleRadiosEnabledAfterSelectingBoth()
        {
            var app = new DoubleRadioMenusApp(new DoubleRadioMenusProps
            {
                LeftItems = new[]
                {
                    new ItemData {
                        Name = "Foo", Description = "Food is good for you."
                    },
                    new ItemData {
                        Name = "Bar", Description = "Bars serve drinks."
                    },
                    new ItemData {
                        Name = "Gra", Description = "Gra is a nonsense word."
                    },
                    new ItemData {
                        Name = "Hoh", Description = "Hoh is one letter short."
                    },
                },
                RightItems = new[]
                {
                    new ItemData {
                        Name = "MegaFoo", Description = "Food is good for you."
                    },
                    new ItemData {
                        Name = "MegaBar", Description = "Bars serve drinks."
                    },
                    new ItemData {
                        Name = "MegaGra", Description = "Gra is a nonsense word."
                    },
                    new ItemData {
                        Name = "MegaHoh", Description = "Hoh is one letter short."
                    },
                },
            });

            TestUIDriver driver = new TestUIDriver(app);

            driver.Press(Buttons.A);
            driver.Press(Buttons.DPadRight);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.A);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);

            app.SelectedLeft.Name.Should().Be("Foo");
            app.SelectedRight.Name.Should().Be("MegaGra");

            driver.Focus.Should().BeOfType(typeof(ButtonElement));
        }
Exemple #5
0
        public void DoubleRadiosAcceptDisabledByDefault()
        {
            var app = new DoubleRadioMenusApp(new DoubleRadioMenusProps
            {
                LeftItems = new[]
                {
                    new ItemData {
                        Name = "Foo", Description = "Food is good for you."
                    },
                    new ItemData {
                        Name = "Bar", Description = "Bars serve drinks."
                    },
                    new ItemData {
                        Name = "Gra", Description = "Gra is a nonsense word."
                    },
                    new ItemData {
                        Name = "Hoh", Description = "Hoh is one letter short."
                    },
                },
                RightItems = new[]
                {
                    new ItemData {
                        Name = "MegaFoo", Description = "Food is good for you."
                    },
                    new ItemData {
                        Name = "MegaBar", Description = "Bars serve drinks."
                    },
                    new ItemData {
                        Name = "MegaGra", Description = "Gra is a nonsense word."
                    },
                    new ItemData {
                        Name = "MegaHoh", Description = "Hoh is one letter short."
                    },
                },
            });

            TestUIDriver driver = new TestUIDriver(app);

            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);

            // This
            driver.Focus.Should().BeOfType(typeof(RadioButtonElement), "we shouldn't have gotten to the accept button.");
        }
Exemple #6
0
        public void DisabledMenuItemsWontTriggerOnAccept()
        {
            int disabledCount = 0;

            var menu = new Window(new WindowProps
            {
                Children =
                {
                    new MenuEnableToggleComponent(new MenuEnableToggleComponentProps
                    {
                        OnMenuItemDisabled = e =>
                        {
                            if (disabledCount > 0)
                            {
                                throw new InvalidOperationException("OnAccept triggered for disabled menu item.");
                            }

                            disabledCount++;
                        },
                    }),
                    new Window(new WindowProps
                    {
                        Children =
                        {
                            new Button(new ButtonProps {
                                Text = "Testing if we"
                            }),
                            new Button(new ButtonProps {
                                Text = "Can navigate out"
                            }),
                            new Button(new ButtonProps {
                                Text = "of a menu who's last"
                            }),
                            new Button(new ButtonProps {
                                Text = "item is disabled."
                            }),
                        }
                    })
                }
            });

            TestUIDriver driver = new TestUIDriver(menu);

            driver.Press(Buttons.A);
            driver.Press(Buttons.A);

            disabledCount.Should().Be(1, "menu item's onaccept should only be called once.");
        }
Exemple #7
0
        public void MenuInputCancel()
        {
            bool canceled = false;

            var menu = new Window(new WindowProps
            {
                OnCancel = e => canceled = true,
                Children = { new Button(new ButtonProps {
                        Text = "Hello"
                    }) }
            });

            TestUIDriver driver = new TestUIDriver(menu);

            driver.Press(Buttons.B);

            canceled.Should().BeTrue("Menu did not exit when cancel was pressed.");
        }
Exemple #8
0
        public void DoubleRadiosDownAndBackUp()
        {
            ItemData selectedLeft  = null;
            ItemData selectedRight = null;
            bool     acceptFired   = false;

            var app = new DoubleRadioMenusApp(new DoubleRadioMenusProps
            {
                LeftItems = new[]
                {
                    new ItemData {
                        Name = "Foo", Description = "Food is good for you."
                    },
                    new ItemData {
                        Name = "Bar", Description = "Bars serve drinks."
                    },
                    new ItemData {
                        Name = "Gra", Description = "Gra is a nonsense word."
                    },
                    new ItemData {
                        Name = "Hoh", Description = "Hoh is one letter short."
                    },
                },
                RightItems = new[]
                {
                    new ItemData {
                        Name = "MegaFoo", Description = "Food is good for you."
                    },
                    new ItemData {
                        Name = "MegaBar", Description = "Bars serve drinks."
                    },
                    new ItemData {
                        Name = "MegaGra", Description = "Gra is a nonsense word."
                    },
                    new ItemData {
                        Name = "MegaHoh", Description = "Hoh is one letter short."
                    },
                },
                OnAccept = (left, right) =>
                {
                    acceptFired   = true;
                    selectedLeft  = left;
                    selectedRight = right;
                }
            });

            TestUIDriver driver = new TestUIDriver(app);

            driver.Press(Buttons.DPadRight);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.A);
            driver.Press(Buttons.DPadLeft);
            driver.Press(Buttons.A);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadDown);
            driver.Press(Buttons.DPadUp);
            driver.Press(Buttons.A);

            acceptFired.Should().BeFalse("accept event was not fired.");

            app.SelectedLeft.Name.Should().Be("Hoh");
            app.SelectedRight.Name.Should().Be("MegaGra");
        }
Exemple #9
0
 private static void FocusItemHasText(TestUIDriver driver, string text)
 {
     driver.Focus.Props.Should().BeOfType(typeof(ButtonElementProps));
     (driver.Focus.Props as ButtonElementProps).Text.Should().Be(text);
 }