Get help with testing, discuss unit testing strategies etc.


Post by AaronTovo »

I have a global variable, TR, that specifies a bunch of strings as part of our localization scheme. This variable is served up in a jsp template and looks something like
    <script type="text/javascript">
        TR = {
            AccessionEmptyText: '<spring:message code="home.AccessionEmptyText" javaScriptEscape="true"/>',
            AccessionNumber: '<spring:message code="home.AccessionNumber" javaScriptEscape="true"/>',
              ...
            WeeksAbbreviation: '<spring:message code="home.WeeksAbbreviation" javaScriptEscape="true"/>',
            YearsAbbreviation: '<spring:message code="home.YearsAbbreviation" javaScriptEscape="true"/>'
        }
    </script>
where there are dozens more members in the place of the "...".

The problem I'm encountering is that this variable does not appear in the scope of the tests. So that the following test fails because TR is an undefined reference.
StartTest(function(t) {
    t.ok(Ext, 'ExtJS is here');
    t.ok(this.global.TR, 'TR strings are here');
})
How can I access such a global from within a test?

Post by jakub »

I'm not an expert in Siesta so we will probably have to wait for Nickolay, but knowing that each test is run in a separate iframe, your variable is not present in it's scope. Will you be able to inlcude your files in the preload config of the Harness file ? : https://bryntum.com/products/siesta/docs ... fg-preload
JavaScript/Angular/ExtJS consulting - kuba@virtualdesign.pl

Post by mats »

You can look at the hostPageURL option, if you want your test to be launched in a JSP page. Then the scope will be correctly set and you can access all your globals etc.

Post by nickolay »

Double check you have the file with TR definitions in the preloads?

Also no need to use "this.global.TR" - test code is executed on the test page, it can access the globals directly:
    StartTest(function(t) {
        t.ok(Ext, 'ExtJS is here');
        t.ok(typeof TR != 'undefined', 'TR strings are here');
    })

Post by AaronTovo »

hostPageURL did the trick.

I noticed that I can add hostPageURL to the Harness.configure config and it will apply to all tests, but I don't see that in the documentation at https://www.bryntum.com/products/siesta/ ... -configure. Is that safe to do?

Post by AaronTovo »

Interesting...

Now I see the entire siesta test results page showing up in the test's iframe/viewer.

https://d.pr/i/t08u
If I try to render my own components, with view.render(Ext.getBody()), they get combined with this nested siesta page.

This has echoes of an earlier problem I encountered: https://forum.bryntum.com/viewtopic.php?t=1984

Here is my index.js file:
var Harness = Siesta.Harness.Browser.ExtJS;

Harness.configure({
    title       : 'Awesome Test Suite',
    loaderPath  : { 'StudySearch' : 'study-search' },
    waitForAppReady: false,
    expectedGlobals: [
        'Ext',
        'VI',
        'TR'
    ],
    preload     : [
        "siesta-test/lib/ext4/resources/vitaltheme/css/vitaltheme.css",
        "siesta-test/lib/ext4/ext-all-debug.js",
        "siesta-test/lib/ext4/locale/ext-lang-en.js",
        "study-search/Utils.js"
    ]
});

Harness.start(
    {
        hostPageUrl: 'siesta',
        url: 'siesta-test/010_sanity.t.js'
    },
    'siesta-test/020_basic.t.js',
    {
        hostPageUrl: 'siesta',
        url: 'siesta-test/030_archive.t.js'
    }
);

Post by nickolay »

AaronTovo wrote:hostPageURL did the trick.

I noticed that I can add hostPageURL to the Harness.configure config and it will apply to all tests, but I don't see that in the documentation at https://www.bryntum.com/products/siesta/ ... -configure. Is that safe to do?
Yes, its safe. By default, all options are for Harness.configure call, and only those explicitly marked (most of them anyway) are available in test file descriptors.
AaronTovo wrote:Interesting...

Now I see the entire siesta test results page showing up in the test's iframe/viewer.

https://d.pr/i/t08u
If I try to render my own components, with view.render(Ext.getBody()), they get combined with this nested siesta page.

This has echoes of an earlier problem I encountered: https://forum.bryntum.com/viewtopic.php?t=1984
In that thread, it seems you have siesta files included on your application page - thats why it tries to render the UI. Try removing them.
    <%@ taglib prefix="c" uri="https://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="spring" uri="https://www.springframework.org/tags" %>
    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <spring:message var="builddate" code="build.date" />

    <!DOCTYPE HTML>
    <html>
    <head>
        ...
        <!-- No need to include these files ->
        <script type="text/javascript" src="siesta-test/lib/siesta-1.0.8-lite/siesta-all.js"></script>

        <script type="text/javascript" src="siesta-test/index.js"></script>   
        ...
    </head>
    <body>
    </body>
    </html>


Post by AaronTovo »

oh, of course, I was loading both my app and the siesta page with the same jsp file.

I've separated them so that they are loaded separately. Now I see only the app displayed in that viewer. I'm getting a couple of 'undefined' errors but I think that's due to something else.

Thanks.

Post Reply