Skip to content

Commit

Permalink
fix(core): fcl refactoring to not rely on element's dimensions, mainl…
Browse files Browse the repository at this point in the history
…y to fix unit tests

BREAKING CHANGES:
* if you rely on dimensions in your unit tests now you have to call component's `updateLayout()` method to organize cards into the columns.
  • Loading branch information
platon-rov committed Jul 29, 2022
1 parent 3ab5b58 commit f625c7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('FixedCardLayoutComponent', () => {
}
} as any;

component.fixedCardLayout.updateLayout();
component.fixedCardLayout._onDragDropped(event);
fixture.detectChanges();

Expand Down
23 changes: 7 additions & 16 deletions libs/core/src/lib/fixed-card-layout/fixed-card-layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange
_placeholderMargin: boolean;

/** @hidden */
_listenResize = false;
_listenResize = true;

/** @hidden */
_hiddenCard: Nullable<CardDefinitionDirective>;
Expand Down Expand Up @@ -214,11 +214,7 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange

/** @hidden */
ngAfterViewInit(): void {
if (this._layout.nativeElement.clientHeight) {
this._processCards();
} else {
this._listenResize = true;
}
this._processCards();

this._listenOnResize();
this._listenOnCardsChange();
Expand Down Expand Up @@ -418,27 +414,22 @@ export class FixedCardLayoutComponent implements OnInit, AfterViewInit, OnChange
),
takeUntil(this._onDestroy$)
)
.subscribe(() => {
if (this._cardsArray) {
this.updateLayout();
} else {
this._processCards();
}
});
.subscribe(() => this.updateLayout());
}

/** @hidden Listen card change and distribute cards on column change */
private _listenOnCardsChange(): void {
this._cards.changes.subscribe(() => this._processCards());
this._cards.changes.subscribe(() => {
this._processCards();
this.updateLayout();
});
}

/** @hidden */
private _processCards(): void {
this._cardsArray = this._cards
.toArray()
.sort((firstCard, secondCard) => firstCard.fdCardDef - secondCard.fdCardDef);

this.updateLayout();
}

/** @hidden Distribute cards among columns to arrange them in "Z" flow */
Expand Down

0 comments on commit f625c7d

Please sign in to comment.