Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Unify tests #4368

Merged
merged 3 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@ export const useGridColumnResize = (

colDefRef.current = colDef as GridStateColDef;
colElementRef.current =
apiRef.current.columnHeadersContainerElementRef?.current!.querySelector(
apiRef.current.columnHeadersContainerElementRef?.current!.querySelector<HTMLDivElement>(
`[data-field="${colDef.field}"]`,
) as HTMLDivElement;
)!;

colCellElementsRef.current = findGridCellElementsFromCol(
colElementRef.current,
) as NodeListOf<Element>;

const doc = ownerDocument(apiRef.current.rootElementRef!.current as HTMLElement);
const doc = ownerDocument(apiRef.current.rootElementRef!.current);
doc.body.style.cursor = 'col-resize';

separatorSide.current = getSeparatorSide(event.currentTarget);
Expand Down Expand Up @@ -350,7 +350,7 @@ export const useGridColumnResize = (
});

const stopListening = React.useCallback(() => {
const doc = ownerDocument(apiRef.current.rootElementRef!.current as HTMLElement);
const doc = ownerDocument(apiRef.current.rootElementRef!.current);
doc.body.style.removeProperty('cursor');
doc.removeEventListener('mousemove', handleResizeMouseMove);
doc.removeEventListener('mouseup', handleResizeMouseUp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ describe('<DataGridPro /> - Column pinning', () => {
this.skip();
}
render(<TestCase initialState={{ pinnedColumns: { left: ['id'] } }} />);
const renderZone = document.querySelector(
const renderZone = document.querySelector<HTMLDivElement>(
`.${gridClasses.virtualScrollerRenderZone}`,
) as HTMLDivElement;
)!;
expect(renderZone).toHaveInlineStyle({ transform: 'translate3d(100px, 0px, 0px)' });
const columnHeader = getColumnHeaderCell(0);
const separator = columnHeader.querySelector(`.${gridClasses['columnSeparator--resizable']}`);
Expand All @@ -126,9 +126,9 @@ describe('<DataGridPro /> - Column pinning', () => {
this.skip();
}
render(<TestCase initialState={{ pinnedColumns: { left: ['id'] } }} />);
const columnHeadersInner = document.querySelector(
const columnHeadersInner = document.querySelector<HTMLDivElement>(
`.${gridClasses.columnHeadersInner}`,
) as HTMLDivElement;
)!;
expect(columnHeadersInner).toHaveInlineStyle({ transform: 'translate3d(100px, 0px, 0px)' });
const columnHeader = getColumnHeaderCell(0);
const separator = columnHeader.querySelector(`.${gridClasses['columnSeparator--resizable']}`);
Expand Down Expand Up @@ -261,9 +261,9 @@ describe('<DataGridPro /> - Column pinning', () => {
describe('props: pinnedColumns', () => {
it('should pin the columns specified', () => {
render(<TestCase pinnedColumns={{ left: ['currencyPair'] }} />);
const leftColumns = document.querySelector(
const leftColumns = document.querySelector<HTMLDivElement>(
`.${gridClasses['pinnedColumns--left']}`,
) as HTMLDivElement;
)!;
expect(leftColumns.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
});

Expand All @@ -284,9 +284,9 @@ describe('<DataGridPro /> - Column pinning', () => {

it('should filter our duplicated columns', () => {
render(<TestCase pinnedColumns={{ left: ['currencyPair'], right: ['currencyPair'] }} />);
const leftColumns = document.querySelector(
const leftColumns = document.querySelector<HTMLDivElement>(
`.${gridClasses['pinnedColumns--left']}`,
) as HTMLDivElement;
)!;
expect(leftColumns.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
expect(document.querySelector(`.${gridClasses['pinnedColumns--right']}`)).to.equal(null);
});
Expand Down Expand Up @@ -331,12 +331,12 @@ describe('<DataGridPro /> - Column pinning', () => {
describe('apiRef', () => {
it('should reorder the columns to render the left pinned columns before all other columns', () => {
render(<TestCase initialState={{ pinnedColumns: { left: ['currencyPair', 'price1M'] } }} />);
const leftColumns = document.querySelector(
const leftColumns = document.querySelector<HTMLDivElement>(
`.${gridClasses['pinnedColumns--left']}`,
) as HTMLDivElement;
const renderZone = document.querySelector(
)!;
const renderZone = document.querySelector<HTMLDivElement>(
`.${gridClasses.virtualScrollerRenderZone}`,
) as HTMLDivElement;
)!;
expect(leftColumns.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
expect(leftColumns.querySelector('[data-field="price1M"]')).not.to.equal(null);
expect(renderZone.querySelector('[data-field="currencyPair"]')).to.equal(null);
Expand All @@ -345,12 +345,12 @@ describe('<DataGridPro /> - Column pinning', () => {

it('should reorder the columns to render the right pinned columns after all other columns', () => {
render(<TestCase initialState={{ pinnedColumns: { right: ['price16M', 'price17M'] } }} />);
const rightColumns = document.querySelector(
const rightColumns = document.querySelector<HTMLDivElement>(
`.${gridClasses['pinnedColumns--right']}`,
) as HTMLDivElement;
const renderZone = document.querySelector(
)!;
const renderZone = document.querySelector<HTMLDivElement>(
`.${gridClasses.virtualScrollerRenderZone}`,
) as HTMLDivElement;
)!;
expect(rightColumns.querySelector('[data-field="price16M"]')).not.to.equal(null);
expect(rightColumns.querySelector('[data-field="price17M"]')).not.to.equal(null);
expect(renderZone.querySelector('[data-field="price16M"]')).to.equal(null);
Expand All @@ -367,47 +367,47 @@ describe('<DataGridPro /> - Column pinning', () => {
describe('pinColumn', () => {
it('should pin the given column', () => {
render(<TestCase />);
const renderZone = document.querySelector(
const renderZone = document.querySelector<HTMLDivElement>(
`.${gridClasses.virtualScrollerRenderZone}`,
) as HTMLDivElement;
)!;
expect(renderZone.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
apiRef.current.pinColumn('currencyPair', GridPinnedPosition.left);
const leftColumns = document.querySelector(
const leftColumns = document.querySelector<HTMLDivElement>(
`.${gridClasses['pinnedColumns--left']}`,
) as HTMLDivElement;
)!;
expect(leftColumns.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
expect(renderZone.querySelector('[data-field="currencyPair"]')).to.equal(null);
});

it('should change the side when called on a pinned column', () => {
render(<TestCase />);
const renderZone = document.querySelector(
const renderZone = document.querySelector<HTMLDivElement>(
`.${gridClasses.virtualScrollerRenderZone}`,
) as HTMLDivElement;
)!;
expect(renderZone.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
expect(renderZone.querySelector('[data-field="currencyPair"]')).not.to.equal(null);

apiRef.current.pinColumn('currencyPair', GridPinnedPosition.left);
const leftColumns = document.querySelector(
const leftColumns = document.querySelector<HTMLDivElement>(
`.${gridClasses['pinnedColumns--left']}`,
) as HTMLDivElement;
)!;
expect(leftColumns.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
expect(renderZone.querySelector('[data-field="currencyPair"]')).to.equal(null);

apiRef.current.pinColumn('currencyPair', GridPinnedPosition.right);
const rightColumns = document.querySelector(
const rightColumns = document.querySelector<HTMLDivElement>(
`.${gridClasses['pinnedColumns--right']}`,
) as HTMLDivElement;
)!;
expect(document.querySelector(`.${gridClasses['pinnedColumns--left']}`)).to.equal(null);
expect(rightColumns.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
});

it('should not change the columns when called on a pinned column with the same side ', () => {
render(<TestCase />);
apiRef.current.pinColumn('currencyPair', GridPinnedPosition.left);
const leftColumns = document.querySelector(
const leftColumns = document.querySelector<HTMLDivElement>(
`.${gridClasses['pinnedColumns--left']}`,
) as HTMLDivElement;
)!;
expect(leftColumns.querySelector('[data-id="0"]')?.children).to.have.length(1);
apiRef.current.pinColumn('currencyPair', GridPinnedPosition.left);
expect(leftColumns.querySelector('[data-id="0"]')?.children).to.have.length(1);
Expand All @@ -421,9 +421,9 @@ describe('<DataGridPro /> - Column pinning', () => {
expect(document.querySelector(`.${gridClasses['pinnedColumns--left']}`)).not.to.equal(null);
apiRef.current.unpinColumn('currencyPair');
expect(document.querySelector(`.${gridClasses['pinnedColumns--left']}`)).to.equal(null);
const renderZone = document.querySelector(
const renderZone = document.querySelector<HTMLDivElement>(
`.${gridClasses.virtualScrollerRenderZone}`,
) as HTMLDivElement;
)!;
expect(renderZone.querySelector('[data-field="currencyPair"]')).not.to.equal(null);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('<DataGridPro /> - Filter', () => {
it('should apply the filterModel prop correctly', () => {
render(<TestCase filterModel={filterModel} />);

expect(getColumnValues()).to.deep.equal(['Adidas', 'Puma']);
expect(getColumnValues(0)).to.deep.equal(['Adidas', 'Puma']);
});

it('should apply the filterModel prop correctly on GridApiRef setRows', () => {
Expand All @@ -93,14 +93,14 @@ describe('<DataGridPro /> - Filter', () => {
},
];
apiRef.current.setRows(newRows);
expect(getColumnValues()).to.deep.equal(['Asics']);
expect(getColumnValues(0)).to.deep.equal(['Asics']);
});

it('should apply the filterModel prop correctly on GridApiRef update row data', () => {
render(<TestCase filterModel={filterModel} />);
apiRef.current.updateRows([{ id: 1, brand: 'Fila' }]);
apiRef.current.updateRows([{ id: 0, brand: 'Patagonia' }]);
expect(getColumnValues()).to.deep.equal(['Patagonia', 'Fila', 'Puma']);
expect(getColumnValues(0)).to.deep.equal(['Patagonia', 'Fila', 'Puma']);
});

it('should allow apiRef to setFilterModel', () => {
Expand All @@ -114,7 +114,7 @@ describe('<DataGridPro /> - Filter', () => {
},
],
});
expect(getColumnValues()).to.deep.equal(['Adidas']);
expect(getColumnValues(0)).to.deep.equal(['Adidas']);
});

it('should allow multiple filter and default to AND', () => {
Expand All @@ -135,7 +135,7 @@ describe('<DataGridPro /> - Filter', () => {
],
};
render(<TestCase filterModel={newModel} />);
expect(getColumnValues()).to.deep.equal(['Puma']);
expect(getColumnValues(0)).to.deep.equal(['Puma']);
});

it('should allow multiple filter via apiRef', () => {
Expand All @@ -157,7 +157,7 @@ describe('<DataGridPro /> - Filter', () => {
],
};
apiRef.current.setFilterModel(newModel);
expect(getColumnValues()).to.deep.equal(['Adidas']);
expect(getColumnValues(0)).to.deep.equal(['Adidas']);
});

it('should allow multiple filter and changing the linkOperator', () => {
Expand All @@ -179,7 +179,7 @@ describe('<DataGridPro /> - Filter', () => {
linkOperator: GridLinkOperator.Or,
};
render(<TestCase filterModel={newModel} />);
expect(getColumnValues()).to.deep.equal(['Adidas', 'Puma']);
expect(getColumnValues(0)).to.deep.equal(['Adidas', 'Puma']);
});

it('should trigger onFilterModelChange when the link operator changes but not change the state', () => {
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('<DataGridPro /> - Filter', () => {
/>,
);
expect(onFilterModelChange.callCount).to.equal(0);
expect(getColumnValues()).to.deep.equal([]);
expect(getColumnValues(0)).to.deep.equal([]);

// The first combo is hidden and we include hidden elements to make the query faster
// https://github.com/testing-library/dom-testing-library/issues/820#issuecomment-726936225
Expand All @@ -219,7 +219,7 @@ describe('<DataGridPro /> - Filter', () => {
];
fireEvent.change(select, { target: { value: 'or' } });
expect(onFilterModelChange.callCount).to.equal(1);
expect(getColumnValues()).to.deep.equal([]);
expect(getColumnValues(0)).to.deep.equal([]);
});

it('should call onFilterModelChange when the value is emptied', () => {
Expand Down Expand Up @@ -276,9 +276,9 @@ describe('<DataGridPro /> - Filter', () => {
],
};
const { setProps } = render(<TestCase filterModel={newModel} />);
expect(getColumnValues()).to.deep.equal(['Adidas']);
expect(getColumnValues(0)).to.deep.equal(['Adidas']);
setProps({ filterModel: { items: [] } });
expect(getColumnValues()).to.deep.equal(['Nike', 'Adidas', 'Puma']);
expect(getColumnValues(0)).to.deep.equal(['Nike', 'Adidas', 'Puma']);
});

it('should show the latest visibleRows', () => {
Expand All @@ -296,7 +296,7 @@ describe('<DataGridPro /> - Filter', () => {
const input = screen.getByPlaceholderText('Filter value');
fireEvent.change(input, { target: { value: 'ad' } });
clock.tick(SUBMIT_FILTER_STROKE_TIME);
expect(getColumnValues()).to.deep.equal(['Adidas']);
expect(getColumnValues(0)).to.deep.equal(['Adidas']);

expect(apiRef.current.getVisibleRowModels().size).to.equal(1);
expect(apiRef.current.getVisibleRowModels().get(1)).to.deep.equal({ id: 1, brand: 'Adidas' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ describe('<DataGridPro /> - Pagination', () => {

render(<GridTest />);

expect(getColumnValues()).to.deep.equal(['0']);
expect(getColumnValues(0)).to.deep.equal(['0']);
act(() => {
apiRef.current.setPage(1);
});

expect(getColumnValues()).to.deep.equal(['1']);
expect(getColumnValues(0)).to.deep.equal(['1']);
});

it('should apply last page if trying to go to a non-existing page', () => {
Expand All @@ -61,12 +61,12 @@ describe('<DataGridPro /> - Pagination', () => {

render(<GridTest />);

expect(getColumnValues()).to.deep.equal(['0']);
expect(getColumnValues(0)).to.deep.equal(['0']);
act(() => {
apiRef.current.setPage(50);
});

expect(getColumnValues()).to.deep.equal(['19']);
expect(getColumnValues(0)).to.deep.equal(['19']);
});
});

Expand Down Expand Up @@ -96,12 +96,12 @@ describe('<DataGridPro /> - Pagination', () => {
render(<GridTest />);
clock.runToLast();

expect(getColumnValues()).to.deep.equal(['0', '1', '2', '3', '4']);
expect(getColumnValues(0)).to.deep.equal(['0', '1', '2', '3', '4']);
act(() => {
apiRef.current.setPageSize(2);
});

expect(getColumnValues()).to.deep.equal(['0', '1']);
expect(getColumnValues(0)).to.deep.equal(['0', '1']);
});
});
});
Loading