Skip to content

Commit a327309

Browse files
committed
merge with develop
2 parents f99cb7d + c0d874d commit a327309

49 files changed

Lines changed: 2576 additions & 280 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/ISSUE_TEMPLATE/existing-feature-enhancement.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ body:
1212
- type: textarea
1313
attributes:
1414
label: Feature enhancement details
15+
description: |
16+
If you want to include screenshots or screen recordings, paste them into the markdown editor below.
1517
validations:
1618
required: true

‎.github/ISSUE_TEMPLATE/feature-request.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ body:
1212
- type: textarea
1313
attributes:
1414
label: Feature request details
15+
description: |
16+
If you want to include screenshots or screen recordings, paste them into the markdown editor below.
1517
validations:
1618
required: true

‎.github/ISSUE_TEMPLATE/found-a-bug.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ body:
3838
- type: textarea
3939
attributes:
4040
label: Actual Behavior
41-
placeholder: What is currently happening.
41+
description: |
42+
Screenshots or screen recordings are preferred if possible. Please paste them into the markdown editor below.
43+
placeholder: What is currently happening. Screenshots or other visuals are appreciated.
4244
validations:
4345
required: true
4446

4547
- type: textarea
4648
attributes:
4749
label: Expected Behavior
4850
description: |
49-
If you want to include screenshots, paste them into the markdown editor below.
51+
If you want to include screenshots or screen recordings, paste them into the markdown editor below.
5052
placeholder: What were you expecting?
5153
validations:
5254
required: true

