-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(generate): text, charts, images with pptxgenjs #60
- Loading branch information
Showing
13 changed files
with
367 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Automizer from '../src/automizer'; | ||
import { ChartData, modify } from '../src'; | ||
|
||
const dataChartAreaLine = [ | ||
{ | ||
name: 'Actual Sales', | ||
labels: ['Jan', 'Feb', 'Mar'], | ||
values: [1500, 4600, 5156], | ||
}, | ||
{ | ||
name: 'Projected Sales', | ||
labels: ['Jan', 'Feb', 'Mar'], | ||
values: [1000, 2600, 3456], | ||
}, | ||
]; | ||
|
||
test('generate a chart with pptxgenjs and add it to a template slide', async () => { | ||
const automizer = new Automizer({ | ||
templateDir: `${__dirname}/pptx-templates`, | ||
outputDir: `${__dirname}/pptx-output`, | ||
}); | ||
|
||
const pres = automizer | ||
.loadRoot(`RootTemplate.pptx`) | ||
.load(`EmptySlide.pptx`, 'empty') | ||
.load(`SlideWithCharts.pptx`, 'charts'); | ||
|
||
pres.addSlide('empty', 1, (slide) => { | ||
// Use pptxgenjs to add generated contents from scratch: | ||
slide.generate((pSlide, objectName, pptxGenJs) => { | ||
pSlide.addChart(pptxGenJs.ChartType.line, dataChartAreaLine, { | ||
x: 1, | ||
y: 1, | ||
w: 8, | ||
h: 4, | ||
objectName, | ||
}); | ||
}); | ||
}); | ||
|
||
// Mix the created chart with modified existing chart | ||
pres.addSlide('charts', 2, (slide) => { | ||
slide.modifyElement('ColumnChart', [ | ||
modify.setChartData(<ChartData>{ | ||
series: [{ label: 'series 1' }, { label: 'series 3' }], | ||
categories: [ | ||
{ label: 'cat 2-1', values: [50, 50] }, | ||
{ label: 'cat 2-2', values: [14, 50] }, | ||
], | ||
}), | ||
]); | ||
}); | ||
|
||
const result = await pres.write(`generate-pptxgenjs-charts.test.pptx`); | ||
|
||
expect(result.charts).toBe(4); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Automizer from '../src/automizer'; | ||
import { ChartData, modify } from '../src'; | ||
|
||
test('insert an image with pptxgenjs on a template slide', async () => { | ||
const automizer = new Automizer({ | ||
templateDir: `${__dirname}/pptx-templates`, | ||
outputDir: `${__dirname}/pptx-output`, | ||
}); | ||
|
||
const pres = automizer | ||
.loadRoot(`RootTemplate.pptx`) | ||
.load(`EmptySlide.pptx`, 'empty'); | ||
|
||
pres.addSlide('empty', 1, (slide) => { | ||
// Use pptxgenjs to add image from file: | ||
slide.generate((pptxGenJSSlide, objectName) => { | ||
pptxGenJSSlide.addImage({ | ||
path: `${__dirname}/images/test.png`, | ||
x: 1, | ||
y: 2, | ||
objectName, | ||
}); | ||
}); | ||
}); | ||
|
||
const result = await pres.write(`generate-pptxgenjs-image.test.pptx`); | ||
|
||
expect(result.images).toBe(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Automizer from '../src/automizer'; | ||
import { ChartData, modify } from '../src'; | ||
|
||
test('insert a textbox with pptxgenjs on a template slide', async () => { | ||
const automizer = new Automizer({ | ||
templateDir: `${__dirname}/pptx-templates`, | ||
outputDir: `${__dirname}/pptx-output`, | ||
}); | ||
|
||
const pres = automizer | ||
.loadRoot(`RootTemplate.pptx`) | ||
.load(`EmptySlide.pptx`, 'empty'); | ||
|
||
pres.addSlide('empty', 1, (slide) => { | ||
// Use pptxgenjs to add text from scratch: | ||
slide.generate((pptxGenJSSlide, objectName) => { | ||
pptxGenJSSlide.addText('Test', { | ||
x: 1, | ||
y: 1, | ||
color: '363636', | ||
objectName, | ||
}); | ||
}, 'custom object name'); | ||
}); | ||
|
||
const result = await pres.write(`generate-pptxgenjs-text.test.pptx`); | ||
|
||
expect(result.slides).toBe(2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.