Skip to content

Commit 8c3a8de

Browse files
Rexmeherhowji-5740
authored andcommitted
Support-2399 : Removed Expo dependencies with native dependencies. Added test and test dependencies for ReactNativeFusionChart component.
Support-2399 : Removed the Extra Metro.config alteration step from documentation, as it is no longer required. Support-2399 : Removed the Extra Metro.config alteration step from documentation, as it is no longer required. Do not push fcScript files to npm. Support-2399 : Removed the no longer fc-builder file. updated readme added fusioncharts logo removed expo files and clean up
1 parent 4727b89 commit 8c3a8de

37 files changed

+30978
-26605
lines changed

.npmignore

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
# Don't push source codes to npm
2-
.expo/
3-
.expo-shared/
1+
# This file lists items that should be excluded from the published npm package
42
assets/
53
bin/
64
node_modules/
5+
examples/
6+
testData/
7+
__tests__/
8+
src/modules/fusioncharts/
9+
src/modules/index.html
10+
gulpUtil.js
11+
gulpfile.js
12+
jest-setup.js
13+
jest.config.js
14+
babel.config.js

README.md

Lines changed: 288 additions & 340 deletions
Large diffs are not rendered by default.

__tests__/__snapshots__/index.test.js.snap

Lines changed: 351 additions & 0 deletions
Large diffs are not rendered by default.

__tests__/index.test.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/**
2+
* @format
3+
*/
4+
5+
import 'react-native';
6+
import React from 'react';
7+
import ReactNativeFusionCharts from '../src/FusionCharts.js';
8+
import { data } from '../testData/null_data.js';
9+
import { schema } from '../testData/null_schema.js';
10+
11+
// Note: import explicitly to use the types shipped with jest.
12+
import { it } from '@jest/globals';
13+
14+
// Note: test renderer must be required after react-native.
15+
import renderer from 'react-test-renderer';
16+
import { render } from '@testing-library/react-native';
17+
18+
jest.mock('react-native-webview', () => {
19+
const MockWebView = jest.requireActual('react-native').View;
20+
21+
return {
22+
__esModule: true,
23+
WebView: MockWebView,
24+
default: MockWebView,
25+
};
26+
});
27+
28+
jest.mock('react-native-fs', () => ({
29+
default: () => jest.fn() // or any mocked component instead of native view,
30+
}));
31+
32+
jest.mock('@notifee/react-native', () => ({
33+
default: () => jest.fn() // or any mocked component instead of native view,
34+
}));
35+
36+
jest.mock('react-native-share', () => ({
37+
default: () => jest.fn() // or any mocked component instead of native view,
38+
}));
39+
40+
jest.mock('@react-native-camera-roll/camera-roll', () => ({
41+
default: () => jest.fn() // or any mocked component instead of native view,
42+
}));
43+
44+
45+
it('Chart renders without crashing', () => {
46+
const chartData = [
47+
{ label: "Venezuela", value: "250" },
48+
{ label: "Saudi", value: "260" },
49+
{ label: "Canada", value: "180" },
50+
{ label: "Iran", value: "140" },
51+
{ label: "Russia", value: "115" },
52+
{ label: "UAE", value: "100" },
53+
{ label: "US", value: "30" },
54+
{ label: "China", value: "30" },
55+
];
56+
const chartConfig = {
57+
type: "column2D",
58+
width: "300",
59+
height: "400",
60+
dataFormat: "json",
61+
dataSource: {
62+
chart: {
63+
caption: "Countries With Most Oil Reserves [2017-18]",
64+
subCaption: "In MMbbl = One Million barrels",
65+
xAxisName: "Country",
66+
yAxisName: "Reserves (MMbbl)",
67+
numberSuffix: "K",
68+
theme: "fusion",
69+
exportEnabled: 1 // to enable the export chart functionality
70+
},
71+
data: chartData
72+
}
73+
};
74+
const { toJSON } = render(
75+
<ReactNativeFusionCharts
76+
chartConfig={chartConfig}
77+
/>);
78+
expect(toJSON()).toMatchSnapshot(); // Check if the component renders correctly
79+
});
80+
81+
82+
it('TimeSeries chart renders without crashing', () => {
83+
let startTime = performance.now();
84+
85+
const chartConfig = {
86+
type: 'timeseries',
87+
width: '100%',
88+
height: '500',
89+
dataFormat: 'json',
90+
dataSource: {
91+
chart: {},
92+
data: null,
93+
caption: {
94+
text: "Pollution Report of Yatcha Street"
95+
},
96+
subcaption: {
97+
text: "An industrial town"
98+
},
99+
yaxis: [{
100+
plot: [{
101+
value: "Pollution",
102+
"connectnulldata": "true",
103+
type: 'line'
104+
105+
}],
106+
title: "Pollution Concentration (in ppm)",
107+
min: "130",
108+
109+
referenceline: [{
110+
label: "Controlled Temperature",
111+
value: "150"
112+
}]
113+
}]
114+
},
115+
schemaJson: schema,
116+
dataJson: data
117+
};
118+
119+
const events = {
120+
dataplotclick: (e, a) => {
121+
alert(`You clicked on ${e.data.categoryLabel}`);
122+
},
123+
"rendered": (e, a) => {
124+
let endTime = performance.now()
125+
126+
console.log(`Call to doSomething took ${endTime - startTime} milliseconds.`);
127+
},
128+
"referencelineclick": function (ev) {
129+
alert('reference line clicked')
130+
},
131+
}
132+
const modules = ['timeseries'];
133+
134+
135+
const { toJSON } = render(
136+
<ReactNativeFusionCharts
137+
chartConfig={chartConfig}
138+
events={events}
139+
modules={modules}
140+
/>);
141+
expect(toJSON()).toMatchSnapshot(); // Check if the component renders correctly
142+
});

