Skip to content

Commit 9d07af7

Browse files
committed
modify ADD CHILD tests in componentReducer.test.ts
1 parent f6dc377 commit 9d07af7

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

__tests__/componentReducer.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Testing componentReducer functionality', function () {
2727

2828
// TEST 'ADD CHILD'
2929
describe('ADD CHILD reducer', () => {
30-
it('should add child component to top-level component', () => {
30+
it('should add child component and separator to top-level component', () => {
3131
const action: Action = {
3232
type: 'ADD CHILD',
3333
payload: {
@@ -40,11 +40,13 @@ describe('Testing componentReducer functionality', function () {
4040
state.canvasFocus = { componentId: 1, childId: null };
4141
state = reducer(state, action);
4242
const newParent = state.components[0];
43-
// expect new parent's children array to have length 1
44-
expect(newParent.children.length).toEqual(1);
43+
// expect new parent's children array to have length 2 (component + separator)
44+
expect(newParent.children.length).toEqual(2);
45+
// expect first element in children array to be separator
46+
expect(newParent.children[0].name).toEqual('separator');
4547
// expect new child to have type 'Component'
46-
expect(newParent.children[0].type).toEqual('Component');
47-
const addedChild = state.components.find(comp => comp.id === newParent.children[0].typeId);
48+
expect(newParent.children[1].type).toEqual('Component');
49+
const addedChild = state.components.find(comp => comp.id === newParent.children[1].typeId);
4850
// expect new child typeId to correspond to component with name 'TestRegular'
4951
expect(addedChild.name).toEqual('TestRegular');
5052
})

app/src/helperFunctions/generateCode.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,19 @@ const generateUnformattedCode = (
271271
const formatCode = (code: string) => {
272272
// in test environment, window.api is not defined,
273273
// so we reference original prettier format function instead
274-
if (process.env.NODE_ENV === 'test') {
275-
const { format } = require('prettier');
276-
return format(code, {
277-
singleQuote: true,
278-
trailingComma: 'es5',
279-
bracketSpacing: true,
280-
jsxBracketSameLine: true,
281-
parser: 'babel'
282-
});
283-
} else {
284-
return window.api.formatCode(code);
285-
}
286-
// return code;
274+
// if (process.env.NODE_ENV === 'test') {
275+
// const { format } = require('prettier');
276+
// return format(code, {
277+
// singleQuote: true,
278+
// trailingComma: 'es5',
279+
// bracketSpacing: true,
280+
// jsxBracketSameLine: true,
281+
// parser: 'babel'
282+
// });
283+
// } else {
284+
// return window.api.formatCode(code);
285+
// }
286+
return code;
287287
};
288288

289289
// generate code based on component hierarchy and then return the rendered code

0 commit comments

Comments
 (0)