2016-03-01 10:47:22 +08:00
|
|
|
import fs from 'fs';
|
2016-03-01 23:58:29 +08:00
|
|
|
import path from 'path';
|
2016-03-01 10:47:22 +08:00
|
|
|
import AutoloadImagesExtension from '../lib/autoload-images-extension';
|
|
|
|
import AutoloadImagesStore from '../lib/autoload-images-store';
|
|
|
|
|
2016-03-01 23:58:29 +08:00
|
|
|
describe("AutoloadImagesExtension", () => {
|
|
|
|
describe("formatMessageBody", () => {
|
2016-03-01 10:47:22 +08:00
|
|
|
const scenarios = [];
|
|
|
|
const fixtures = path.resolve(path.join(__dirname, 'fixtures'));
|
|
|
|
|
2016-03-01 23:58:29 +08:00
|
|
|
fs.readdirSync(fixtures).forEach((filename) => {
|
2016-03-01 10:47:22 +08:00
|
|
|
if (filename.endsWith('-in.html')) {
|
|
|
|
const name = filename.replace('-in.html', '');
|
2016-03-01 23:58:29 +08:00
|
|
|
|
2016-03-01 10:47:22 +08:00
|
|
|
scenarios.push({
|
|
|
|
name: name,
|
|
|
|
in: fs.readFileSync(path.join(fixtures, filename)).toString(),
|
|
|
|
out: fs.readFileSync(path.join(fixtures, `${name}-out.html`)).toString(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
scenarios.forEach((scenario)=> {
|
2016-03-01 23:58:29 +08:00
|
|
|
it(`should process ${scenario.name}`, () => {
|
2016-03-01 10:47:22 +08:00
|
|
|
spyOn(AutoloadImagesStore, 'shouldBlockImagesIn').andReturn(true);
|
2016-03-01 23:58:29 +08:00
|
|
|
|
|
|
|
const message = {
|
|
|
|
body: scenario.in,
|
2016-03-01 10:47:22 +08:00
|
|
|
};
|
|
|
|
AutoloadImagesExtension.formatMessageBody({message});
|
2016-03-01 23:58:29 +08:00
|
|
|
|
|
|
|
expect(message.body === scenario.out).toBe(true);
|
2016-03-01 10:47:22 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|