Skip to content

Commit

Permalink
- Condition action tests added
Browse files Browse the repository at this point in the history
🪿
  • Loading branch information
maZahaca committed Dec 3, 2018
1 parent 5b84e2d commit 3c34ffb
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/actions/ActionCondition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
121 changes: 121 additions & 0 deletions test/integration/actions/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 3c34ffb

Please sign in to comment.