Skip to main content

Test Conditional Appearance Rules

  • 2 minutes to read

The EasyTest functional testing framework allows you to test Conditional Appearance rules. This topic demonstrates how to implement such tests.

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e3250/how-to-test-conditional-appearance-rules.

To see beginner’s step-by-step testing instructions, refer to the Test an Action topic.

Suppose you have the MyPerson persistent object that exposes the Name, IsMarried and SpouseName properties. The requirement is that the SpouseName property’s editor is disabled when IsMarried is false. To do this, apply the AppearanceAttribute to the SpouseName property:

using DevExpress.ExpressApp.ConditionalAppearance;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
// ...
[DefaultClassOptions]
public class MyPerson : BaseObject {
    public MyPerson(Session session) : base(session) { }

    private string name;
    public string Name {
        get => name;
        set => SetPropertyValue(nameof(Name), ref name, value);
    }

    private bool isMarried;
    [ImmediatePostData]
    public bool IsMarried {
        get => isMarried;
        set {
            SetPropertyValue(nameof(IsMarried), ref isMarried, value);
            if (!string.IsNullOrEmpty(SpouseName) && !value) SpouseName = string.Empty;
        }
    }

    private string spouseName;
    [Appearance("DisableSpouseName", Criteria = "!IsMarried", Enabled = false)]
    public string SpouseName {
        get => spouseName;
        set => SetPropertyValue(nameof(SpouseName), ref spouseName, value);
    }
}

TestConditionalAppearanceRules

To test the MyPerson object’s Conditional Appearance rule, you can use the following EasyTest script.

;#DropDB MySolutionEasyTest

#Application MySolutionWin
#Application MySolutionWeb
#Application MySolutionBlazor

*Action Navigation(Person)

*Action New

;Set IsMarried to true
*FillForm
 Name = Jane Smith
 Is Married = true

;Test that the SpouseName field is editable
*FillForm
 Spouse Name = John Smith

;Set IsMarried to false
*FillForm
 Is Married = false

;Test that the SpouseName field is not editable
!FillForm
 Spouse Name = John Smith

Note

EasyTest supports only test visibility and an enabled/disabled state.

See Also