Commit 9c4d1dd6 authored by Jérome Perrin's avatar Jérome Perrin

fixup! software/jstestnode: add json for instance parameters

This json schema was not finished ...
parent 69593b36
{ {
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"description": "Parameters to instantiate JSTestNode", "description": "Parameters to instantiate JSTestNode",
"additionalProperties": false, "additionalProperties": true,
"properties": { "common": {
"test-suite": { "test-suite": {
"description": "The test suite to run", "description": "The test suite to run",
"type": "string", "type": "string",
...@@ -17,19 +17,34 @@ ...@@ -17,19 +17,34 @@
"format": "uri", "format": "uri",
"default": "(the web server started by this instance)", "default": "(the web server started by this instance)",
"example": "https://softinst1234.host.vifib.net/" "example": "https://softinst1234.host.vifib.net/"
}
}, },
"oneOf": [ "oneOf": [
{ {
"title": "selenium server", "description": "Configuration for Selenium server",
"description": "Configuration for running tests on selenium server", "type": "object",
"additionalProperties": false,
"required": [
"desired-capabilities",
"server-url",
"target"
],
"properties": { "properties": {
"target": { "target": {
"description": "Target system", "description": "Target system",
"type": "string",
"const": "selenium-server" "const": "selenium-server"
}, },
"test-suite": {
"$ref": "#/common/test-suite"
},
"remote-access-url": {
"$ref": "#/common/remote-access-url"
},
"server-url": { "server-url": {
"description": "URL of the selenium server", "description": "URL of the selenium server",
"type": "string" "type": "string",
"format": "uri"
}, },
"verify-server-certificate": { "verify-server-certificate": {
"description": "Verify the SSL/TLS Certificats of the selenium server when using HTTPS", "description": "Verify the SSL/TLS Certificats of the selenium server when using HTTPS",
...@@ -43,43 +58,59 @@ ...@@ -43,43 +58,59 @@
}, },
"desired-capabilities": { "desired-capabilities": {
"description": "Desired browser capabilities", "description": "Desired browser capabilities",
"required": [
"browserName"
],
"type": "object", "type": "object",
"properties": { "properties": {
"browserName": { "browserName": {
"description": "Name of the browser being used, for example firefox, chrome", "description": "Name of the browser being used, for example firefox, chrome",
"type": "string", "type": "string"
"required": true
}, },
"version": { "version": {
"description": "The browser version", "description": "The browser version",
"type": "string" "type": "string"
} }
}, }
"additionalProperties": true
} }
} }
}, },
{ {
"title": "firefox", "description": "Configuration for Firefox",
"description": "Configuration for running tests on local firefox process", "type": "object",
"additionalProperties": false,
"properties": { "properties": {
"target": { "target": {
"description": "Target system", "description": "Target system",
"const": "firefox", "const": "firefox",
"type": "string",
"default": "firefox" "default": "firefox"
},
"test-suite": {
"$ref": "#/common/test-suite"
},
"remote-access-url": {
"$ref": "#/common/remote-access-url"
} }
} }
}, },
{ {
"title": "node", "description": "Configuration for NodeJS",
"description": "Configuration for running tests on local nodejs", "type": "object",
"additionalProperties": false,
"properties": { "properties": {
"target": { "target": {
"description": "Target system", "description": "Target system",
"const": "node" "const": "node",
"type": "string"
},
"test-suite": {
"$ref": "#/common/test-suite"
},
"remote-access-url": {
"$ref": "#/common/remote-access-url"
} }
} }
} }
] ]
}
} }
  • before i looked at this schema i had thought no schema could have oneOf/anyOf at the top level, that's why rjs_json_form renders only the first variant of oneOf/anyOf at the top level. Do i correctly understand:

    • that the properties indicated in oneOf are the target entity properties?
    • target, testsuit are the property of jstestnode entity?

    If both of the above statements are correct, then the choice of Firefox/Selenium/Nodejs is the choice of target type, isn't it? If this is true, then placing this choice at the same level as jstestnode is not logical.

    As i see the schema can be rewritten:

    • at the top level there are 2 properties - target and test-suite.
    • target has 3 oneOf items, every item has constant type

    @jerome , what do you think?

    Also I wonder if there's a way not to repeat the

    "test-suite": {
       "$ref": "#/common/test-suite"
    }, 

    i think the repetition can be avoided by:

    {
      "allOf": [
        {
          "properties": {
            "test-suite": {
              "description": "The test suite to run",
              "type": "string",
              "enum": [
                "jio",
                "renderjs"
              ]
            }
          }
        },
        {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": {
                  "type": "string",
                  "const": "selenium-server"
                }
              }
            }
          ]
        }
      ]
    }

    rjs_json_form supports any order and quantity of anyOf/oneOf/allOf enclosed in each other.

    [edit: fix misprint in example]

    Edited by Boris Kocherov
  • Thanks @bk . I'll try this again soon. I remember trying something similar but could not find the correct syntax. I also feel this is the correct approach.

    Sorry for not replying earlier. I really appreciated your feedback, I could not find the time to look into this seriously yet.

    PS I assume you meant allOf and not andOf. Or is it a recent json schema feature ?

  • PS I assume you meant allOf and not andOf. Or is it a recent json schema feature ?

    Sorry. Of couse i meant allOf.

  • @jerome , the fact that i didn't implement the anyOf/oneOf at the top level doesn't correspond to the specs. I did this on purpose because i think such schemes don't fit for visualization as forms. I think an user is accustomed to see the static set of fields on the top level and that fields can have arrays or properties with variable ('oneOf/anyOf') items, values. For example i think when user opens the Person for edit he expects to see the properties of Person, not a choice "edit Person or Organisation".

    Before rendering schema in form generator any quantity of anyOf/oneOf situated on the same level will be simplified to one anyOf even if some of anyOf/oneOf are inside of allOf. That's why the schema

    {
      "allOf": [
        {
          "properties": {
            "test-suite": {
              "description": "The test suite to run",
              "type": "string",
              "enum": [
                "jio",
                "renderjs"
              ]
            }
          }
        },
        {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": {
                  "type": "string",
                  "const": "selenium-server"
                }
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": {
                  "type": "string",
                  "const": "firefox"
                }
              }
            }
          ]
        }
      ]
    }

    will be simplified to:

    {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "test-suite": {
              "description": "The test suite to run",
              "type": "string",
              "enum": [
                "jio",
                "renderjs"
              ]
            },
            "type": {
              "type": "string",
              "const": "selenium-server"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "test-suite": {
              "description": "The test suite to run",
              "type": "string",
              "enum": [
                "jio",
                "renderjs"
              ]
            },
            "type": {
              "type": "string",
              "const": "firefox"
            }
          }
        }
      ]
    }

    So, there are 2 variants

    • make changes in your schema (this will invoke changes in the backend):
    • at the top level there are 2 properties - target and test-suite.
    • target has 3 oneOf items, every item has constant type
    • make changes in form generator, so it can render anyOf/oneOf at the top level.

    @jerome , what is your opinion?

  • Thanks @bk

    That's true that a "oneOf" at top level is a bit strange, for ERP5 we would first choose adding a person or organisation, for SlapOS we could use different "software types" for this (but we don't use much of this, I think that with testnode we can only request the default software).

    For other reasons (so that it uses the same test-runner key as ERP5), I was also considering at moving the oneOf to select the target down one level. If we have test-runner, instead of:

    {
        "remote-access-url": "http://localhost",
        "test-suite": "jio",
        "target": "firefox"
    }

    We would use

    {
        "remote-access-url": "http://localhost",
        "test-suite": "jio",
        "test-runner": {
            "target": "firefox"
        }
    }

    or

     {
        "remote-access-url": "http://localhost",
        "test-suite": "jio",
        "test-runner": {
            "target": "selenium-server",
            "server-url": "http://localhost",
            "verify-server-certificate": false,
            "desired-capabilities": {
                "browserName": "Firefox",
                "version": "52"
            }
        }
    }

    I tried quickly ( jerome/slapos@3ed2e7fe / https://codepen.io/perrinjerome/pen/RqGOWj ), but I could not get rjs_json_form show a list field for target type. I might be doing something wrong.

    At this point I can't say if we need to support top level oneOf/allOf, I still need to understand how to get it working at "non top level".

  • Hello @jerome , could you have a look at: https://codepen.io/bkrocherov/pen/MzbeRx There i changed the schema:

    • added titles for each of oneOf item
    • changed test-runner property - it's required
    • switched additionalProperties to False.

    The view of the schema at https://codepen.io/bkrocherov/pen/MzbeRx is one i expected. I don't find yet why we have differences in css, which broke the view and why clicking on empty space rises the exception.

  • Hello @jerome,

    i've found the cause why clicking on empty space rises the exception and have fixed it: bk/rjs_json_form@0c9057b2 .

    About css: it looks like this css is broken by template engine. Correct css can be :

  • Hello @bk

    A big "thank you" for all this !

    I don't think I ran grunt less this might be the issue with my CSS.

  • mentioned in merge request !425 (merged)

    Toggle commit list
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment