|
23 | 23 | */ |
24 | 24 |
|
25 | 25 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
26 | | -import { Router } from '@angular/router'; |
27 | 26 | import { UserPreferencesService } from '@alfresco/adf-core'; |
28 | | -import { AlfrescoApiService } from '@alfresco/adf-content-services'; |
29 | 27 | import { FavoriteLibrariesComponent } from './favorite-libraries.component'; |
30 | 28 | import { AppTestingModule } from '../../testing/app-testing.module'; |
31 | | -import { AppHookService, ContentApiService } from '@alfresco/aca-shared'; |
| 29 | +import { AppExtensionService, AppHookService, ContentApiService } from '@alfresco/aca-shared'; |
32 | 30 | import { provideEffects } from '@ngrx/effects'; |
33 | | -import { RouterEffects } from '@alfresco/aca-shared/store'; |
34 | 31 | import { of, throwError } from 'rxjs'; |
35 | 32 | import { LibraryEffects } from '../../store/effects'; |
36 | 33 | import { NodeEntry } from '@alfresco/js-api'; |
37 | | -import { getTitleElementText } from '../../testing/test-utils'; |
38 | 34 | import { MatSnackBarModule } from '@angular/material/snack-bar'; |
39 | | -import { SiteEntry } from '@alfresco/js-api/typings'; |
| 35 | +import { libraryColumnsPresetMock, favoriteLibrariesMock, libraryPaginationMock } from '../../mock/libraries-mock'; |
40 | 36 |
|
41 | 37 | describe('FavoriteLibrariesComponent', () => { |
42 | 38 | let fixture: ComponentFixture<FavoriteLibrariesComponent>; |
43 | 39 | let component: FavoriteLibrariesComponent; |
44 | | - let alfrescoApi: AlfrescoApiService; |
45 | 40 | let userPreference: UserPreferencesService; |
46 | 41 | let contentApiService: ContentApiService; |
47 | | - let router: Router; |
48 | | - let page; |
49 | 42 | let appHookService: AppHookService; |
50 | | - |
51 | | - beforeEach(() => { |
52 | | - page = { |
53 | | - list: { |
54 | | - entries: [{ entry: { id: 1 } }, { entry: { id: 2 } }], |
55 | | - pagination: { data: 'data' } |
56 | | - } |
57 | | - }; |
58 | | - }); |
| 43 | + let appExtensionService: AppExtensionService; |
59 | 44 |
|
60 | 45 | beforeEach(() => { |
61 | 46 | TestBed.configureTestingModule({ |
62 | 47 | imports: [AppTestingModule, FavoriteLibrariesComponent, MatSnackBarModule], |
63 | | - providers: [provideEffects([RouterEffects, LibraryEffects])] |
| 48 | + providers: [provideEffects([LibraryEffects])] |
64 | 49 | }); |
65 | 50 |
|
66 | 51 | fixture = TestBed.createComponent(FavoriteLibrariesComponent); |
67 | 52 | component = fixture.componentInstance; |
68 | 53 |
|
69 | | - alfrescoApi = TestBed.inject(AlfrescoApiService); |
70 | 54 | contentApiService = TestBed.inject(ContentApiService); |
71 | 55 | userPreference = TestBed.inject(UserPreferencesService); |
72 | 56 | appHookService = TestBed.inject(AppHookService); |
73 | | - alfrescoApi.reset(); |
74 | | - router = TestBed.inject(Router); |
| 57 | + appExtensionService = TestBed.inject(AppExtensionService); |
75 | 58 |
|
76 | 59 | spyOn(contentApiService, 'getNode').and.returnValue(of({ entry: { id: 'libraryId' } } as NodeEntry)); |
77 | 60 | }); |
78 | 61 |
|
79 | | - describe('on initialization', () => { |
80 | | - it('should set data', () => { |
81 | | - spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page)); |
82 | | - fixture.detectChanges(); |
83 | | - |
84 | | - expect(component.list).toBe(page); |
85 | | - expect(component.pagination).toBe(page.list.pagination); |
86 | | - }); |
87 | | - |
88 | | - it('should get data with user preference pagination size', () => { |
89 | | - userPreference.paginationSize = 1; |
90 | | - spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page)); |
| 62 | + it('should set data', () => { |
| 63 | + spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock)); |
| 64 | + fixture.detectChanges(); |
91 | 65 |
|
92 | | - fixture.detectChanges(); |
| 66 | + expect(component.list).toBe(favoriteLibrariesMock); |
| 67 | + expect(component.pagination).toBe(favoriteLibrariesMock.list.pagination); |
| 68 | + }); |
93 | 69 |
|
94 | | - expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', { |
95 | | - maxItems: userPreference.paginationSize |
96 | | - }); |
97 | | - }); |
| 70 | + it('should get data with user preference pagination size', () => { |
| 71 | + userPreference.paginationSize = 1; |
| 72 | + spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock)); |
98 | 73 |
|
99 | | - it('should set data on error', () => { |
100 | | - spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(throwError('error')); |
101 | | - fixture.detectChanges(); |
| 74 | + fixture.detectChanges(); |
102 | 75 |
|
103 | | - expect(component.list).toBe(null); |
104 | | - expect(component.pagination).toBe(null); |
105 | | - expect(component.isLoading).toBe(false); |
| 76 | + expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', { |
| 77 | + maxItems: userPreference.paginationSize |
106 | 78 | }); |
| 79 | + }); |
107 | 80 |
|
108 | | - it('should set title based on selectedRowItemsCount', () => { |
109 | | - fixture.detectChanges(); |
110 | | - |
111 | | - expect(getTitleElementText(fixture)).toBe('APP.BROWSE.LIBRARIES.MENU.FAVORITE_LIBRARIES.TITLE'); |
| 81 | + it('should set data on error', () => { |
| 82 | + spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(throwError('error')); |
| 83 | + fixture.detectChanges(); |
112 | 84 |
|
113 | | - component.selectedRowItemsCount = 5; |
114 | | - fixture.detectChanges(); |
115 | | - |
116 | | - expect(getTitleElementText(fixture)).toBe('APP.HEADER.SELECTED'); |
117 | | - }); |
| 85 | + expect(component.list).toBe(null); |
| 86 | + expect(component.pagination).toBe(null); |
| 87 | + expect(component.isLoading).toBe(false); |
118 | 88 | }); |
119 | 89 |
|
120 | | - describe('Node navigation', () => { |
121 | | - it('does not navigate when id is not passed', () => { |
122 | | - spyOn(router, 'navigate').and.stub(); |
123 | | - component.navigateTo(null); |
124 | | - |
125 | | - expect(router.navigate).not.toHaveBeenCalled(); |
126 | | - }); |
| 90 | + it('should set columns from extensions on init', () => { |
| 91 | + appExtensionService.documentListPresets.libraries = libraryColumnsPresetMock; |
| 92 | + fixture.detectChanges(); |
| 93 | + expect(component.columns).toEqual(appExtensionService.documentListPresets.favoriteLibraries); |
| 94 | + }); |
127 | 95 |
|
128 | | - it('does not navigate when id is not passed', () => { |
129 | | - spyOn(router, 'navigate').and.stub(); |
130 | | - component.navigateTo({ |
131 | | - entry: { |
132 | | - guid: 'test-guid', |
133 | | - visibility: 'PUBLIC', |
134 | | - role: 'SiteConsumer' |
135 | | - } |
136 | | - } as SiteEntry); |
137 | | - |
138 | | - expect(router.navigate).toHaveBeenCalledWith(['favorite/libraries', 'libraryId']); |
139 | | - }); |
| 96 | + it('should handle no columns preset in extensions', () => { |
| 97 | + appExtensionService.documentListPresets.favoriteLibraries = undefined; |
| 98 | + component.ngOnInit(); |
| 99 | + expect(component.columns.length).toBe(0); |
140 | 100 | }); |
141 | 101 |
|
142 | | - describe('Reload on actions', () => { |
| 102 | + describe('Library hooks', () => { |
143 | 103 | beforeEach(() => { |
144 | | - spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page)); |
| 104 | + spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock)); |
145 | 105 | fixture.detectChanges(); |
146 | 106 | }); |
147 | 107 |
|
148 | | - it('should reload on libraryDeleted action', () => { |
| 108 | + it('should reload on libraryDeleted hook', () => { |
149 | 109 | appHookService.libraryDeleted.next(''); |
150 | 110 | expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled(); |
151 | 111 | }); |
152 | 112 |
|
153 | | - it('should reload on libraryUpdated action', () => { |
| 113 | + it('should reload on libraryUpdated hook', () => { |
154 | 114 | appHookService.libraryUpdated.next({} as any); |
155 | 115 | expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled(); |
156 | 116 | }); |
157 | 117 |
|
158 | | - it('should reload on favoriteLibraryToggle action', () => { |
| 118 | + it('should reload on favoriteLibraryToggle hook', () => { |
159 | 119 | appHookService.favoriteLibraryToggle.next(); |
160 | 120 | expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled(); |
161 | 121 | }); |
162 | 122 |
|
163 | | - it('should reload on libraryJoined action', () => { |
| 123 | + it('should reload on libraryJoined hook', () => { |
164 | 124 | appHookService.libraryJoined.next(); |
165 | 125 | expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled(); |
166 | 126 | }); |
167 | 127 |
|
168 | | - it('should reload on libraryLeft action', () => { |
| 128 | + it('should reload on libraryLeft hook', () => { |
169 | 129 | appHookService.libraryLeft.next({} as any); |
170 | 130 | expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled(); |
171 | 131 | }); |
172 | 132 | }); |
173 | 133 |
|
174 | 134 | describe('Pagination', () => { |
175 | | - let pagination; |
176 | | - |
177 | | - beforeEach(() => { |
178 | | - pagination = { |
179 | | - count: 100, |
180 | | - hasMoreItems: true, |
181 | | - totalItems: 300, |
182 | | - skipCount: 25, |
183 | | - maxItems: 25 |
184 | | - }; |
185 | | - }); |
186 | | - |
187 | | - it('should get list with pagination data onChange event', () => { |
188 | | - spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page)); |
189 | | - |
190 | | - component.onChange(pagination); |
191 | | - |
192 | | - expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', pagination); |
193 | | - }); |
194 | | - |
195 | 135 | it('should get list with pagination data onChangePageSize event', () => { |
196 | | - spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page)); |
| 136 | + spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock)); |
197 | 137 |
|
198 | | - component.onChangePageSize(pagination); |
| 138 | + component.onChangePageSize(libraryPaginationMock); |
199 | 139 |
|
200 | | - expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', pagination); |
| 140 | + expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', libraryPaginationMock); |
201 | 141 | }); |
202 | 142 |
|
203 | 143 | it('should set preference page size onChangePageSize event', () => { |
204 | | - spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page)); |
| 144 | + spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock)); |
205 | 145 |
|
206 | | - component.onChangePageSize(pagination); |
| 146 | + component.onChangePageSize(libraryPaginationMock); |
207 | 147 |
|
208 | | - expect(userPreference.paginationSize).toBe(pagination.maxItems); |
| 148 | + expect(userPreference.paginationSize).toBe(libraryPaginationMock.maxItems); |
209 | 149 | }); |
210 | 150 | }); |
211 | 151 | }); |
0 commit comments