refactor: expose dependencies of XmlToMathMLAdapter
This commit is contained in:
parent
abee69ff21
commit
8cd62236db
@ -1,4 +1,9 @@
|
||||
import { XmlToMathMLAdapter } from '../../../src/infra/usecases/xmldom-to-mathml-elements';
|
||||
import {
|
||||
XmlToMathMLAdapter,
|
||||
ElementsToMathMLAdapter,
|
||||
ErrorHandler,
|
||||
} from '../../../src/infra/usecases/xmldom-to-mathml-elements';
|
||||
|
||||
import {
|
||||
singleMi,
|
||||
singleMiNoRoot,
|
||||
@ -8,11 +13,18 @@ import {
|
||||
} from '../../mocks/mathmlStrings';
|
||||
|
||||
describe('#convert', () => {
|
||||
const makeSut = (): XmlToMathMLAdapter => {
|
||||
const elementsToMathMLAdapter = new ElementsToMathMLAdapter();
|
||||
const errorHandler = new ErrorHandler();
|
||||
|
||||
return new XmlToMathMLAdapter(elementsToMathMLAdapter, errorHandler);
|
||||
};
|
||||
|
||||
describe('given math string with mi tag', () => {
|
||||
it('return array with single mathml interface of name math and child mi', () => {
|
||||
const mathmlString = singleMi;
|
||||
|
||||
const result = new XmlToMathMLAdapter(mathmlString).convert();
|
||||
const result = makeSut().convert(mathmlString);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toMatchObject({
|
||||
@ -28,7 +40,7 @@ describe('#convert', () => {
|
||||
test('return array with single mathml interface of name math and child mi', () => {
|
||||
const mathmlString = singleMiNoRoot;
|
||||
|
||||
const result = new XmlToMathMLAdapter(mathmlString).convert();
|
||||
const result = makeSut().convert(mathmlString);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toMatchObject({
|
||||
@ -44,7 +56,7 @@ describe('#convert', () => {
|
||||
test('return content in a three and keep value on each child', () => {
|
||||
const mathmlString = mrow;
|
||||
|
||||
const result = new XmlToMathMLAdapter(mathmlString).convert();
|
||||
const result = makeSut().convert(mathmlString);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toMatchObject({
|
||||
@ -71,7 +83,7 @@ describe('#convert', () => {
|
||||
test('add attributes to children related with name mfenced', () => {
|
||||
const mathmlString = mfencedWithSeparatorAttribute;
|
||||
|
||||
const result = new XmlToMathMLAdapter(mathmlString).convert();
|
||||
const result = makeSut().convert(mathmlString);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toMatchObject({
|
||||
@ -98,7 +110,7 @@ describe('#convert', () => {
|
||||
test('add attributes to children related with name mfenced', () => {
|
||||
const mathmlString = mfencedWithBrokenAttribute;
|
||||
|
||||
const result = new XmlToMathMLAdapter(mathmlString).convert();
|
||||
const result = makeSut().convert(mathmlString);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toMatchObject({
|
||||
|
@ -1 +1,3 @@
|
||||
export * from './xmldom-to-mathml-element-adapter';
|
||||
export * from './error-handler';
|
||||
export * from './xmldom-elements-to-mathml-elements-adapter';
|
||||
|
@ -6,16 +6,14 @@ import { ErrorHandler } from './error-handler';
|
||||
import { MathMLElement } from '@/data/protocols/mathml-element';
|
||||
|
||||
export class XmlToMathMLAdapter {
|
||||
private _xml: string;
|
||||
private _xml = '';
|
||||
private readonly _xmlDOM: DOMParser;
|
||||
private readonly _errorHandler: ErrorHandler;
|
||||
private readonly _elementsConvertor: ElementsToMathMLAdapter;
|
||||
|
||||
constructor(xml: string) {
|
||||
this._xml = this._removeLineBreaks(xml);
|
||||
|
||||
this._elementsConvertor = new ElementsToMathMLAdapter();
|
||||
this._errorHandler = new ErrorHandler();
|
||||
constructor(elementsConvertor: ElementsToMathMLAdapter, errorHandler: ErrorHandler) {
|
||||
this._elementsConvertor = elementsConvertor;
|
||||
this._errorHandler = errorHandler;
|
||||
|
||||
this._xmlDOM = new xmldom.DOMParser({
|
||||
locator: this._errorHandler.errorLocator,
|
||||
@ -23,7 +21,8 @@ export class XmlToMathMLAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
convert(): MathMLElement[] {
|
||||
convert(xml: string): MathMLElement[] {
|
||||
this._xml = this._removeLineBreaks(xml);
|
||||
return this._elementsConvertor.convert(this._mathMLElements);
|
||||
}
|
||||
|
||||
|
1
src/main/factories/index.ts
Normal file
1
src/main/factories/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './make-to-math-elements-converter';
|
8
src/main/factories/make-to-math-elements-converter.ts
Normal file
8
src/main/factories/make-to-math-elements-converter.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { XmlToMathMLAdapter, ElementsToMathMLAdapter, ErrorHandler } from '@/infra/usecases/xmldom-to-mathml-elements';
|
||||
|
||||
export const makeToMathElementsConverter = (): XmlToMathMLAdapter => {
|
||||
const elementsToMathMLAdapter = new ElementsToMathMLAdapter();
|
||||
const errorHandler = new ErrorHandler();
|
||||
|
||||
return new XmlToMathMLAdapter(elementsToMathMLAdapter, errorHandler);
|
||||
};
|
@ -1,9 +1,9 @@
|
||||
import { MathMLElementToLatexConverterAdapter } from '@/data/usecases/mathml-to-latex-convertion/mathml-element-to-latex-converter-adapter';
|
||||
import { XmlToMathMLAdapter } from '@/infra/usecases/xmldom-to-mathml-elements';
|
||||
import { makeToMathElementsConverter } from './factories';
|
||||
|
||||
export class MathMLToLaTeX {
|
||||
static convert(mathml: string): string {
|
||||
const mathmlElements = new XmlToMathMLAdapter(mathml).convert();
|
||||
const mathmlElements = makeToMathElementsConverter().convert(mathml);
|
||||
const mathmlElementsToLaTeXConverters = mathmlElements.map((mathMLElement) =>
|
||||
new MathMLElementToLatexConverterAdapter(mathMLElement).toLatexConverter(),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user