Fix: get highest ASN regardless of user (#4326)

This commit is contained in:
shamoon
2023-10-06 17:22:31 -07:00
committed by GitHub
parent 826426424f
commit b34104ef90
6 changed files with 75 additions and 45 deletions

View File

@@ -30,39 +30,9 @@ describe('NumberComponent', () => {
input = component.inputField.nativeElement
})
// TODO: why doesnt this work?
// it('should support use of input field', () => {
// expect(component.value).toBeUndefined()
// input.stepUp()
// console.log(input.value);
// input.dispatchEvent(new Event('change'))
// fixture.detectChanges()
// expect(component.value).toEqual('3')
// })
it('should support +1 ASN', () => {
const listAllSpy = jest.spyOn(documentService, 'listFiltered')
listAllSpy
.mockReturnValueOnce(
of({
count: 1,
all: [1],
results: [
{
id: 1,
archive_serial_number: 1000,
},
],
})
)
.mockReturnValueOnce(
of({
count: 0,
all: [],
results: [],
})
)
const nextAsnSpy = jest.spyOn(documentService, 'getNextAsn')
nextAsnSpy.mockReturnValueOnce(of(1001)).mockReturnValueOnce(of(1))
expect(component.value).toBeUndefined()
component.nextAsn()
expect(component.value).toEqual(1001)

View File

@@ -1,6 +1,5 @@
import { Component, forwardRef, Input } from '@angular/core'
import { NG_VALUE_ACCESSOR } from '@angular/forms'
import { FILTER_ASN_ISNULL } from 'src/app/data/filter-rule-type'
import { DocumentService } from 'src/app/services/rest/document.service'
import { AbstractInputComponent } from '../abstract-input'
@@ -28,17 +27,9 @@ export class NumberComponent extends AbstractInputComponent<number> {
if (this.value) {
return
}
this.documentService
.listFiltered(1, 1, 'archive_serial_number', true, [
{ rule_type: FILTER_ASN_ISNULL, value: 'false' },
])
.subscribe((results) => {
if (results.count > 0) {
this.value = results.results[0].archive_serial_number + 1
} else {
this.value = 1
}
this.onChange(this.value)
})
this.documentService.getNextAsn().subscribe((nextAsn) => {
this.value = nextAsn
this.onChange(this.value)
})
}
}