Skip to content

Commit 1018abc

Browse files
committed
Add unit test
1 parent 8575590 commit 1018abc

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

packages/iris-grid/src/sidebar/CustomColumnBuilder.test.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,43 @@ test('Ignores empty names or formulas on save', async () => {
9393
expect(mockSave).toBeCalledWith(customColumns);
9494
});
9595

96+
test('Ignores deleted formulas on save', async () => {
97+
// There is an issue with populating the custom columns and then editing the existing column
98+
// RTL/monaco aren't playing nicely and it won't edit the existing text
99+
// This test instead creates the new text, saves, then removes it to test the same behavior
100+
jest.useFakeTimers();
101+
const user = userEvent.setup({ delay: null });
102+
const model = IrisGridTestUtils.makeModel();
103+
const mockSave = jest.fn(() =>
104+
setTimeout(() => {
105+
model.dispatchEvent(
106+
new EventShimCustomEvent(IrisGridModel.EVENT.COLUMNS_CHANGED)
107+
);
108+
}, 50)
109+
);
110+
111+
const { container } = render(<Builder model={model} onSave={mockSave} />);
112+
113+
await user.type(screen.getByPlaceholderText('Column Name'), 'foo');
114+
await user.click(container.querySelectorAll('.input-editor-wrapper')[0]);
115+
await user.keyboard('bar');
116+
117+
await user.click(screen.getByText(/Save/));
118+
jest.advanceTimersByTime(50); // Applying duration
119+
jest.advanceTimersByTime(CustomColumnBuilder.SUCCESS_SHOW_DURATION);
120+
121+
expect(mockSave).toBeCalledWith(['foo=bar']);
122+
123+
mockSave.mockClear();
124+
125+
await user.click(container.querySelectorAll('.input-editor-wrapper')[0]);
126+
await user.keyboard('{Control>}a{/Control}{Backspace}');
127+
await user.click(screen.getByText(/Save/));
128+
expect(mockSave).toBeCalledWith([]);
129+
130+
jest.useRealTimers();
131+
});
132+
96133
test('Deletes columns', async () => {
97134
const user = userEvent.setup();
98135
const customColumns = ['abc=def', 'foo=bar'];

0 commit comments

Comments
 (0)