Skip to content

Commit

Permalink
WIP: Fix failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acdvorak committed Feb 9, 2019
1 parent f53f6b3 commit e196d6b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 51 deletions.
2 changes: 0 additions & 2 deletions packages/mdc-top-app-bar/fixed/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ class MDCFixedTopAppBarFoundation extends MDCTopAppBarFoundation {

init() {
super.init();
this.adapter_.registerScrollHandler(this.scrollHandler_);
}

destroy() {
super.destroy();
this.adapter_.deregisterScrollHandler(this.scrollHandler_);
}

/**
Expand Down
26 changes: 15 additions & 11 deletions packages/mdc-top-app-bar/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,35 @@ class MDCTopAppBarBaseFoundation extends MDCFoundation<MDCTopAppBarAdapter> {
// tslint:enable:object-literal-sort-keys
}

protected navClickHandler_: EventListener;
protected scrollHandler_: EventListener;
protected scrollHandler_?: EventListener;
protected resizeHandler_?: EventListener;
private readonly navClickHandler_: EventListener;

constructor(adapter: Partial<MDCTopAppBarAdapter> = {}) {
super({...MDCTopAppBarBaseFoundation.defaultAdapter, ...adapter});

this.navClickHandler_ = () => this.adapter_.notifyNavigationIconClicked();
this.scrollHandler_ = () => undefined;
}

init() {
if (this.scrollHandler_) {
this.adapter_.registerScrollHandler(this.scrollHandler_);
}
if (this.resizeHandler_) {
this.adapter_.registerResizeHandler(this.resizeHandler_);
}
this.adapter_.registerNavigationIconInteractionHandler('click', this.navClickHandler_);
}

destroy() {
if (this.scrollHandler_) {
this.adapter_.deregisterScrollHandler(this.scrollHandler_);
}
if (this.resizeHandler_) {
this.adapter_.deregisterResizeHandler(this.resizeHandler_);
}
this.adapter_.deregisterNavigationIconInteractionHandler('click', this.navClickHandler_);
}

initScrollHandler() {
this.adapter_.registerScrollHandler(this.scrollHandler_);
}

destroyScrollHandler() {
this.adapter_.deregisterScrollHandler(this.scrollHandler_);
}
}

export {MDCTopAppBarBaseFoundation as default, MDCTopAppBarBaseFoundation};
2 changes: 0 additions & 2 deletions packages/mdc-top-app-bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ class MDCTopAppBar extends MDCComponent<MDCTopAppBarBaseFoundation> {
}

setScrollTarget(target: EventTarget) {
this.foundation_.destroyScrollHandler();
this.scrollTarget_ = target;
this.foundation_.initScrollHandler();
}

getDefaultFoundation(): MDCTopAppBarBaseFoundation {
Expand Down
11 changes: 6 additions & 5 deletions packages/mdc-top-app-bar/short/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,28 @@ class MDCShortTopAppBarFoundation extends MDCTopAppBarBaseFoundation {

constructor(adapter: Partial<MDCTopAppBarAdapter> = {}) {
super(adapter);

this.scrollHandler_ = () => this.shortAppBarScrollHandler_();
}

init() {
super.init();
const isAlwaysCollapsed = this.adapter_.hasClass(cssClasses.SHORT_COLLAPSED_CLASS);

if (this.adapter_.getTotalActionItems() > 0) {
this.adapter_.addClass(cssClasses.SHORT_HAS_ACTION_ITEM_CLASS);
}

if (!isAlwaysCollapsed) {
if (!this.isAlwaysCollapsed_) {
this.scrollHandler_ = () => this.shortAppBarScrollHandler_();
this.adapter_.registerScrollHandler(this.scrollHandler_);
this.shortAppBarScrollHandler_();
}
}

destroy() {
super.destroy();
this.adapter_.deregisterScrollHandler(this.scrollHandler_);
}

private get isAlwaysCollapsed_() {
return this.adapter_.hasClass(cssClasses.SHORT_COLLAPSED_CLASS);
}

/**
Expand Down
6 changes: 0 additions & 6 deletions packages/mdc-top-app-bar/standard/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class MDCTopAppBarFoundation extends MDCTopAppBarBaseFoundation {
*/
private resizeDebounceId_ = INITIAL_VALUE;

private readonly resizeHandler_: EventListener;

constructor(adapter: Partial<MDCTopAppBarAdapter> = {}) {
super(adapter);

Expand All @@ -82,14 +80,10 @@ class MDCTopAppBarFoundation extends MDCTopAppBarBaseFoundation {

init() {
super.init();
this.adapter_.registerScrollHandler(this.scrollHandler_);
this.adapter_.registerResizeHandler(this.resizeHandler_);
}

destroy() {
super.destroy();
this.adapter_.deregisterScrollHandler(this.scrollHandler_);
this.adapter_.deregisterResizeHandler(this.resizeHandler_);
this.adapter_.setStyle('top', '');
}

Expand Down
14 changes: 0 additions & 14 deletions test/unit/mdc-top-app-bar/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,3 @@ test('click handler removed from navigation icon during destroy', () => {
foundation.destroy();
td.verify(mockAdapter.deregisterNavigationIconInteractionHandler('click', td.matchers.isA(Function)));
});

test('#initScrollHandler calls registerScrollHandler', () => {
const {foundation, mockAdapter} = setupTest();
foundation.scrollHandler_ = td.func();
foundation.initScrollHandler();
td.verify(mockAdapter.registerScrollHandler(foundation.scrollHandler_), {times: 1});
});

test('#destroyScrollHandler calls deregisterScrollHandler', () => {
const {foundation, mockAdapter} = setupTest();
foundation.scrollHandler_ = td.func();
foundation.destroyScrollHandler();
td.verify(mockAdapter.deregisterScrollHandler(foundation.scrollHandler_), {times: 1});
});
11 changes: 0 additions & 11 deletions test/unit/mdc-top-app-bar/mdc-top-app-bar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ test('destroy destroys icon ripples', () => {
});
});

test('#setScrollTarget deregisters and registers scroll handler on provided target', () => {
const {component} = setupTest();
const fakeTarget = {};
component.foundation_.destroyScrollHandler = td.func();
component.foundation_.initScrollHandler = td.func();
component.setScrollTarget(fakeTarget);
td.verify(component.foundation_.destroyScrollHandler(), {times: 1});
td.verify(component.foundation_.initScrollHandler(), {times: 1});
assert.equal(component.scrollTarget_, fakeTarget);
});

test('getDefaultFoundation returns the appropriate foundation for default', () => {
const fixture = getFixture();
const root = fixture.querySelector(strings.ROOT_SELECTOR);
Expand Down

0 comments on commit e196d6b

Please sign in to comment.