@@ -113,7 +113,7 @@ const restored = {
|
||||
],
|
||||
};
|
||||
|
||||
function render(userId = 7, tenantId = 3) {
|
||||
function render(userId = 7, tenantId = 3, errors: Record<string, string> = {}) {
|
||||
return renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={RequisitionForm}
|
||||
@@ -124,7 +124,7 @@ function render(userId = 7, tenantId = 3) {
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
errors,
|
||||
auth: { user: { id: userId, tenant_id: tenantId } },
|
||||
internalRequisitionReady: true,
|
||||
incompleteDraftsAvailable: true,
|
||||
@@ -145,6 +145,27 @@ test('native remembered history restores unfinished fields and line values witho
|
||||
expect(html).toContain('Artigo ainda por gravar');
|
||||
expect(html).toContain('value="2.000"');
|
||||
expect(html).not.toContain('value="0.00"');
|
||||
expect(html).toContain('Por completar');
|
||||
expect(html).toContain('data-preparation-dirty="true"');
|
||||
});
|
||||
|
||||
test('the native form displays the exact half-cent estimate from remembered decimal inputs', () => {
|
||||
vi.spyOn(router, 'restore').mockImplementation((key) =>
|
||||
key === 'requisition:3:7:new:0:data'
|
||||
? {
|
||||
...restored,
|
||||
items: [
|
||||
{
|
||||
...restored.items[0],
|
||||
quantity: '0.29',
|
||||
unit_price: '0.50',
|
||||
tax_rate: '0',
|
||||
},
|
||||
],
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
expect(render()).toContain('0,15 MZN');
|
||||
});
|
||||
|
||||
test('remembered preparation is separated by user and company', () => {
|
||||
@@ -152,5 +173,34 @@ test('remembered preparation is separated by user and company', () => {
|
||||
key === 'requisition:3:7:new:0:data' ? restored : undefined,
|
||||
);
|
||||
expect(render(8, 3)).not.toContain('Artigo ainda por gravar');
|
||||
expect(render(8, 3)).toContain('data-preparation-dirty="false"');
|
||||
expect(render(7, 4)).not.toContain('Artigo ainda por gravar');
|
||||
});
|
||||
|
||||
test('native validation links address the restored line and retain process errors without a false field destination', () => {
|
||||
const errors = {
|
||||
'items.0.quantity': 'Corrija a quantidade',
|
||||
'items.0.equipment_id': 'Confira o equipamento',
|
||||
cost_center_id: 'Escolha o centro',
|
||||
process_version: 'Actualize a versão',
|
||||
};
|
||||
vi.spyOn(router, 'restore').mockImplementation((key) =>
|
||||
key === 'requisition:3:7:new:0:data'
|
||||
? restored
|
||||
: key === 'requisition:3:7:new:0:errors'
|
||||
? errors
|
||||
: undefined,
|
||||
);
|
||||
const html = render(7, 3, errors);
|
||||
expect(html).toContain('href="#quantity-kept-line"');
|
||||
expect(html).toContain('id="quantity-kept-line"');
|
||||
expect(html).toContain('href="#requisition-line-kept-line"');
|
||||
expect(html).toContain('id="requisition-line-kept-line"');
|
||||
expect(html).toContain('href="#cost-center"');
|
||||
expect(html).toContain('aria-describedby="error-items.0.quantity"');
|
||||
expect(html).toContain('id="error-items.0.quantity"');
|
||||
expect(html).toContain('id="error-items.0.equipment_id"');
|
||||
expect(html).toContain('id="error-cost_center_id"');
|
||||
expect(html).not.toContain('href="#process_version"');
|
||||
expect(html).toContain('Actualize a versão');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user