Skip to content

Commit 9ec067d

Browse files
committed
chore: tile resize spec checkpoint
1 parent b98cbdc commit 9ec067d

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

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

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ describe('Tile resize', () => {
2121

2222
let tileManager: IgcTileManagerComponent;
2323

24+
function getTiles() {
25+
return Array.from(tileManager.querySelectorAll('igc-tile'));
26+
}
27+
2428
function getTileBaseWrapper(element: IgcTileComponent) {
29+
const resizeElement = element.renderRoot.querySelector('igc-resize');
30+
31+
if (resizeElement) {
32+
return resizeElement.querySelector<HTMLDivElement>('[part~="base"]')!;
33+
}
34+
2535
return element.renderRoot.querySelector<HTMLDivElement>('[part~="base"]')!;
2636
}
2737

@@ -48,68 +58,60 @@ describe('Tile resize', () => {
4858
tileManager = await fixture<IgcTileManagerComponent>(createTileManager());
4959
});
5060

51-
it('should create a ghost element on resize start', async () => {
52-
const tile = first(tileManager.tiles);
53-
// const eventSpy = spy(tile, 'emitEvent');
61+
const resize = async (tile: Element, clientX: number, clientY: number) => {
62+
const resizer = tile.shadowRoot?.querySelector('igc-resize');
63+
const resizeHandle =
64+
resizer?.shadowRoot?.querySelector('[part="trigger"]');
5465

55-
await elementUpdated(tile);
66+
simulatePointerDown(resizeHandle!);
67+
68+
await elementUpdated(resizer!);
69+
70+
simulatePointerMove(resizeHandle!, { clientX });
71+
72+
await elementUpdated(resizer!);
73+
};
74+
75+
it('should create a ghost element on resize start', async () => {
76+
const tile = first(getTiles());
5677
const resizer = tile.renderRoot.querySelector('igc-resize')!;
57-
const resizeHandle = resizer?.shadowRoot?.querySelector('igc-icon');
78+
const eventSpy = spy(resizer, 'emitEvent');
79+
const resizeHandle =
80+
resizer?.shadowRoot?.querySelector('[part="trigger"]');
5881
const resizerChildren = resizer.children;
5982
expect(resizerChildren).lengthOf(1);
6083

6184
simulatePointerDown(resizeHandle!);
62-
await elementUpdated(resizeHandle!);
85+
await elementUpdated(resizer!);
6386

6487
expect(resizerChildren).lengthOf(2);
6588
const ghostElement = resizerChildren[1];
66-
expect(ghostElement).to.not.be.null;
6789

68-
simulatePointerMove(resizeHandle!, { clientX: 10, clientY: 10 });
69-
// expect(eventSpy).calledWith('igcResizeStart');
70-
// expect(eventSpy).to.have.been.calledWith('igcResizeStart'
71-
// // {
72-
// // detail: tile,
73-
// // cancelable: true,
74-
// // }
75-
// );
90+
expect(ghostElement).to.not.be.null;
91+
expect(eventSpy).calledWith('igcResizeStart');
7692
});
7793

78-
it('should update ghost element styles during pointer move', async () => {
79-
const tile = first(tileManager.tiles);
80-
// const eventSpy = spy(tile, 'emitEvent');
81-
const { x, y, width, height } = tile.getBoundingClientRect();
82-
// const resizeHandle = tile.shadowRoot!.querySelector('.resize-handle');
83-
94+
it('should update ghost element styles during pointer move - columns', async () => {
95+
const tile = first(getTiles());
8496
const resizer = tile.renderRoot.querySelector('igc-resize')!;
85-
const resizeHandle = resizer?.shadowRoot?.querySelector('igc-icon');
97+
//const resizeHandle = resizer?.shadowRoot?.querySelector('[part="trigger"]');
8698

87-
simulatePointerDown(resizeHandle!);
88-
await elementUpdated(resizeHandle!);
99+
const eventSpy = spy(resizer, 'emitEvent');
89100

90-
simulatePointerMove(resizeHandle!, {
91-
clientX: x + width * 2,
92-
clientY: y + height * 2,
93-
});
94-
await elementUpdated(resizeHandle!);
101+
const { x, width } = tile.getBoundingClientRect();
102+
resize(tile, x + width * 2, 0);
103+
104+
await elementUpdated(tile);
105+
106+
const updatedGhostElement = resizer.children[1] as HTMLElement;
107+
//debugger
108+
109+
expect(eventSpy).calledWith('igcResize');
95110

96-
// expect(eventSpy).calledWith('igcResizeStart');
97-
// expect(eventSpy.getCall(0)).calledWith('igcResizeStart', {
98-
// detail: tile,
99-
// cancelable: true,
100-
// });
101-
102-
// expect(eventSpy.getCall(1)).calledWith('igcResizeMove', {
103-
// detail: tile,
104-
// cancelable: true,
105-
// });
106-
107-
// TODO Fix or remove that check when the resize interaction is finalized
108-
// const ghostElement = tileManager.querySelector(
109-
// '#resize-ghost'
110-
// ) as HTMLElement;
111-
// expect(ghostElement.style.gridColumn).to.equal('span 9');
112-
// expect(ghostElement.style.gridRow).to.equal('span 9');
111+
// Check if styles are updated, also check values
112+
expect(updatedGhostElement.style.width).to.not.be.empty;
113+
expect(updatedGhostElement.style.height).to.not.be.empty;
114+
// Check values
113115
});
114116

115117
xit('should set the styles on the tile and remove the ghost element on resize end', async () => {

0 commit comments

Comments
 (0)