|
| 1 | +import { FeedbackDataService } from './feedback-data.service'; |
| 2 | +import { HALLink } from '../shared/hal-link.model'; |
| 3 | +import { Item } from '../shared/item.model'; |
| 4 | +import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub'; |
| 5 | +import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; |
| 6 | +import { getMockRequestService } from '../../shared/mocks/request.service.mock'; |
| 7 | +import { NotificationsService } from '../../shared/notifications/notifications.service'; |
| 8 | +import { HttpClient } from '@angular/common/http'; |
| 9 | +import { Store } from '@ngrx/store'; |
| 10 | +import { CoreState } from '../core.reducers'; |
| 11 | +import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service'; |
| 12 | +import { Feedback } from './models/feedback.model'; |
| 13 | + |
| 14 | +describe('FeedbackDataService', () => { |
| 15 | + let service: FeedbackDataService; |
| 16 | + let requestService; |
| 17 | + let halService; |
| 18 | + let rdbService; |
| 19 | + let notificationsService; |
| 20 | + let http; |
| 21 | + let comparator; |
| 22 | + let objectCache; |
| 23 | + let store; |
| 24 | + let item; |
| 25 | + let bundleLink; |
| 26 | + let bundleHALLink; |
| 27 | + |
| 28 | + const feedbackPayload = Object.assign(new Feedback(), { |
| 29 | + |
| 30 | + message: 'message', |
| 31 | + page: '/home' |
| 32 | + }); |
| 33 | + |
| 34 | + |
| 35 | + function initTestService(): FeedbackDataService { |
| 36 | + bundleLink = '/items/0fdc0cd7-ff8c-433d-b33c-9b56108abc07/bundles'; |
| 37 | + bundleHALLink = new HALLink(); |
| 38 | + bundleHALLink.href = bundleLink; |
| 39 | + item = new Item(); |
| 40 | + item._links = { |
| 41 | + bundles: bundleHALLink |
| 42 | + }; |
| 43 | + requestService = getMockRequestService(); |
| 44 | + halService = new HALEndpointServiceStub('url') as any; |
| 45 | + rdbService = {} as RemoteDataBuildService; |
| 46 | + notificationsService = {} as NotificationsService; |
| 47 | + http = {} as HttpClient; |
| 48 | + comparator = new DSOChangeAnalyzer() as any; |
| 49 | + objectCache = { |
| 50 | + |
| 51 | + addPatch: () => { |
| 52 | + /* empty */ |
| 53 | + }, |
| 54 | + getObjectBySelfLink: () => { |
| 55 | + /* empty */ |
| 56 | + } |
| 57 | + } as any; |
| 58 | + store = {} as Store<CoreState>; |
| 59 | + return new FeedbackDataService( |
| 60 | + requestService, |
| 61 | + rdbService, |
| 62 | + store, |
| 63 | + objectCache, |
| 64 | + halService, |
| 65 | + notificationsService, |
| 66 | + http, |
| 67 | + comparator, |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + beforeEach(() => { |
| 73 | + service = initTestService(); |
| 74 | + }); |
| 75 | + |
| 76 | + |
| 77 | + describe('getFeedback', () => { |
| 78 | + beforeEach(() => { |
| 79 | + spyOn(service, 'getFeedback'); |
| 80 | + service.getFeedback('3'); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should call getFeedback with the feedback link', () => { |
| 84 | + expect(service.getFeedback).toHaveBeenCalledWith('3'); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | +}); |
0 commit comments