Skip to content

Commit

Permalink
test(integration-karma): migrate nested-template-event-target (#1207)
Browse files Browse the repository at this point in the history
* test(integration-karma): migrate nested-template-event-target

* test(integration-karma): migrate root-listener-event-target

* test(integration-karma): migrate slotted-custome-element-event-target

* test(integration-karma): migrate nested-render-conditional

* test: increase timeout for two tests that flap in ie11
  • Loading branch information
jodarove authored and ekashida committed May 10, 2019
1 parent 41bce87 commit 40905e7
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 162 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createElement } from 'test-utils';
import Container from 'x/container';

describe('Event target in slot elements', () => {
it('should receive event with correct target', function() {
const elm = createElement('x-container', { is: Container });
document.body.appendChild(elm);

const child = elm.shadowRoot.querySelector('x-child');

child.dispatchFoo();

return Promise.resolve().then(() => {
const elementWithResult = elm.shadowRoot.querySelector('.evt-target-is-x-child');
expect(elementWithResult).not.toBeNull();
expect(elementWithResult.innerText).toBe('Event Target Is x-child');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template>
<integration-child onfoo={handleFoo}></integration-child>
<x-child onfoo={handleFoo}></x-child>
<div class="evt-target-is-x-child" if:true={evtTargetIsXChild}>Event Target Is x-child</div>
</template>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { LightningElement, track } from 'lwc';

export default class NestedTemplateEventTarget extends LightningElement {
export default class Container extends LightningElement {
@track
evtTargetIsXChild = false;

handleFoo(evt) {
this.evtTargetIsXChild = evt.target.tagName.toLowerCase() === 'integration-child';
this.evtTargetIsXChild = evt.target.tagName.toLowerCase() === 'x-child';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createElement } from 'test-utils';
import Container from 'x/container';

describe('Event target in slot elements', () => {
it('should receive event with correct event.target in a shadowRoot listener', function() {
const elm = createElement('x-container', { is: Container });
document.body.appendChild(elm);

const child = elm.shadowRoot.querySelector('x-child');
child.click();

return Promise.resolve().then(() => {
const elementWithResult = elm.shadowRoot.querySelector('.event-target-correct');
expect(elementWithResult).not.toBeNull();
expect(elementWithResult.innerText).toBe('Event Target is correct element');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template>
<integration-grand-child></integration-grand-child>
<x-child></x-child>
<div class="event-target-correct" if:true={eventTargetIsCorrect}>Event Target is correct element</div>
</template>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { LightningElement, track } from 'lwc';

export default class Child extends LightningElement {
export default class Container extends LightningElement {
@track eventTargetIsCorrect = false;

connectedCallback() {
this.template.addEventListener('click', evt => {
this.eventTargetIsCorrect = evt.target.tagName === 'INTEGRATION-GRAND-CHILD';
this.eventTargetIsCorrect = evt.target.tagName === 'X-CHILD';
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createElement } from 'test-utils';
import Container from 'x/container';

describe('Event target in slot elements', () => {
it('should receive event with correct target in slotted custom element', function() {
const elm = createElement('x-container', { is: Container });
document.body.appendChild(elm);

const child = elm.shadowRoot.querySelector('x-child');
child.click();

return Promise.resolve().then(() => {
const elementWithResult = elm.shadowRoot
.querySelector('x-parent')
.shadowRoot.querySelector('.correct-event-target');

expect(elementWithResult).not.toBeNull();
expect(elementWithResult.innerText).toBe('Event target is correct');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LightningElement } from 'lwc';

export default class Child extends LightningElement {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<x-parent>
<x-child></x-child>
</x-parent>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LightningElement } from 'lwc';

export default class Container extends LightningElement {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { LightningElement, track } from 'lwc';
export default class XParent extends LightningElement {
@track eventTargetIsCorrectTag = false;
handleClick(evt) {
this.eventTargetIsCorrectTag = evt.target.tagName === 'INTEGRATION-CHILD';
this.eventTargetIsCorrectTag = evt.target.tagName === 'X-CHILD';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createElement } from 'test-utils';
import XTest from 'x/test';
import XSlotted from 'x/slotted';
import NestedRenderConditional from 'x/nestedRenderConditional';

describe('if:true directive', () => {
it('should render if the value is truthy', () => {
Expand All @@ -19,6 +20,21 @@ describe('if:true directive', () => {
expect(elm.shadowRoot.querySelector('.true')).toBeNull();
});

it('should remove element within a nested conditional', () => {
const elm = createElement('x-nested-render-conditional', { is: NestedRenderConditional });
document.body.appendChild(elm);

const elementToggler = elm.shadowRoot.querySelector('.click-me');

elementToggler.click();

return Promise.resolve().then(() => {
const elementInsideNestedCondition = elm.shadowRoot.querySelector('.toggle');

expect(elementInsideNestedCondition).toBeNull();
});
});

it('should update if the value change', () => {
const elm = createElement('x-test', { is: XTest });
elm.isVisible = true;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Component with a wired method', () => {
});
return todoText.value === 'Title:task 1 Completed:false';
},
500,
1000,
'Should update todo id'
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Component with a wired property', () => {
});
return todoText.value === 'Title:task 1 Completed:false';
},
500,
1000,
'expect todo item to be updated'
);
});
Expand Down

0 comments on commit 40905e7

Please sign in to comment.