Docs Help

Terms, Icons, and Labels

Many classes have shortcut names used when creating (instantiating) a class with a configuration object. The shortcut name is referred to as an alias (or xtype if the class extends Ext.Component). The alias/xtype is listed next to the class name of applicable classes for quick reference.

Access Levels

Framework classes or their members may be specified as private or protected. Else, the class / member is public. Public, protected, and private are access descriptors used to convey how and when the class or class member should be used.

Member Types

Member Syntax

Below is an example class member that we can disect to show the syntax of a class member (the lookupComponent method as viewed from the Ext.button.Button class in this case).

lookupComponent ( item ) : Ext.Component
protected

Called when a raw config object is added to this container either during initialization of the items config, or when new items are added), or {@link #insert inserted.

This method converts the passed object into an instanced child component.

This may be overridden in subclasses when special processing needs to be applied to child creation.

Parameters

item :  Object

The config object being added.

Returns
Ext.Component

The component to be added.

Let's look at each part of the member row:

Member Flags

The API documentation uses a number of flags to further commnicate the class member's function and intent. The label may be represented by a text label, an abbreviation, or an icon.

Class Icons

- Indicates a framework class

- A singleton framework class. *See the singleton flag for more information

- A component-type framework class (any class within the Ext JS framework that extends Ext.Component)

- Indicates that the class, member, or guide is new in the currently viewed version

Member Icons

- Indicates a class member of type config

- Indicates a class member of type property

- Indicates a class member of type method

- Indicates a class member of type event

- Indicates a class member of type theme variable

- Indicates a class member of type theme mixin

- Indicates that the class, member, or guide is new in the currently viewed version

Class Member Quick-Nav Menu

Just below the class name on an API doc page is a row of buttons corresponding to the types of members owned by the current class. Each button shows a count of members by type (this count is updated as filters are applied). Clicking the button will navigate you to that member section. Hovering over the member-type button will reveal a popup menu of all members of that type for quick navigation.

Getter and Setter Methods

Getting and setter methods that correlate to a class config option will show up in the methods section as well as in the configs section of both the API doc and the member-type menus just beneath the config they work with. The getter and setter method documentation will be found in the config row for easy reference.

History Bar

Your page history is kept in localstorage and displayed (using the available real estate) just below the top title bar. By default, the only search results shown are the pages matching the product / version you're currently viewing. You can expand what is displayed by clicking on the button on the right-hand side of the history bar and choosing the "All" radio option. This will show all recent pages in the history bar for all products / versions.

Within the history config menu you will also see a listing of your recent page visits. The results are filtered by the "Current Product / Version" and "All" radio options. Clicking on the button will clear the history bar as well as the history kept in local storage.

If "All" is selected in the history config menu the checkbox option for "Show product details in the history bar" will be enabled. When checked, the product/version for each historic page will show alongside the page name in the history bar. Hovering the cursor over the page names in the history bar will also show the product/version as a tooltip.

Search and Filters

Both API docs and guides can be searched for using the search field at the top of the page.

On API doc pages there is also a filter input field that filters the member rows using the filter string. In addition to filtering by string you can filter the class members by access level, inheritance, and read only. This is done using the checkboxes at the top of the page.

The checkbox at the bottom of the API class navigation tree filters the class list to include or exclude private classes.

Clicking on an empty search field will show your last 10 searches for quick navigation.

API Doc Class Metadata

Each API doc page (with the exception of Javascript primitives pages) has a menu view of metadata relating to that class. This metadata view will have one or more of the following:

Expanding and Collapsing Examples and Class Members

Runnable examples (Fiddles) are expanded on a page by default. You can collapse and expand example code blocks individually using the arrow on the top-left of the code block. You can also toggle the collapse state of all examples using the toggle button on the top-right of the page. The toggle-all state will be remembered between page loads.

Class members are collapsed on a page by default. You can expand and collapse members using the arrow icon on the left of the member row or globally using the expand / collapse all toggle button top-right.

Desktop -vs- Mobile View

Viewing the docs on narrower screens or browsers will result in a view optimized for a smaller form factor. The primary differences between the desktop and "mobile" view are:

Viewing the Class Source

The class source can be viewed by clicking on the class name at the top of an API doc page. The source for class members can be viewed by clicking on the "view source" link on the right-hand side of the member row.

Sencha Test 2.4.0


top

Testing Ext JS Applications

End-to-End Testing

If you have an existing Ext JS application published that you wish to perform end-to-end testing on (where the entire app is launched, and tested from an end-user's perspective), follow the steps below to get your project set up in Sencha Studio, and start writing some tests.

  1. Open Sencha Studio, and create a new Project. Define the URL where you have your Ext JS app running, for example, http://examples.sencha.com/extjs/latest/examples/admin-dashboard/.

    • Name: Name of the project, for example AdminDashboard
    • Path: Where the project will be created. Scenarios and test suite files will be added in this location.
    • URL: Web address for the running web app, for example http://examples.sencha.com/extjs/latest/examples/admin-dashboard/.
  2. Once the project has been created, you will be able to click on the "New Scenario" button to create a scenario that will hold your test suite files.

    • Name: A name for the scenario, for example if you are creating end-to-end tests, you could call the scenario EndToEnd
    • Test type: Selecting WebDriver will run your tests separately from the browser. This is suitable for end-to-end testing. If you have the Test Engineer persona selected in Sencha Studio, this option will be hidden, and new scenarios will default to WebDriver type.
  3. After the scenario has been created, select the scenario in the tree, then click the "New Test Suite" button >> select "Jasmine Test Suite" from the menu. Enter a name for the test suite, for example Dashboard. This creates a new Jasmine test suite file. The .js file extension gets added automatically.

  4. With the new test suite loaded in the editor, you can now begin writing your tests. You can leverage the Event Recorder to capture a set of actions for insertion in to your test suite, or write code using the Futures APIs. You can also leverage the Inspect tool to help you create locators for elements.

Unit Testing

Sencha Studio allows developers to quickly and automatically test granular aspects of an Ext JS application or web page. Unit testing ensures that all of the pieces of your application behave as anticipated as your codebase grows and changes.

In the steps below, we're going to walk through generating a new application and setting up a test environment, creating a testable application class, and testing said class with a custom unit test. All of these things can be done directly in Sencha Studio.

These steps assume some familiarity with the Jasmine test framework. If you are unfamiliar with Jasmine or test concepts, check out their excellent documentation for more information on authoring and editing Jasmine tests. This guide also makes use of Sencha Cmd to generate an Ext JS application and assumes you have downloaded / installed them.

Let's get started!

Generating a Project

We'll begin by opening Sencha Studio.

You can generate your required workspace with Sencha Studio by choosing the following from the application toolbar:

Sencha Studio -> New Project

Select the appropriate file system path, select where the Ext JS framework resides, and click "OK".

Adding a Testable Class

The starter application has very little functionality, so let's add something that we can test. For our purposes, let's create a WindowEditor class at MyApp/app/view/main/WindowEditor.js using the IDE of your choice. You can use this code to follow along:

Ext.define('MyApp.view.main.WindowEditor', {
   extend: 'Ext.Window',

   alias: 'widget.windoweditor',

   width:400,
   height:200,
   padding:20,

   autoShow: true,

   title: 'Update Email',

   items: [{
       xtype: 'form',
       items: [{
           xtype: 'textfield',
           allowBlank: false,
           vtype: 'email'
       },{
           xtype: 'button',
           text: 'Submit Change',
           formBind: true
       }]
   }]
});

This class extends a window that contains a form, which in turn, contains a textfield and a button. We've instructed the textfield that we will not allow a blank value, and that any input must pass email validation.

Additionally, we've set formBind true on the button. This instructs the button to remain in a disabled state until the form considers itself valid. Once valid, the button will change to a clickable state.

You can then replace MyApp/app/view/main/MainController.js's onItemSelected method with the following:

onItemSelected: function (sender, record) {
    Ext.create('MyApp.view.main.WindowEditor');
}

This will open a faux email-editor for our grid. You really don't need to modify this controller code to create the upcoming test in Sencha Studio. That said, you'll find that your application's creation logic often runs parallel to the code you'll end up writing in your test spec.

We'll eventually use this class to test whether or not the button is successfully enabled/disabled as the text input satisfies our prescribed validation.

Note: This "editor" doesn't really do anything at this point, but it should serve our purposes for testing demonstration.

Initializing a Test Project

Let's get our project settings added by clicking on the application's "Tests" node. Then click "Initialize Test Project" in the right-hand details panel. Upon clicking, you should see a few Project Settings. We shouldn't need to change anything at this time. However, if you do modify any of the settings, be sure to click "Save" before proceeding.

Next, let's add an application scenario.

Adding a Scenario

A test project must contain a “Scenario” in order to add a suite of test specs.

Scenario - Scenarios house the test suites that you will soon create.

To create a scenario, click the "Add Scenario" button. You can then change the name and file system location of the Scenario. Typically, you'll want to name your Scenario based on the content you'll be testing. In this case, let's call it "WindowEditor". You also want to select the Scenario type (either WebDriver or In-Browser). Select "In-Browser" for unit tests. Once added, make sure to click "Save". We can now begin adding a suite of test specs to our scenario.

Adding a Suite

You should now see “WindowEditor” as a child of the "Tests" node. Go ahead and click on that node, and you should see your local browsers and a panel that says "No tests found". Let's change that!

Let's add a Jasmine Test Suite.

Suite - A suite is a file containing a collection of tests that represent some aspect of your application. This could be a class, a component, or a grouping of functions. It really depends on how you choose to organize your test suites.

With the scenario selected, click the "New Test Suite" button and select "Jasmine Test Suite" from the menu. A modal window will then pop up that allows you to give your Suite a name. Let's call it "WindowValidation".

Once added, you should then see a "WindowValidation.js" file under "WindowEditor". Click the new file and you'll see some stubbed in suite code to get your started.

describe("my test suite", function() {
    it("should pass", function() {
        expect(1).toBe(1);
    });
});

Our stubbed in suite code isn't very helpful in its current form, so let's go ahead and add a spec to our suite.

Adding a Spec

Spec - A spec is an individual test in the form of a JavaScript function that explains what a portion of your program should accomplish. We should explain in plain language what the test is expecting. It should then provide JavaScript that performs the tests for said expectation.

It's important to note that many times your test may parallel many aspects of your application code in terms of creating classes and obtaining references to components.

For the time being, go ahead and paste the following suite into your WindowEditor.js file and press "Save":

describe("formBind true", function() {
    it("should disable button if email is not valid", function(done) {

        // Create and reference the WindowEditor and then 
        // get reference to the button and textfield
        var win = Ext.create('MyApp.view.main.WindowEditor'),
            button = win.down('button'),      
            field  = win.down('textfield');

        // Set the field's value to a valid email address
        // in order to have the button fire an enable event
        field.setValue('[email protected]');

        button.on('enable', function() {

            // Set the field's value to an invalid email address (nothing)
            // in order to have the button fire a disable event
            field.setValue('');

            button.on('disable', function() {

                //  Once the disable event has been called after setting a 
                //  bad value, we can safely say that the button is properly 
                //  hooked into the form's validity.  Thusly, we can 
                //  alert the spec to return by calling the done function.
                done();    
            });
        });
    });
});

As you can see, we're testing that the button's state correctly follows the form's validity. If the textfield contains a valid value, the form is valid, and the button should be enabled. Conversely, if the textfield contains an invalid value, the form is invalid, and the button should be disabled. This behavior all takes place due to the button's formBind config being set to true.

We are able to test that these conditions are properly met by listening to the button's enable/disable events. If button fires "enable", we know that the form has become valid. If the button fires the "disable" event, we know that the form has become invalid. At that point, we can be satisfied that the test was successful and then call Jasmine's done() function.

In many cases, you would use an expectation to ensure the results meet your postulation. An expectation is built with the expect function, which takes a value, called the actual. It is then chained to a Matcher function which takes the expected value. This determines true/false, or, in other words, pass/fail.

That said, we don't necessarily have to use an expectation in this case. The done() function is passed to the it() method as an argument. We can use done() by simply calling it when we determine the processing to be complete. Generally, done() will be called as a "success" callback when dealing with asynchronous testing. However, we can use it here instead of setting an expectation. By virtue of reaching the final event, we know that we've satisfied our test, so there is no need for an expectation. If the final event is never fired, done() will not be called, and the test will timeout after 5 seconds, indicating a failure.

Now that we have a test case, let's run it and ensure that our application's editor is successfully measuring our form's validity.

Running the Test

Now that we have our test connected, let's walk through running it via a local browser.

First, select the "WindowEditor" scenario node from the Workspace navigation view to display the scenario's test runner tab. Next, select your browser(s) of choice from the left hand Browsers pane in the test runner tab. For our purposes, we'll select Chrome.
Once selected, you'll see your selected browser(s) open your connected application.

Note: If "sencha app watch" is initializing, you'll see a yellow eye icon next to the application node. Your browser will not open until the eye turns black, signifying that "app watch" has initialized.

Select "WindowValidation.js" from the WindowEditor Test Runner and click "Run Selection" from the top toolbar. If all goes well, you should receive a green checkbox indicating that the test has successfully passed.

It may be useful to see what happens if the test fails as well, so let's force that to occur by changing our test case.

Replace the following line:

// Set the field's value to a valid email address
// in order to have the button fire an enable event
field.setValue('[email protected]');

with this code:

field.setValue('');

As you can imagine, this change will cause the textfield value to remain invalid, meaning the button's enable event will never fire and we'll never call done(). After 5 seconds, the test will determine itself failed and timeout.

Save your spec and re-run the selection. This time you should see a red "1". This indicates that one spec failed. If you expand WindowValidation.js, and then expand formBind true, you'll see our spec with a red "x" next to it. If you click on the red "x", you can then review a summary of the error in the lower summary panel.

Conclusion

As you may imagine, this guide only scratches the surface of what can be done with Sencha Test by way of Sencha Studio. Hopefully, this introduction provides you with the knowledge you'll need to navigate through and discover the many powerful tools contained within Sencha Studio.

If you have further questions, concerns, or bug reports, please visit the Sencha Test forums.

Sencha Test 2.4.0