Skip to content

Commit

Permalink
Action test
Browse files Browse the repository at this point in the history
  • Loading branch information
alanorozco committed Feb 12, 2019
1 parent 0b9eaec commit 6d395a5
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/unit/test-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {AmpDocSingle} from '../../src/service/ampdoc-impl';
import {Keys} from '../../src/utils/key-codes';
import {createCustomEvent} from '../../src/event-helper';
import {createElementWithAttributes} from '../../src/dom';
import {htmlFor} from '../../src/static-template';
import {setParentWindow} from '../../src/service';


Expand Down Expand Up @@ -642,6 +643,48 @@ describe('Action hasAction', () => {

});

describes.fakeWin('Action hasResolvableAction', {}, env => {
let action;
let html;

beforeEach(() => {
html = htmlFor(env.win.document);
action = new ActionService(new AmpDocSingle(env.win), env.win.document);

// Insert element for valid actions to be resolved.
env.win.document.body.appendChild(html`<div id="valid-target"></div>`);
});

it('returns true if the target element exists (single)', () => {
const element = html`<div on="event1: valid-target"></div>`;
expect(action.hasResolvableAction(element, 'event1')).to.equal(true);
});

it('returns true if the target element exists (one amongst many)', () => {
const element =
html`<div on="event1: i-dont-exist, valid-target, i-dont-exist-either">
</div>`;
expect(action.hasResolvableAction(element, 'event1')).to.equal(true);
});

it('returns false if the target element does not exist (one)', () => {
const element = html`<div on="event1: i-do-not-exist"></div>`;
expect(action.hasResolvableAction(element, 'event1')).to.equal(false);
});

it('returns false if the target element does not exist (multiple)', () => {
const element =
html`<div on="event1: i-do-not-exist, i-dont-exist-either"></div>`;
expect(action.hasResolvableAction(element, 'event1')).to.equal(false);
});

it('returns false if target element does not have the target action', () => {
const element = html`<div on="event1: valid-target"></div>`;
expect(action.hasResolvableAction(element, 'event2')).to.equal(false);
});

});


describe('Action method', () => {
let sandbox;
Expand Down

0 comments on commit 6d395a5

Please sign in to comment.