Skip to content

Commit

Permalink
fix: add primary-section-changed event
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Feb 5, 2020
1 parent d1d26d2 commit 5526381
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/vaadin-app-layout-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ export const AppLayoutMixin = <T extends Constructor<LitElement>>(
})
);
}

if (props.has('primarySection')) {
this.dispatchEvent(
new CustomEvent('primary-section-changed', {
detail: {
value: this.primarySection
}
})
);
}
}

protected _sizeChanged(contentRect: DOMRect) {
Expand Down
28 changes: 22 additions & 6 deletions test/unit/app-layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ describe('app-layout', () => {
});
});

describe('primarySection', () => {
beforeEach(async () => {
layout = await fixture(html`
<vaadin-app-layout></vaadin-app-layout>
`);
});

it('should fire "primary-section-changed" event when property changes', async () => {
const spy = sinon.spy();
layout.addEventListener('primary-section-changed', spy);
layout.primarySection = 'drawer';
await layout.updateComplete;
expect(spy).to.be.calledOnce;
});

it('should fallback to navbar if invalid "primarySection" is set', async () => {
layout.primarySection = 'foobar';
await layout.updateComplete;
expect(layout.primarySection).to.be.equal('navbar');
});
});

describe('drawer', () => {
let drawer: Element;

Expand Down Expand Up @@ -93,12 +115,6 @@ describe('app-layout', () => {
expect(layout.drawerOpened).to.be.not.equal(currentDrawerState);
});

it('should fallback to navbar if invalid "primarySection" is set', async () => {
layout.primarySection = 'foobar';
await layout.updateComplete;
expect(layout.primarySection).to.be.equal('navbar');
});

it('should fire "drawer-opened-changed" event when opening drawer', async () => {
layout.drawerOpened = false;
await layout.updateComplete;
Expand Down

0 comments on commit 5526381

Please sign in to comment.