Skip to content

Commit 6ad6aab

Browse files
committed
chore: code cleanup, add tests
1 parent 0c3946f commit 6ad6aab

File tree

3 files changed

+72
-38
lines changed

3 files changed

+72
-38
lines changed

src/components/tile-manager/resize-state.ts

+2-30
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ class TileResizeState {
8585
height: null,
8686
};
8787

88-
public get emptyResizeDimensions(): TileResizeDimensions {
89-
return { width: null, height: null };
90-
}
91-
9288
public get gap(): number {
9389
return this._gap;
9490
}
@@ -153,30 +149,6 @@ class TileResizeState {
153149
};
154150
}
155151

156-
/**
157-
* Checks and adjusts tile spans based on the column count of the tile manager.
158-
*/
159-
// REVIEW once we decide how to handle empty columns.
160-
public adjustTileGridPosition(tiles: IgcTileComponent[]): void {
161-
const columnCount = this.columns.count;
162-
163-
for (const tile of tiles) {
164-
const colStart = tile.colStart || 0;
165-
const colSpan = tile.colSpan || 0;
166-
167-
if (colStart > columnCount) {
168-
//Prioritize span over start?
169-
tile.colSpan = 1;
170-
tile.colStart = columnCount;
171-
continue;
172-
}
173-
174-
if (colStart + colSpan - 1 > columnCount) {
175-
tile.colSpan = columnCount - colStart + 1;
176-
}
177-
}
178-
}
179-
180152
private initState(grid: HTMLElement, tile: IgcTileComponent): void {
181153
const { gap, columns, rows } = parseTileParentGrid(grid);
182154

@@ -257,14 +229,14 @@ class TileResizeState {
257229
targetSize: rect.height,
258230
tilePosition: this.position.row,
259231
tileGridDimension: this.rows,
260-
gap: this._gap,
232+
gap: this.gap,
261233
isRow,
262234
}
263235
: {
264236
targetSize: rect.width,
265237
tilePosition: this.position.column,
266238
tileGridDimension: this.columns,
267-
gap: this._gap,
239+
gap: this.gap,
268240
isRow,
269241
};
270242
}

src/components/tile-manager/tile-manager.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ describe('Tile Manager component', () => {
214214
);
215215
});
216216

217+
it('Should correctly set gap', async () => {
218+
const style = getComputedStyle(getTileManagerBase());
219+
220+
expect(style.gap).to.equal('10px');
221+
222+
tileManager.gap = '25px';
223+
await elementUpdated(tileManager);
224+
225+
expect(style.gap).to.equal('25px');
226+
});
227+
217228
it('should respect tile row and col start properties', async () => {
218229
const tile = tileManager.tiles[2];
219230
tile.colStart = 7;

src/components/tile-manager/tile-resize.spec.ts

+59-8
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,33 @@ describe('Tile resize', () => {
214214
expect(getComputedStyle(firstTile).gridColumn).to.eql('auto / span 2');
215215
});
216216

217+
it('Should correctly shrink tile', async () => {
218+
firstTile.colSpan = 3;
219+
firstTile.rowSpan = 3;
220+
221+
const DOM = getResizeContainerDOM(firstTile);
222+
223+
simulatePointerDown(DOM.adorners.corner);
224+
await elementUpdated(DOM.container);
225+
226+
expect(getComputedStyle(firstTile).gridColumn).to.eql('auto / span 3');
227+
expect(getComputedStyle(firstTile).gridRow).to.eql('auto / span 3');
228+
229+
simulatePointerMove(DOM.adorners.corner, {
230+
clientX: columnSize,
231+
clientY: rowSize,
232+
});
233+
234+
await elementUpdated(DOM.resizeElement);
235+
236+
simulateLostPointerCapture(DOM.adorners.corner);
237+
await elementUpdated(DOM.resizeElement);
238+
await nextFrame();
239+
240+
expect(getComputedStyle(firstTile).gridColumn).to.eql('auto / span 1');
241+
expect(getComputedStyle(firstTile).gridRow).to.eql('auto / span 1');
242+
});
243+
217244
it('Should correctly create/remove implicit rows and resize row with auto grid', async () => {
218245
const DOM = getResizeContainerDOM(firstTile);
219246

@@ -281,6 +308,15 @@ describe('Tile resize', () => {
281308
expect(getColumns().length).to.eql(10);
282309
});
283310

311+
it('Should correctly set rowCount', async () => {
312+
expect(getRows().length).to.eql(1);
313+
314+
tileManager.rowCount = 10;
315+
await elementUpdated(tileManager);
316+
317+
expect(getRows().length).to.eql(10);
318+
});
319+
284320
it('Should cap resizing to max col if greater than', async () => {
285321
const DOM = getResizeContainerDOM(firstTile);
286322

@@ -303,18 +339,33 @@ describe('Tile resize', () => {
303339
expect(getComputedStyle(firstTile).gridColumn).to.eql('auto / span 10');
304340
});
305341

306-
// REVIEW
307-
it('Should initialize tile span as columnCount if it is greater than columnCount', async () => {
342+
it('Should initialize tile colSpan as columnCount if it is greater than columnCount', async () => {
308343
tileManager.columnCount = 10;
344+
firstTile.colSpan = 15;
309345
await elementUpdated(tileManager);
310346

311-
firstTile.colSpan = 15;
312-
await elementUpdated(firstTile);
347+
expect(getColumns().length).to.eql(10);
348+
expect(getComputedStyle(firstTile).gridColumn).to.eql('auto / span 10');
349+
});
313350

314-
// REVIEW once we decide how to handle the scenario where colSpan is greater than column count
315-
// currently 0px columns are added to cover the difference
316-
expect(getColumns().length).to.eql(15);
317-
expect(getComputedStyle(firstTile).gridColumn).to.eql('auto / span 15');
351+
it('Should preserve tile colStart when colStart is valid and colStart + colSpan is greater than columnCount', async () => {
352+
tileManager.columnCount = 10;
353+
firstTile.colStart = 5;
354+
firstTile.colSpan = 10;
355+
await elementUpdated(tileManager);
356+
357+
expect(getColumns().length).to.eql(10);
358+
expect(getComputedStyle(firstTile).gridColumn).to.eql('5 / span 6');
359+
});
360+
361+
it('Should set colStart to 0(auto) and colSpan to columnCount when both are greater than columnCount', async () => {
362+
tileManager.columnCount = 10;
363+
firstTile.colStart = 11;
364+
firstTile.colSpan = 12;
365+
await elementUpdated(tileManager);
366+
367+
expect(getColumns().length).to.eql(10);
368+
expect(getComputedStyle(firstTile).gridColumn).to.eql('auto / span 10');
318369
});
319370

320371
it('Should maintain column position on resize when colStart is set', async () => {

0 commit comments

Comments
 (0)