‎client/modules/IDE/actions/project.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ export function saveProject(
196196
dispatch(endSavingProject());
197197
dispatch(setToastText('Toast.SketchFailedSave'));
198198
dispatch(showToast(1500));
199-
if (response.status === 403) {
199+
if (response?.status === 403) {
200200
dispatch(showErrorModal('staleSession'));
201-
} else if (response.status === 409) {
201+
} else if (response?.status === 409) {
202202
dispatch(showErrorModal('staleProject'));
203203
} else {
204-
dispatch(projectSaveFail(response.data));
204+
dispatch(projectSaveFail(response?.data));
205205
}
206206
});
207207
}
@@ -246,10 +246,10 @@ export function saveProject(
246246
dispatch(endSavingProject());
247247
dispatch(setToastText('Toast.SketchFailedSave'));
248248
dispatch(showToast(1500));
249-
if (response.status === 403) {
249+
if (response?.status === 403) {
250250
dispatch(showErrorModal('staleSession'));
251251
} else {
252-
dispatch(projectSaveFail(response.data));
252+
dispatch(projectSaveFail(response?.data));
253253
}
254254
});
255255
};
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import configureStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
4+
import * as ProjectActions from './project';
5+
import * as ActionTypes from '../../../constants';
6+
import { apiClient } from '../../../utils/apiClient';
7+
import { initialTestState } from '../../../testData/testReduxStore';
8+
9+
const mockStore = configureStore([thunk]);
10+
11+
const existingProjectState = {
12+
...initialTestState,
13+
project: {
14+
...initialTestState.project,
15+
id: 'project123',
16+
owner: { id: initialTestState.user.id }
17+
}
18+
};
19+
20+
const newProjectState = {
21+
...initialTestState,
22+
project: {
23+
...initialTestState.project,
24+
id: undefined,
25+
owner: undefined
26+
}
27+
};
28+
29+
const httpError = (status, data) => ({
30+
response: { status, data }
31+
});
32+
33+
const expectSaveFailureToast = (actions) => {
34+
expect(actions).toContainEqual(ProjectActions.startSavingProject());
35+
expect(actions).toContainEqual(ProjectActions.endSavingProject());
36+
expect(actions).toContainEqual({
37+
type: ActionTypes.SET_TOAST_TEXT,
38+
text: 'Toast.SketchFailedSave'
39+
});
40+
expect(actions).toContainEqual({ type: ActionTypes.SHOW_TOAST });
41+
};
42+
43+
describe('saveProject', () => {
44+
let store;
45+
46+
afterEach(() => {
47+
jest.restoreAllMocks();
48+
if (store) {
49+
store.clearActions();
50+
}
51+
});
52+
53+
describe('updating an existing project (PUT)', () => {
54+
it('handles a network error without throwing when error.response is undefined', async () => {
55+
store = mockStore(existingProjectState);
56+
jest
57+
.spyOn(apiClient, 'put')
58+
.mockRejectedValueOnce(new Error('Network Error'));
59+
60+
await expect(
61+
store.dispatch(ProjectActions.saveProject())
62+
).resolves.toBeUndefined();
63+
64+
const actions = store.getActions();
65+
expectSaveFailureToast(actions);
66+
expect(actions).toContainEqual(ProjectActions.projectSaveFail(undefined));
67+
expect(actions).not.toContainEqual(
68+
expect.objectContaining({ type: ActionTypes.SHOW_ERROR_MODAL })
69+
);
70+
});
71+
72+
it('shows the staleSession modal on 403', async () => {
73+
store = mockStore(existingProjectState);
74+
jest
75+
.spyOn(apiClient, 'put')
76+
.mockRejectedValueOnce(httpError(403, { error: 'Forbidden' }));
77+
78+
await store.dispatch(ProjectActions.saveProject());
79+
80+
const actions = store.getActions();
81+
expectSaveFailureToast(actions);
82+
expect(actions).toContainEqual({
83+
type: ActionTypes.SHOW_ERROR_MODAL,
84+
modalType: 'staleSession'
85+
});
86+
expect(actions).not.toContainEqual(
87+
expect.objectContaining({ type: ActionTypes.PROJECT_SAVE_FAIL })
88+
);
89+
});
90+
91+
it('shows the staleProject modal on 409', async () => {
92+
store = mockStore(existingProjectState);
93+
jest
94+
.spyOn(apiClient, 'put')
95+
.mockRejectedValueOnce(httpError(409, { error: 'Conflict' }));
96+
97+
await store.dispatch(ProjectActions.saveProject());
98+
99+
const actions = store.getActions();
100+
expectSaveFailureToast(actions);
101+
expect(actions).toContainEqual({
102+
type: ActionTypes.SHOW_ERROR_MODAL,
103+
modalType: 'staleProject'
104+
});
105+
expect(actions).not.toContainEqual(
106+
expect.objectContaining({ type: ActionTypes.PROJECT_SAVE_FAIL })
107+
);
108+
});
109+
});
110+
111+
describe('creating a new project (POST)', () => {
112+
it('handles a network error without throwing when error.response is undefined', async () => {
113+
store = mockStore(newProjectState);
114+
jest
115+
.spyOn(apiClient, 'post')
116+
.mockRejectedValueOnce(new Error('Network Error'));
117+
118+
await expect(
119+
store.dispatch(ProjectActions.saveProject())
120+
).resolves.toBeUndefined();
121+
122+
const actions = store.getActions();
123+
expectSaveFailureToast(actions);
124+
expect(actions).toContainEqual(ProjectActions.projectSaveFail(undefined));
125+
expect(actions).not.toContainEqual(
126+
expect.objectContaining({ type: ActionTypes.SHOW_ERROR_MODAL })
127+
);
128+
});
129+
130+
it('shows the staleSession modal on 403', async () => {
131+
store = mockStore(newProjectState);
132+
jest
133+
.spyOn(apiClient, 'post')
134+
.mockRejectedValueOnce(httpError(403, { error: 'Forbidden' }));
135+
136+
await store.dispatch(ProjectActions.saveProject());
137+
138+
const actions = store.getActions();
139+
expectSaveFailureToast(actions);
140+
expect(actions).toContainEqual({
141+
type: ActionTypes.SHOW_ERROR_MODAL,
142+
modalType: 'staleSession'
143+
});
144+
expect(actions).not.toContainEqual(
145+
expect.objectContaining({ type: ActionTypes.PROJECT_SAVE_FAIL })
146+
);
147+
});
148+
});
149+
});

