Update tests
This commit is contained in:
parent
d157eeae6a
commit
bf90e6f858
@ -254,9 +254,6 @@ describe('DocumentDetailComponent', () => {
|
|||||||
|
|
||||||
router = TestBed.inject(Router)
|
router = TestBed.inject(Router)
|
||||||
activatedRoute = TestBed.inject(ActivatedRoute)
|
activatedRoute = TestBed.inject(ActivatedRoute)
|
||||||
jest
|
|
||||||
.spyOn(activatedRoute, 'paramMap', 'get')
|
|
||||||
.mockReturnValue(of(convertToParamMap({ id: 3 })))
|
|
||||||
openDocumentsService = TestBed.inject(OpenDocumentsService)
|
openDocumentsService = TestBed.inject(OpenDocumentsService)
|
||||||
documentService = TestBed.inject(DocumentService)
|
documentService = TestBed.inject(DocumentService)
|
||||||
modalService = TestBed.inject(NgbModal)
|
modalService = TestBed.inject(NgbModal)
|
||||||
@ -294,6 +291,17 @@ describe('DocumentDetailComponent', () => {
|
|||||||
expect(navigateSpy).toHaveBeenCalledWith(['documents', 3, 'notes'])
|
expect(navigateSpy).toHaveBeenCalledWith(['documents', 3, 'notes'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should forward id without section to details', () => {
|
||||||
|
const navigateSpy = jest.spyOn(router, 'navigate')
|
||||||
|
jest
|
||||||
|
.spyOn(activatedRoute, 'paramMap', 'get')
|
||||||
|
.mockReturnValue(of(convertToParamMap({ id: 3 })))
|
||||||
|
fixture.detectChanges()
|
||||||
|
expect(navigateSpy).toHaveBeenCalledWith(['documents', 3, 'details'], {
|
||||||
|
replaceUrl: true,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('should update title after debounce', fakeAsync(() => {
|
it('should update title after debounce', fakeAsync(() => {
|
||||||
initNormally()
|
initNormally()
|
||||||
component.titleInput.value = 'Foo Bar'
|
component.titleInput.value = 'Foo Bar'
|
||||||
@ -319,6 +327,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should load already-opened document via param', () => {
|
it('should load already-opened document via param', () => {
|
||||||
|
initNormally()
|
||||||
jest.spyOn(documentService, 'get').mockReturnValueOnce(of(doc))
|
jest.spyOn(documentService, 'get').mockReturnValueOnce(of(doc))
|
||||||
jest.spyOn(openDocumentsService, 'getOpenDocument').mockReturnValue(doc)
|
jest.spyOn(openDocumentsService, 'getOpenDocument').mockReturnValue(doc)
|
||||||
jest.spyOn(customFieldsService, 'listAll').mockReturnValue(
|
jest.spyOn(customFieldsService, 'listAll').mockReturnValue(
|
||||||
@ -399,8 +408,11 @@ describe('DocumentDetailComponent', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should 404 on invalid id', () => {
|
it('should 404 on invalid id', () => {
|
||||||
jest.spyOn(documentService, 'get').mockReturnValueOnce(of(null))
|
|
||||||
const navigateSpy = jest.spyOn(router, 'navigate')
|
const navigateSpy = jest.spyOn(router, 'navigate')
|
||||||
|
jest
|
||||||
|
.spyOn(activatedRoute, 'paramMap', 'get')
|
||||||
|
.mockReturnValue(of(convertToParamMap({ id: 999, section: 'details' })))
|
||||||
|
jest.spyOn(documentService, 'get').mockReturnValueOnce(of(null))
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(navigateSpy).toHaveBeenCalledWith(['404'], { replaceUrl: true })
|
expect(navigateSpy).toHaveBeenCalledWith(['404'], { replaceUrl: true })
|
||||||
})
|
})
|
||||||
@ -935,7 +947,29 @@ describe('DocumentDetailComponent', () => {
|
|||||||
expect(refreshSpy).toHaveBeenCalled()
|
expect(refreshSpy).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should get suggestions', () => {
|
||||||
|
const suggestionsSpy = jest.spyOn(documentService, 'getSuggestions')
|
||||||
|
suggestionsSpy.mockReturnValue(of({ tags: [1, 2] }))
|
||||||
|
initNormally()
|
||||||
|
expect(suggestionsSpy).toHaveBeenCalled()
|
||||||
|
expect(component.suggestions).toEqual({ tags: [1, 2] })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should show error if needed for get suggestions', () => {
|
||||||
|
const suggestionsSpy = jest.spyOn(documentService, 'getSuggestions')
|
||||||
|
const errorSpy = jest.spyOn(toastService, 'showError')
|
||||||
|
suggestionsSpy.mockImplementationOnce(() =>
|
||||||
|
throwError(() => new Error('failed to get suggestions'))
|
||||||
|
)
|
||||||
|
initNormally()
|
||||||
|
expect(suggestionsSpy).toHaveBeenCalled()
|
||||||
|
expect(errorSpy).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
function initNormally() {
|
function initNormally() {
|
||||||
|
jest
|
||||||
|
.spyOn(activatedRoute, 'paramMap', 'get')
|
||||||
|
.mockReturnValue(of(convertToParamMap({ id: 3, section: 'details' })))
|
||||||
jest
|
jest
|
||||||
.spyOn(documentService, 'get')
|
.spyOn(documentService, 'get')
|
||||||
.mockReturnValueOnce(of(Object.assign({}, doc)))
|
.mockReturnValueOnce(of(Object.assign({}, doc)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user