test(web): celdas de cuenta de las líneas de documento (código con formato al cargar y al escribir)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f923d98e87
commit
68d2cfe6d0
1 file changed
+48
@@ -3,6 +3,7 @@ import { HttpTestingController, provideHttpClientTesting } from '@angular/common
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { type ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { AccountCodesService } from '../../core/sl/account-codes';
|
||||
import { ITEMS_MULTI_ADD, LINE_COLUMNS, newDocumentLine, recalcLine } from '../../features/documents/line-columns';
|
||||
|
||||
/** Las ocho columnas básicas de una línea (las posiciones que usan estos tests). */
|
||||
@@ -614,3 +615,50 @@ describe('LinesGrid: dónde va la columna de lotes y series', () => {
|
||||
expect(el.querySelector('input[data-r="0"][data-c="2"]')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('LinesGrid: celdas de cuenta', () => {
|
||||
let fixture: ComponentFixture<Host>;
|
||||
let ctrl: HttpTestingController;
|
||||
let el: HTMLElement;
|
||||
const tick = async () => {
|
||||
fixture.detectChanges();
|
||||
await new Promise((r) => setTimeout(r));
|
||||
fixture.detectChanges();
|
||||
};
|
||||
const cell = () => el.querySelector<HTMLInputElement>('input[data-r="0"][data-c="1"]')!;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [Host],
|
||||
providers: [provideHttpClient(), provideHttpClientTesting()],
|
||||
}).compileComponents();
|
||||
ctrl = TestBed.inject(HttpTestingController);
|
||||
TestBed.inject(AccountCodesService); // la app lo instancia en su marco principal
|
||||
fixture = TestBed.createComponent(Host);
|
||||
el = fixture.nativeElement;
|
||||
fixture.componentInstance.columns = [LINE_COLUMNS.item, LINE_COLUMNS.account];
|
||||
});
|
||||
|
||||
it('una línea con la cuenta interna pide su código con formato y lo muestra', async () => {
|
||||
fixture.componentInstance.lines.set([{ ItemCode: 'S1', AccountCode: '_SYS00000002407' }]);
|
||||
await tick();
|
||||
const req = ctrl.expectOne((r) => r.url === '/api/sl/ChartOfAccounts' && r.params.get('$filter') === "Code eq '_SYS00000002407'");
|
||||
req.flush({ value: [{ Code: '_SYS00000002407', FormatCode: '1071111010' }] });
|
||||
await tick();
|
||||
expect(cell().value).toBe('1071111010');
|
||||
expect(fixture.componentInstance.lines()[0]['AccountCode']).toBe('_SYS00000002407'); // lo guardado sigue siendo el interno
|
||||
});
|
||||
|
||||
it('escribir el código con formato guarda el interno de la cuenta', async () => {
|
||||
fixture.componentInstance.lines.set([{ ItemCode: 'S1' }]);
|
||||
await tick();
|
||||
cell().value = '1071111010';
|
||||
cell().dispatchEvent(new Event('change'));
|
||||
await tick();
|
||||
const req = ctrl.expectOne((r) => r.url === '/api/sl/ChartOfAccounts' && (r.params.get('$filter') ?? '').includes("FormatCode eq '1071111010'"));
|
||||
req.flush({ value: [{ Code: '_SYS00000002407', FormatCode: '1071111010', Name: 'Banco' }] });
|
||||
await tick();
|
||||
expect(fixture.componentInstance.lines()[0]['AccountCode']).toBe('_SYS00000002407');
|
||||
expect(cell().value).toBe('1071111010');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user