Skip to content

Commit b6d76da

Browse files
authored
fix: add setup cell that has been deleted (#6916)
## 📝 Summary <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes #123). --> Updated the condition for checking the existence of the setup cell to use `state.cellIds` instead of `state.cellData`. When deleteCell is called, it removes from cellIds, not cellData ## 🔍 Description of Changes <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [x] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected.
1 parent 4dc2b15 commit b6d76da

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

frontend/src/core/cells/__tests__/cells.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ describe("cell reducer", () => {
21092109
actions.addSetupCellIfDoesntExist({ code: "# Updated setup code" });
21102110

21112111
// Check that the same setup cell was updated, not duplicated
2112-
expect(state.cellData[SETUP_CELL_ID].code).toBe("# Setup code");
2112+
expect(state.cellData[SETUP_CELL_ID].code).toBe("# Updated setup code");
21132113
expect(state.cellData[SETUP_CELL_ID].edited).toBe(true);
21142114
expect(state.cellIds.inOrderIds).toContain(SETUP_CELL_ID);
21152115
});
@@ -2143,6 +2143,24 @@ describe("cell reducer", () => {
21432143
expect(state.cellIds.inOrderIds).toContain(SETUP_CELL_ID);
21442144
});
21452145

2146+
it("can delete and then create a new setup cell", () => {
2147+
// Create the setup cell
2148+
actions.addSetupCellIfDoesntExist({ code: "# Setup code" });
2149+
2150+
// Delete the setup cell
2151+
actions.deleteCell({ cellId: SETUP_CELL_ID });
2152+
2153+
// Create a new setup cell
2154+
actions.addSetupCellIfDoesntExist({ code: "# New code" });
2155+
2156+
// Check that the new setup cell was created
2157+
expect(state.cellData[SETUP_CELL_ID].id).toBe(SETUP_CELL_ID);
2158+
expect(state.cellData[SETUP_CELL_ID].name).toBe("setup");
2159+
expect(state.cellData[SETUP_CELL_ID].code).toBe("# New code");
2160+
expect(state.cellData[SETUP_CELL_ID].edited).toBe(true);
2161+
expect(state.cellIds.inOrderIds).toContain(SETUP_CELL_ID);
2162+
});
2163+
21462164
it("can clear all outputs", () => {
21472165
// Add a cell and give it output
21482166
actions.createNewCell({

frontend/src/core/cells/cells.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ const {
13361336
}
13371337

13381338
// First check if setup cell already exists
1339-
if (SETUP_CELL_ID in state.cellData) {
1339+
if (SETUP_CELL_ID in state.cellIds) {
13401340
// Just focus on the existing setup cell
13411341
return {
13421342
...state,

0 commit comments

Comments
 (0)