Skip to content

Commit 4bb2f9a

Browse files
authored
Fixing instructions state when set to an empty string (#1191)
This is fixing a bug where the user deletes everything in the instructions box and it suddenly switches back to the empty instructions state. This was caused by the fact that an empty string is `falsy` in Javascript, so when the instructions content was deleted we would get `projectInstructions = ""` which resulted in the instructions being deleted.
1 parent cdcec16 commit 4bb2f9a

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1919
- Instructions empty state to show when instructions are editable (#1165, #1168)
2020
- Allow `instructions` attribute to override instructions attached to the project (#1169)
2121
- Instructions tabs for edit and viewing (#1167)
22-
- Add remove instructions button modal (#1176)
22+
- Add remove instructions button modal (#1176, #1191)
2323
- Dark mode colours (#1182)
2424
- Dark mode for instuctions code block (#1187)
2525
- Change markdown links to open in new tab (#1188)

src/components/WebComponentProject/WebComponentProject.jsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ const WebComponentProject = ({
9898
dispatch(
9999
setInstructions({
100100
project: {
101-
steps: projectInstructions
102-
? [
103-
{
104-
quiz: false,
105-
title: "",
106-
content: marked.parse(projectInstructions),
107-
},
108-
]
109-
: [],
101+
steps:
102+
typeof projectInstructions === "string"
103+
? [
104+
{
105+
quiz: false,
106+
title: "",
107+
content: marked.parse(projectInstructions),
108+
},
109+
]
110+
: [],
110111
},
111112
permitOverride: true,
112113
}),

src/components/WebComponentProject/WebComponentProject.test.js

+31
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,37 @@ describe("When there are instructions", () => {
135135
});
136136
});
137137

138+
describe("When instructions are an empty string", () => {
139+
beforeEach(() => {
140+
renderWebComponentProject({
141+
instructions: "",
142+
codeRunTriggered: true,
143+
});
144+
});
145+
146+
test("Dispatches action to set instructions", () => {
147+
expect(store.getActions()).toEqual(
148+
expect.arrayContaining([
149+
{
150+
type: "instructions/setInstructions",
151+
payload: {
152+
permitOverride: true,
153+
project: {
154+
steps: [
155+
{
156+
title: "",
157+
content: "",
158+
quiz: false,
159+
},
160+
],
161+
},
162+
},
163+
},
164+
]),
165+
);
166+
});
167+
});
168+
138169
describe("When there are no instructions", () => {
139170
beforeEach(() => {
140171
renderWebComponentProject({});

0 commit comments

Comments
 (0)