aboutsummaryrefslogtreecommitdiff
path: root/test/test-profile-conditions-util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-05-01 15:54:31 -0400
committerGitHub <noreply@github.com>2021-05-01 15:54:31 -0400
commitc514bbc4fbe39f611d7d9cfd3a48681bacbaf559 (patch)
tree275c792977b0c925fca67a324b036e1a81ba25dc /test/test-profile-conditions-util.js
parent8bf6ff92f9e318554139d3f21f1dcdb98ce59036 (diff)
Flags profile conditions (#1647)
* Generalize modifier keys * Optimize bindings * Add support for flags * Add clipboard flag * Update tests * Add tests
Diffstat (limited to 'test/test-profile-conditions-util.js')
-rw-r--r--test/test-profile-conditions-util.js270
1 files changed, 265 insertions, 5 deletions
diff --git a/test/test-profile-conditions-util.js b/test/test-profile-conditions-util.js
index ebc72be7..b77578de 100644
--- a/test/test-profile-conditions-util.js
+++ b/test/test-profile-conditions-util.js
@@ -40,25 +40,25 @@ function testNormalizeContext() {
// Empty
{
context: {},
- expected: {}
+ expected: {flags: []}
},
// Domain normalization
{
context: {url: ''},
- expected: {url: ''}
+ expected: {url: '', flags: []}
},
{
context: {url: 'http://example.com/'},
- expected: {url: 'http://example.com/', domain: 'example.com'}
+ expected: {url: 'http://example.com/', domain: 'example.com', flags: []}
},
{
context: {url: 'http://example.com:1234/'},
- expected: {url: 'http://example.com:1234/', domain: 'example.com'}
+ expected: {url: 'http://example.com:1234/', domain: 'example.com', flags: []}
},
{
context: {url: 'http://user@example.com:1234/'},
- expected: {url: 'http://user@example.com:1234/', domain: 'example.com'}
+ expected: {url: 'http://user@example.com:1234/', domain: 'example.com', flags: []}
}
];
@@ -611,6 +611,266 @@ function testSchemas() {
]
},
+ // flags tests
+ {
+ conditionGroups: [
+ {
+ conditions: [
+ {
+ type: 'flags',
+ operator: 'are',
+ value: ''
+ }
+ ]
+ }
+ ],
+ expectedSchema: {
+ required: ['flags'],
+ properties: {
+ flags: {
+ type: 'array',
+ maxItems: 0,
+ minItems: 0
+ }
+ }
+ },
+ inputs: [
+ {expected: true, context: {}},
+ {expected: true, context: {flags: []}},
+ {expected: false, context: {flags: ['test1']}},
+ {expected: false, context: {flags: ['test1', 'test2']}},
+ {expected: false, context: {flags: ['test1', 'test2', 'test3']}}
+ ]
+ },
+ {
+ conditionGroups: [
+ {
+ conditions: [
+ {
+ type: 'flags',
+ operator: 'are',
+ value: 'test1, test2'
+ }
+ ]
+ }
+ ],
+ expectedSchema: {
+ required: ['flags'],
+ properties: {
+ flags: {
+ type: 'array',
+ maxItems: 2,
+ minItems: 2,
+ allOf: [
+ {contains: {const: 'test1'}},
+ {contains: {const: 'test2'}}
+ ]
+ }
+ }
+ },
+ inputs: [
+ {expected: false, context: {}},
+ {expected: false, context: {flags: []}},
+ {expected: false, context: {flags: ['test1']}},
+ {expected: true, context: {flags: ['test1', 'test2']}},
+ {expected: false, context: {flags: ['test1', 'test2', 'test3']}}
+ ]
+ },
+ {
+ conditionGroups: [
+ {
+ conditions: [
+ {
+ type: 'flags',
+ operator: 'areNot',
+ value: ''
+ }
+ ]
+ }
+ ],
+ expectedSchema: {
+ not: [
+ {
+ required: ['flags'],
+ properties: {
+ flags: {
+ type: 'array',
+ maxItems: 0,
+ minItems: 0
+ }
+ }
+ }
+ ]
+ },
+ inputs: [
+ {expected: false, context: {}},
+ {expected: false, context: {flags: []}},
+ {expected: true, context: {flags: ['test1']}},
+ {expected: true, context: {flags: ['test1', 'test2']}},
+ {expected: true, context: {flags: ['test1', 'test2', 'test3']}}
+ ]
+ },
+ {
+ conditionGroups: [
+ {
+ conditions: [
+ {
+ type: 'flags',
+ operator: 'areNot',
+ value: 'test1, test2'
+ }
+ ]
+ }
+ ],
+ expectedSchema: {
+ not: [
+ {
+ required: ['flags'],
+ properties: {
+ flags: {
+ type: 'array',
+ maxItems: 2,
+ minItems: 2,
+ allOf: [
+ {contains: {const: 'test1'}},
+ {contains: {const: 'test2'}}
+ ]
+ }
+ }
+ }
+ ]
+ },
+ inputs: [
+ {expected: true, context: {}},
+ {expected: true, context: {flags: []}},
+ {expected: true, context: {flags: ['test1']}},
+ {expected: false, context: {flags: ['test1', 'test2']}},
+ {expected: true, context: {flags: ['test1', 'test2', 'test3']}}
+ ]
+ },
+ {
+ conditionGroups: [
+ {
+ conditions: [
+ {
+ type: 'flags',
+ operator: 'include',
+ value: ''
+ }
+ ]
+ }
+ ],
+ expectedSchema: {
+ required: ['flags'],
+ properties: {
+ flags: {
+ type: 'array',
+ minItems: 0
+ }
+ }
+ },
+ inputs: [
+ {expected: true, context: {}},
+ {expected: true, context: {flags: []}},
+ {expected: true, context: {flags: ['test1']}},
+ {expected: true, context: {flags: ['test1', 'test2']}},
+ {expected: true, context: {flags: ['test1', 'test2', 'test3']}}
+ ]
+ },
+ {
+ conditionGroups: [
+ {
+ conditions: [
+ {
+ type: 'flags',
+ operator: 'include',
+ value: 'test1, test2'
+ }
+ ]
+ }
+ ],
+ expectedSchema: {
+ required: ['flags'],
+ properties: {
+ flags: {
+ type: 'array',
+ minItems: 2,
+ allOf: [
+ {contains: {const: 'test1'}},
+ {contains: {const: 'test2'}}
+ ]
+ }
+ }
+ },
+ inputs: [
+ {expected: false, context: {}},
+ {expected: false, context: {flags: []}},
+ {expected: false, context: {flags: ['test1']}},
+ {expected: true, context: {flags: ['test1', 'test2']}},
+ {expected: true, context: {flags: ['test1', 'test2', 'test3']}}
+ ]
+ },
+ {
+ conditionGroups: [
+ {
+ conditions: [
+ {
+ type: 'flags',
+ operator: 'notInclude',
+ value: ''
+ }
+ ]
+ }
+ ],
+ expectedSchema: {
+ required: ['flags'],
+ properties: {
+ flags: {
+ type: 'array'
+ }
+ }
+ },
+ inputs: [
+ {expected: true, context: {}},
+ {expected: true, context: {flags: []}},
+ {expected: true, context: {flags: ['test1']}},
+ {expected: true, context: {flags: ['test1', 'test2']}},
+ {expected: true, context: {flags: ['test1', 'test2', 'test3']}}
+ ]
+ },
+ {
+ conditionGroups: [
+ {
+ conditions: [
+ {
+ type: 'flags',
+ operator: 'notInclude',
+ value: 'test1, test2'
+ }
+ ]
+ }
+ ],
+ expectedSchema: {
+ required: ['flags'],
+ properties: {
+ flags: {
+ type: 'array',
+ not: [
+ {contains: {const: 'test1'}},
+ {contains: {const: 'test2'}}
+ ]
+ }
+ }
+ },
+ inputs: [
+ {expected: true, context: {}},
+ {expected: true, context: {flags: []}},
+ {expected: false, context: {flags: ['test1']}},
+ {expected: false, context: {flags: ['test1', 'test2']}},
+ {expected: false, context: {flags: ['test1', 'test2', 'test3']}}
+ ]
+ },
+
// Multiple conditions tests
{
conditionGroups: [