Skip to content

Commit

Permalink
tests are passing
Browse files Browse the repository at this point in the history
  • Loading branch information
zaviermiller committed Dec 27, 2023
1 parent 5762b8a commit fd8483a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 58 deletions.
20 changes: 10 additions & 10 deletions packages/receipt-components/test/receipt-component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('receipt-component', () => {
});

it('should use ReceiptComponent.astBuilders in nodeRegistry', () => {
ReceiptComponent.registerNode(dummyNodePlugin);
ReceiptComponent.registerNodes([dummyNodePlugin]);
const component = new ReceiptComponent('test', {
render: () => '',
});
Expand Down Expand Up @@ -90,13 +90,13 @@ describe('receipt-component', () => {
describe('buildAst', () => {
it('should build AST from renderTemplate function', () => {
const render = () => '<root></root>';
const component = new ReceiptComponent('test', {
const component = new ReceiptComponent<null>('test', {
render,
});
const ast = component.buildAst({});
const ast = component.buildAst(null);
expect(ast).toEqual({
name: 'root',
props: null,
props: {},
children: [],
});
});
Expand Down Expand Up @@ -137,21 +137,21 @@ describe('receipt-component', () => {
});
it('should register a node', () => {
ReceiptComponent.registerRenderer(dummyRendererPlugin);
ReceiptComponent.registerNode(dummyNodePlugin);
ReceiptComponent.registerNodes([dummyNodePlugin]);
expect(ReceiptComponent.astBuilders.dummyNode).toBe(
dummyNodePlugin.buildNode
);
});

it('should allow registering a node with renderers not defined on instance', () => {
ReceiptComponent.registerNode(dummyNodePlugin);
ReceiptComponent.registerNodes([dummyNodePlugin]);
expect(ReceiptComponent.astBuilders.dummyNode).toBe(
dummyNodePlugin.buildNode
);
});

it('should register aliases for a node', () => {
ReceiptComponent.registerNode(dummyNodePluginWithAlias);
ReceiptComponent.registerNodes([dummyNodePluginWithAlias]);
expect(ReceiptComponent.astBuilders.dummyNode).toBe(
dummyNodePluginWithAlias.buildNode
);
Expand All @@ -161,16 +161,16 @@ describe('receipt-component', () => {
});

it('should allow overriding a node', () => {
ReceiptComponent.registerNode(dummyNodePlugin);
ReceiptComponent.registerNode(dummyNodePluginWithAlias);
ReceiptComponent.registerNodes([dummyNodePlugin]);
ReceiptComponent.registerNodes([dummyNodePluginWithAlias]);
expect(ReceiptComponent.astBuilders.dummyNode).toBe(
dummyNodePluginWithAlias.buildNode
);
});

it('should register node renderers to installed renderers', () => {
ReceiptComponent.registerRenderer(dummyRendererPlugin);
ReceiptComponent.registerNode(dummyNodePlugin);
ReceiptComponent.registerNodes([dummyNodePlugin]);
expect(dummyRenderFuncRegistry.dummyNode).toBeDefined();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('align', () => {
bytes.ESC,
0x61,
0x00,
bytes.LF,
bytes.ESC,
0x61,
0x01,
Expand All @@ -60,6 +61,7 @@ describe('align', () => {
0x61,
0x01,
...childBytes,
bytes.LF,
bytes.ESC,
0x61,
0x00,
Expand Down
48 changes: 0 additions & 48 deletions packages/renderers/receipt-escpos-renderer/test/util/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ describe('util', () => {
});
});
describe('splitLines', () => {
it('should pad spaces to the line length', () => {
const text = 'Hello';
const lines = splitLines(text, 15, 0).join('\n');

assert(lines.length === 15);
});

it('should split the text into lines', () => {
const text = 'Hello World';
const lines = splitLines(text, 5, 0);
Expand All @@ -60,38 +53,6 @@ describe('util', () => {
expect(lines[1]?.trim()).toBe('World');
});

it('should pad spaces at the start if justify is right', () => {
const text = 'Hello World';
const lines = splitLines(text, 15, 0, 'right');

expect(lines.length).toBe(1);
expect(lines[0]).toBe('Hello World'.padStart(15, ' '));
});

it('should pad spaces at the end if justify is left', () => {
const text = 'Hello World';
const lines = splitLines(text, 15, 0, 'left');

expect(lines.length).toBe(1);
expect(lines[0]).toBe('Hello World'.padEnd(15, ' '));
});

it('should pad spaces at the start and end if justify is center', () => {
const text = 'Hello World';
const lines = splitLines(text, 15, 0, 'center');

expect(lines.length).toBe(1);
expect(lines[0]).toBe('Hello World'.padStart(13, ' ').padEnd(12, ' '));
});

it('should have extra spaces at the end if justify is center and the line length is odd', () => {
const text = 'Hello World';
const lines = splitLines(text, 14, 0, 'center');

expect(lines.length).toBe(1);
expect(lines[0]).toBe('Hello World'.padStart(12, ' ').padEnd(13, ' '));
});

it('should split text when word lengths equal line length', () => {
const text = 'Hello World';
const lines = splitLines(text, 10, 0);
Expand All @@ -108,14 +69,5 @@ describe('util', () => {
expect(lines.length).toBe(1);
expect(lines[0]?.trim()).toBe('Hello World');
});

it('should justify every line', () => {
const text = 'Hello World';
const lines = splitLines(text, 10, 0);

expect(lines.length).toBe(2);
expect(lines[0]).toBe('Hello'.padEnd(10, ' '));
expect(lines[1]).toBe('World'.padEnd(10, ' '));
});
});
});

0 comments on commit fd8483a

Please sign in to comment.