Skip to content
Permalink
Browse files

- Condition action tests added

:goose:
  • Loading branch information...
maZahaca committed Dec 3, 2018
1 parent 5b84e2d commit 3c34ffbfbb3bf76ea8937c4b9cb3c8543c1d27f4
Showing with 122 additions and 1 deletion.
  1. +1 −1 lib/actions/ActionCondition.js
  2. +121 −0 test/integration/actions/actions.test.js
@@ -17,7 +17,7 @@ class ActionCondition extends Action {
const conditionsResult = await this._actions.performActions(conditions, this._selector);
if (!conditionsResult) {
this.log('Conditional actions failed with result %s, skip %o', conditionsResult, thenActions);
return elseActions ? this._actions.performActions(elseActions, this._selector) : false;
return this._actions.performActions(elseActions, this._selector);
}

this.log('Conditional actions return %s, go with real some', conditionsResult);
@@ -664,6 +664,27 @@ describe('Actions', () => {

expect(result).toEqual('test');
});

test('perform with no rules', async () => {
setServerResponse({
html: `<span>test</span><input type="text" />`,
});
const parser = new Parser({
environment: new ChromeEnvironment({ url }),
});
const result = await parser.parse({
rules: {
actions: [
{
type: 'provideRules',
},
],
rulesFromActions: true,
},
});

expect(result).toEqual('');
});
});

describe('ActionExist', () => {
@@ -701,6 +722,106 @@ describe('Actions', () => {

expect(result).toEqual('test');
});

test('perform exist child', async () => {
setServerResponse({
html: `<span>global<a href="#">test</a></span>`
});
const parser = new Parser({
environment: new ChromeEnvironment({ url }),
});
const result = await parser.parse({
rules: {
actions: [
{
type: 'condition',
if: [
{
type: 'exists',
scope: 'span',
child: 1,
}
],
then: [
{
type: 'provideRules',
rules: {
scope: 'span',
child: 1,
},
}
],
},
],
rulesFromActions: true,
},
});

expect(result).toEqual('test');
});
});

describe('ActionCondition', () => {
test('perform', async () => {
setServerResponse({
html: `<a href="#">test</a>`
});
const parser = new Parser({
environment: new ChromeEnvironment({ url }),
});
const result = await parser.parse({
rules: {
actions: [
{
type: 'condition',
if: [
{
type: 'exists',
scope: 'span',
}
],
then: [
{
type: 'provideRules',
rules: {
scope: 'span',
},
}
],
else: [
{
type: 'provideRules',
rules: {
scope: 'a',
},
}
],
},
],
rulesFromActions: true,
},
});

expect(result).toEqual('test');
});

test('perform', async () => {
setServerResponse({
html: `<a href="#">test</a>`
});
const parser = new Parser({
environment: new ChromeEnvironment({ url }),
});
const result = await parser.parse({
actions: [
{
type: 'condition',
},
],
});

expect(result).toEqual('');
});
});

// describe('ActionSnapshot', () => {

0 comments on commit 3c34ffb

Please sign in to comment.
You can’t perform that action at this time.