app.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = function(api) {
22
api.cache(true);
33
return {
4-
presets: ['babel-preset-expo'],
4+
presets: ['module:@react-native/babel-preset'],
55
};
66
};

bin/fc-builder.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

gulpUtil.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
4+
function replacePathsWithContents(obj) {
5+
const promises = [];
6+
function traverseAndReplace(obj) {
7+
for (let key in obj) {
8+
if (typeof obj[key] === 'string') {
9+
const filePath = path.join(__dirname, obj[key]);
10+
promises.push(
11+
new Promise((resolve, reject) => {
12+
fs.readFile(filePath, 'utf8', (err, data) => {
13+
if (err) {
14+
return reject(err);
15+
}
16+
obj[key] = data;
17+
resolve();
18+
});
19+
})
20+
);
21+
} else if (typeof obj[key] === 'object') {
22+
traverseAndReplace(obj[key]);
23+
}
24+
}
25+
}
26+
traverseAndReplace(obj);
27+
return Promise.all(promises).catch(err => {
28+
console.error('Error reading file:', err);
29+
});
30+
}
31+
32+
module.exports = { replacePathsWithContents };

gulpfile.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
const rename = require('gulp-rename');
22
const gulp = require('gulp');
33
const removeFiles = require('gulp-remove-files');
4+
const fs = require('fs').promises;
5+
const merge = require('merge-stream');
6+
const { modules, scripts } = require('./src/FusionChartsModule.js');
7+
const { replacePathsWithContents } = require('./gulpUtil.js');
48

59
const filePath = './src/modules/fusioncharts/';
10+
const inputFilePath = './src/modules/index.html';
11+
const outputFilePath = './src/modules/layout.js';
12+
const jsOutputFilePath = './src/modules/scripts.js';
13+
const modulesOutputFilePath = './src/modules/modules.js';
614

7-
gulp.task('default', async function () {
8-
// rename
9-
gulp.src(filePath + '*.js')
15+
// Task for renaming and removing files
16+
gulp.task('rename', function () {
17+
18+
const renameModuleStream = gulp.src(filePath + '*.js')
1019
.pipe(rename(function (path) {
1120
path.extname = '.fcscript';
1221
}))
1322
.pipe(gulp.dest(filePath));
14-
23+
1524
// remove duplicates
1625
gulp.src(filePath + '*.js')
1726
.pipe(removeFiles());
@@ -22,7 +31,7 @@ gulp.task('default', async function () {
2231
path.extname = '.fcscript';
2332
}))
2433
.pipe(gulp.dest(filePath + 'maps/es/'));
25-
34+
2635
// remove duplicates in maps folder
2736
gulp.src(filePath + 'maps/es/*.js')
2837
.pipe(removeFiles());
@@ -33,9 +42,45 @@ gulp.task('default', async function () {
3342
path.extname = '.fcscript';
3443
}))
3544
.pipe(gulp.dest(filePath + 'themes/'));
36-
45+
3746
// remove duplicates in theme folder
3847
gulp.src(filePath + 'themes/*.js')
3948
.pipe(removeFiles());
4049

50+
return renameModuleStream
4151
});
52+
53+
// Default task
54+
gulp.task('default', gulp.series('rename', async function (done) {
55+
try {
56+
// Read the content of index.html
57+
const data = await fs.readFile(inputFilePath, 'utf8');
58+
59+
// Escape backticks and dollar signs to prevent issues in the template string
60+
const escapedContent = data.replace(/`/g, '\\`').replace(/\$/g, '\\$');
61+
62+
// Prepare the JavaScript content
63+
const outputContent = `export default \`${escapedContent}\`;`;
64+
65+
// Write the content to layout.js
66+
await fs.writeFile(outputFilePath, outputContent);
67+
console.log('layout.js created successfully!');
68+
69+
// Read Scripts and Modules and create a single output.js file
70+
await replacePathsWithContents(scripts);
71+
const jsOutputContent = `export default ${JSON.stringify(scripts)};`;
72+
await fs.writeFile(jsOutputFilePath, jsOutputContent);
73+
console.log('scripts.js created successfully!');
74+
75+
// Process modules
76+
await replacePathsWithContents(modules);
77+
const modulesOutputContent = `export default ${JSON.stringify(modules)};`;
78+
await fs.writeFile(modulesOutputFilePath, modulesOutputContent);
79+
console.log('modules.js created successfully!');
80+
81+
} catch (err) {
82+
console.error('Error:', err);
83+
} finally {
84+
done(); // Ensure done is called even if an error occurs
85+
}
86+
}));

jest-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/react-native/extend-expect';

0 commit comments

Comments
 (0)