‎client/modules/IDE/components/FileNode.jsx‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { useSelector } from 'react-redux';
77

88
import * as IDEActions from '../actions/ide';
99
import * as FileActions from '../actions/files';
10+
import { showToast as showToastAction } from '../actions/toast';
11+
import { CREATE_FILE_REGEX } from '../../../../server/utils/fileUtils';
1012
import DownArrowIcon from '../../../images/down-filled-triangle.svg';
1113
import FolderRightIcon from '../../../images/triangle-arrow-right.svg';
1214
import FolderDownIcon from '../../../images/triangle-arrow-down.svg';
@@ -82,7 +84,8 @@ const FileNode = ({
8284
canEdit,
8385
openUploadFileModal,
8486
authenticated,
85-
onClickFile
87+
onClickFile,
88+
showToast
8689
}) => {
8790
const [isOptionsOpen, setIsOptionsOpen] = useState(false);
8891
const [isEditingName, setIsEditingName] = useState(false);
@@ -195,6 +198,13 @@ const FileNode = ({
195198
const hasEmptyFilename = updatedName.trim() === '';
196199
const hasOnlyExtension =
197200
newFileExtension && updatedName.trim() === newFileExtension[0];
201+
202+
if (fileType === 'file' && !updatedName.match(CREATE_FILE_REGEX)) {
203+
showToast(t('NewFileModal.InvalidType'));
204+
setUpdatedName(currentName);
205+
return;
206+
}
207+
198208
if (
199209
hasEmptyFilename ||
200210
hasNoExtension ||
@@ -415,7 +425,8 @@ FileNode.propTypes = {
415425
canEdit: PropTypes.bool.isRequired,
416426
openUploadFileModal: PropTypes.func.isRequired,
417427
authenticated: PropTypes.bool.isRequired,
418-
onClickFile: PropTypes.func
428+
onClickFile: PropTypes.func,
429+
showToast: PropTypes.func.isRequired
419430
};
420431

421432
FileNode.defaultProps = {
@@ -436,7 +447,11 @@ function mapStateToProps(state, ownProps) {
436447
});
437448
}
438449

439-
const mapDispatchToProps = { ...FileActions, ...IDEActions };
450+
const mapDispatchToProps = {
451+
...FileActions,
452+
...IDEActions,
453+
showToast: showToastAction
454+
};
440455

441456
const ConnectedFileNode = connect(
442457
mapStateToProps,

‎client/modules/IDE/components/FileNode.unit.test.jsx‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('<FileNode />', () => {
3333
const props = {
3434
...extraProps,
3535
id: '0',
36-
name: fileType === 'folder' ? 'afolder' : 'test.jsx',
36+
name: fileType === 'folder' ? 'afolder' : 'test.js',
3737
fileType,
3838
canEdit: true,
3939
children: [],
@@ -48,7 +48,8 @@ describe('<FileNode />', () => {
4848
showFolderChildren: jest.fn(),
4949
hideFolderChildren: jest.fn(),
5050
openUploadFileModal: jest.fn(),
51-
setProjectName: jest.fn()
51+
setProjectName: jest.fn(),
52+
showToast: jest.fn()
5253
};
5354

5455
const mockFiles = [
@@ -100,7 +101,7 @@ describe('<FileNode />', () => {
100101
});
101102

102103
it('can change to a valid filename', async () => {
103-
const newName = 'newname.jsx';
104+
const newName = 'newname.js';
104105
const props = renderFileNode('file');
105106

106107
changeName(newName);
@@ -125,7 +126,7 @@ describe('<FileNode />', () => {
125126
const mockConfirm = jest.fn(() => true);
126127
window.confirm = mockConfirm;
127128

128-
const newName = 'newname.gif';
129+
const newName = 'newname.json';
129130
const props = renderFileNode('file');
130131

131132
changeName(newName);
@@ -137,8 +138,19 @@ describe('<FileNode />', () => {
137138
await expectFileNameToBe(props.name);
138139
});
139140

141+
it('cannot change to an invalid extension', async () => {
142+
const newName = 'newname.obj';
143+
const props = renderFileNode('file');
144+
145+
changeName(newName);
146+
147+
await waitFor(() => expect(props.updateFileName).not.toHaveBeenCalled());
148+
expect(props.showToast).toHaveBeenCalled();
149+
await expectFileNameToBe(props.name);
150+
});
151+
140152
it('cannot be just an extension', async () => {
141-
const newName = '.jsx';
153+
const newName = '.js';
142154
const props = renderFileNode('file');
143155

144156
changeName(newName);
@@ -171,7 +183,7 @@ describe('<FileNode />', () => {
171183
});
172184

173185
it('cannot have a file extension', async () => {
174-
const newName = 'foldername.jsx';
186+
const newName = 'foldername.js';
175187
const props = renderFileNode('folder');
176188

177189
changeName(newName);

‎client/modules/IDE/components/Header/MobileNav.jsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { availableLanguages, languageKeyToLabel } from '../../../../i18n';
3333
import { showToast } from '../../actions/toast';
3434
import { setLanguage } from '../../actions/preferences';
3535
import { Overlay } from '../../../App/components/Overlay';
36+
import packageData from '../../../../../package.json';
3637
import ProjectName from './ProjectName';
3738
import CollectionCreate from '../../../User/components/CollectionCreate';
3839

@@ -456,6 +457,11 @@ const MoreMenu = () => {
456457
{t('Nav.Help.Reference')}
457458
</MobileMenuItem>
458459
<MobileMenuItem href="/about">{t('About.Title')}</MobileMenuItem>
460+
<MobileMenuItem
461+
href={`https://github.com/processing/p5.js-web-editor/releases/tag/v${packageData.version}`}
462+
>
463+
{t('Nav.Help.WebEditorVersion', { version: packageData.version })}
464+
</MobileMenuItem>
459465
</ParentMenuContext.Provider>
460466
</ul>
461467
</div>

‎client/modules/IDE/components/Header/Nav.jsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from '../../actions/ide';
3030
import { logoutUser } from '../../../User/actions';
3131
import { CmControllerContext } from '../../pages/IDEView';
32+
import packageData from '../../../../../package.json';
3233
import MobileNav from './MobileNav';
3334
import useIsMobile from '../../hooks/useIsMobile';
3435

@@ -334,6 +335,12 @@ const ProjectMenu = () => {
334335
>
335336
{t('Nav.Help.PostOnTheForum')}
336337
</MenubarItem>
338+
<MenubarItem
339+
id="help-web-editor-version"
340+
href={`https://github.com/processing/p5.js-web-editor/releases/tag/v${packageData.version}`}
341+
>
342+
{t('Nav.Help.WebEditorVersion', { version: packageData.version })}
343+
</MenubarItem>
337344
</MenubarSubmenu>
338345
{getConfig('TRANSLATIONS_ENABLED') && <LanguageMenu />}
339346
</ul>

‎client/modules/IDE/components/Header/Nav.unit.test.jsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import Nav from './Nav';
66

77
jest.mock('../../../../utils/generateRandomName');
88

9+
// Mock the editor version so the snapshot stays stable across releases.
10+
// The component reads the real version from package.json at runtime (it bumps
11+
// every release), which would otherwise break these snapshots each release day.
12+
jest.mock('../../../../../package.json', () => ({ version: '1.2.3' }));
13+
914
// mock Menubar
1015
jest.mock('../../../../components/Menubar/Menubar', () => ({
1116
Menubar: ({ children, className = 'nav__menubar' }) => (

0 commit comments

Comments
 (0)