Skip to content

Commit ba17ec6

Browse files
authored
Merge pull request #1244 from mito-ds/cross-sheet-test
Add cross sheet formula test
2 parents 7ab41a3 + 828f310 commit ba17ec6

File tree

1 file changed

+112
-1
lines changed

1 file changed

+112
-1
lines changed

tests/streamlit_ui_tests/grid/set_column_formula_tests.spec.ts

+112-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
getValuesInColumn,
88
getMitoFrameWithTestCSV,
99
awaitResponse,
10-
toggleEditEntireColumn
10+
toggleEditEntireColumn,
11+
importCSV,
12+
checkColumnCellsHaveExpectedValues
1113
} from '../utils';
1214

1315

@@ -286,3 +288,112 @@ test('Write spreadsheet formula applied to individual cell', async ({ page }) =>
286288
const cellValues = await getValuesInColumn(mito, columnHeader);
287289
expect(cellValues).toEqual(['1', '0', '0', '0']);
288290
});
291+
292+
test('Cross-sheet formula with VLOOKUP', async ({ page }) => {
293+
const mito = await getMitoFrameWithTestCSV(page);
294+
await importCSV(page, mito, 'merge.csv');
295+
296+
// Add a new column to put the VLOOKUP call in
297+
await mito.locator('.mito-toolbar-button', { hasText: 'Insert' }).click();
298+
await mito.locator('.mito-grid-cell[mito-col-index="1"]').first().dblclick();
299+
300+
// Start the VLOOKUP formula
301+
await mito.locator('input#cell-editor-input').fill('=VLOOKUP(');
302+
// Click on the first cell in Column1 to reference it as the first argument
303+
await mito.locator('.mito-grid-cell[mito-col-index="0"]').first().click();
304+
// Type the comma to separate the arguments
305+
await mito.locator('input#cell-editor-input').press('End');
306+
await mito.locator('input#cell-editor-input').press(',');
307+
308+
// Navigate to the other sheet and select the range of columns
309+
await mito.locator('.tab', { hasText: 'test' }).click();
310+
await expect(mito.locator('.endo-column-header-final-text', { hasText: /new-column/ })).not.toBeVisible();
311+
await mito.locator('.endo-column-header-final-text', { hasText: 'Column1' }).click();
312+
await mito.locator('.endo-column-header-final-text', { hasText: 'Column3' }).click({ modifiers: ['Shift'] });
313+
// Finish the formula
314+
await mito.locator('input#cell-editor-input').press('End');
315+
await mito.locator('input#cell-editor-input').pressSequentially(', 2)');
316+
317+
// Navigate back to the first sheet and check that the values are correct
318+
await mito.locator('.tab', { hasText: 'merge' }).click();
319+
await mito.locator('input#cell-editor-input').press('Enter');
320+
await checkColumnCellsHaveExpectedValues(mito, 1, ['2.00', '5.00', '5.00', 'NaN', '11.00'])
321+
});
322+
323+
324+
test('Cross-sheet formula with VLOOKUP - pressing enter from another sheet', async ({ page }) => {
325+
const mito = await getMitoFrameWithTestCSV(page);
326+
await importCSV(page, mito, 'merge.csv');
327+
328+
// Add a new column to put the VLOOKUP call in
329+
await mito.locator('.mito-toolbar-button', { hasText: 'Insert' }).click();
330+
await mito.locator('.mito-grid-cell[mito-col-index="1"]').first().dblclick();
331+
332+
// Start the VLOOKUP formula
333+
await mito.locator('input#cell-editor-input').fill('=VLOOKUP(');
334+
// Click on the first cell in Column1 to reference it as the first argument
335+
await mito.locator('.mito-grid-cell[mito-col-index="0"]').first().click();
336+
// Type the comma to separate the arguments
337+
await mito.locator('input#cell-editor-input').press('End');
338+
await mito.locator('input#cell-editor-input').press(',');
339+
340+
// Navigate to the other sheet and select the range of columns
341+
await mito.locator('.tab', { hasText: 'test' }).click();
342+
await expect(mito.locator('.endo-column-header-final-text', { hasText: /new-column/ })).not.toBeVisible();
343+
await mito.locator('.endo-column-header-final-text', { hasText: 'Column1' }).click();
344+
await mito.locator('.endo-column-header-final-text', { hasText: 'Column3' }).click({ modifiers: ['Shift'] });
345+
// Finish the formula
346+
await mito.locator('input#cell-editor-input').press('End');
347+
await mito.locator('input#cell-editor-input').pressSequentially(', 2)');
348+
await mito.locator('input#cell-editor-input').press('Enter');
349+
350+
// Expect that it navigated automatically back to the original sheet and that the values are correct
351+
await checkColumnCellsHaveExpectedValues(mito, 1, ['2.00', '5.00', '5.00', 'NaN', '11.00'])
352+
});
353+
354+
test('Can\'t use cross-sheet formula for non-vlookup calls', async ({ page }) => {
355+
const mito = await getMitoFrameWithTestCSV(page);
356+
await importCSV(page, mito, 'merge.csv');
357+
358+
await mito.locator('.mito-grid-cell[mito-col-index="1"]').first().dblclick();
359+
await mito.locator('input#cell-editor-input').fill('=SUM(');
360+
await mito.locator('.tab', { hasText: 'test' }).click();
361+
await mito.locator('.mito-grid-cell[mito-col-index="0"]').first().click();
362+
await mito.locator('input#cell-editor-input').press('Enter');
363+
await expect(mito.getByText('Cross-sheet references are only allowed in calls to VLOOKUP')).toBeVisible();
364+
});
365+
366+
test('Start writing a cross-sheet formula using cel editor and switch to formula bar', async ({ page }) => {
367+
const mito = await getMitoFrameWithTestCSV(page);
368+
// Add a new column to this sheet because the dropdown covers the columns when the formula bar is open
369+
await mito.locator('.mito-toolbar-button', { hasText: 'Insert' }).click();
370+
371+
await importCSV(page, mito, 'merge.csv');
372+
373+
// Add a new column to put the VLOOKUP call in
374+
await mito.locator('.mito-toolbar-button', { hasText: 'Insert' }).click();
375+
await mito.locator('.mito-grid-cell[mito-col-index="1"]').first().dblclick();
376+
377+
// Start the VLOOKUP formula
378+
await mito.locator('input#cell-editor-input').fill('=VLOOKUP(');
379+
// Click on the first cell in Column1 to reference it as the first argument
380+
await mito.locator('.mito-grid-cell[mito-col-index="0"]').first().click();
381+
// Type the comma to separate the arguments
382+
await mito.locator('input#cell-editor-input').press('End');
383+
await mito.locator('input#cell-editor-input').press(',');
384+
385+
// Switch to the formula bar
386+
await mito.locator('.formula-bar').dblclick();
387+
388+
// Navigate to the other sheet and select the range of columns
389+
await mito.locator('.tab', { hasText: 'test' }).click();
390+
await mito.locator('.endo-column-header-final-text', { hasText: 'Column1' }).click();
391+
await mito.locator('.endo-column-header-final-text', { hasText: 'Column3' }).click({ modifiers: ['Shift'] });
392+
// Finish the formula
393+
await mito.locator('#cell-editor-input').press('End');
394+
await mito.locator('#cell-editor-input').pressSequentially(', 3)');
395+
await mito.locator('#cell-editor-input').press('Enter');
396+
397+
// Expect that it navigated automatically back to the original sheet and that the values are correct
398+
await checkColumnCellsHaveExpectedValues(mito, 1, ['2.00', '5.00', '5.00', 'NaN', '11.00'])
399+
});

0 commit comments

Comments
 (0)