Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(integration-karma): migrate nested-template-event-target #1207

Merged
merged 5 commits into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.