cat-documents-ng 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/{src/Shared/constant/ERROR.ts → Shared/constant/ERROR.d.ts} +43 -38
  2. package/Shared/constant/PERMISSIONS.d.ts +20 -0
  3. package/Shared/constant/SHARED.d.ts +215 -0
  4. package/{src/Shared/constant/URLS.ts → Shared/constant/URLS.d.ts} +60 -65
  5. package/Shared/services/app-config.service.d.ts +51 -0
  6. package/{src/Shared/services/global-error.handler.ts → Shared/services/global-error.handler.d.ts} +27 -29
  7. package/Shared/services/session.service.d.ts +46 -0
  8. package/fesm2022/cat-documents-ng.mjs +2623 -0
  9. package/fesm2022/cat-documents-ng.mjs.map +1 -0
  10. package/index.d.ts +5 -0
  11. package/lib/document/components/document-container/document-container.component.d.ts +101 -0
  12. package/lib/document/components/document-list/document-list.component.d.ts +193 -0
  13. package/lib/document/components/document-list-item/document-list-item.component.d.ts +28 -0
  14. package/lib/document/components/document-upload/document-upload.component.d.ts +120 -0
  15. package/lib/document/components/document-viewer/document-viewer.component.d.ts +77 -0
  16. package/{src/lib/document/components/folder-block/folder-block.component.ts → lib/document/components/folder-block/folder-block.component.d.ts} +37 -53
  17. package/lib/document/components/folder-container/folder-container.component.d.ts +29 -0
  18. package/lib/document/components/linked-document/linked-document.component.d.ts +38 -0
  19. package/lib/document/directives/document.directive.d.ts +20 -0
  20. package/lib/document/directives/permission.directive.d.ts +38 -0
  21. package/lib/document/document.module.d.ts +40 -0
  22. package/{src/lib/document/models/document-alert.model.ts → lib/document/models/document-alert.model.d.ts} +38 -45
  23. package/lib/document/models/document-type.model.d.ts +37 -0
  24. package/lib/document/models/document.model.d.ts +44 -0
  25. package/{src/lib/document/models/folder.model.ts → lib/document/models/folder.model.d.ts} +29 -35
  26. package/lib/document/services/document-http.service.d.ts +69 -0
  27. package/lib/document/services/document-upload.service.d.ts +67 -0
  28. package/lib/document/services/document.service.d.ts +20 -0
  29. package/lib/document/services/file-format.service.d.ts +23 -0
  30. package/lib/document/state/document.query.d.ts +50 -0
  31. package/{src/lib/document/state/document.service.ts → lib/document/state/document.service.d.ts} +64 -95
  32. package/{src/lib/document/state/document.state.ts → lib/document/state/document.state.d.ts} +36 -52
  33. package/lib/document/state/document.store.d.ts +29 -0
  34. package/package.json +25 -20
  35. package/{src/public-api.ts → public-api.d.ts} +6 -10
  36. package/ng-package.json +0 -11
  37. package/src/Shared/constant/PERMISSIONS.ts +0 -16
  38. package/src/Shared/constant/SHARED.ts +0 -312
  39. package/src/Shared/services/app-config.service.spec.ts +0 -19
  40. package/src/Shared/services/app-config.service.ts +0 -73
  41. package/src/Shared/services/session.service.spec.ts +0 -16
  42. package/src/Shared/services/session.service.ts +0 -76
  43. package/src/assets/config/api.config.json +0 -20
  44. package/src/lib/document/components/document-container/document-container.component.html +0 -14
  45. package/src/lib/document/components/document-container/document-container.component.scss +0 -8
  46. package/src/lib/document/components/document-container/document-container.component.spec.ts +0 -110
  47. package/src/lib/document/components/document-container/document-container.component.ts +0 -173
  48. package/src/lib/document/components/document-list/document-list.component.html +0 -81
  49. package/src/lib/document/components/document-list/document-list.component.scss +0 -82
  50. package/src/lib/document/components/document-list/document-list.component.spec.ts +0 -96
  51. package/src/lib/document/components/document-list/document-list.component.ts +0 -244
  52. package/src/lib/document/components/document-list-item/document-list-item.component.html +0 -36
  53. package/src/lib/document/components/document-list-item/document-list-item.component.scss +0 -34
  54. package/src/lib/document/components/document-list-item/document-list-item.component.spec.ts +0 -75
  55. package/src/lib/document/components/document-list-item/document-list-item.component.ts +0 -40
  56. package/src/lib/document/components/document-upload/document-upload.component.html +0 -56
  57. package/src/lib/document/components/document-upload/document-upload.component.scss +0 -32
  58. package/src/lib/document/components/document-upload/document-upload.component.spec.ts +0 -95
  59. package/src/lib/document/components/document-upload/document-upload.component.ts +0 -162
  60. package/src/lib/document/components/document-viewer/document-viewer.component.html +0 -98
  61. package/src/lib/document/components/document-viewer/document-viewer.component.scss +0 -54
  62. package/src/lib/document/components/document-viewer/document-viewer.component.spec.ts +0 -79
  63. package/src/lib/document/components/document-viewer/document-viewer.component.ts +0 -106
  64. package/src/lib/document/components/folder-block/folder-block.component.html +0 -46
  65. package/src/lib/document/components/folder-block/folder-block.component.scss +0 -9
  66. package/src/lib/document/components/folder-block/folder-block.component.spec.ts +0 -70
  67. package/src/lib/document/components/folder-container/folder-container.component.html +0 -2
  68. package/src/lib/document/components/folder-container/folder-container.component.scss +0 -0
  69. package/src/lib/document/components/folder-container/folder-container.component.spec.ts +0 -27
  70. package/src/lib/document/components/folder-container/folder-container.component.ts +0 -37
  71. package/src/lib/document/components/linked-document/linked-document.component.html +0 -23
  72. package/src/lib/document/components/linked-document/linked-document.component.scss +0 -10
  73. package/src/lib/document/components/linked-document/linked-document.component.spec.ts +0 -61
  74. package/src/lib/document/components/linked-document/linked-document.component.ts +0 -49
  75. package/src/lib/document/directives/document.directive.ts +0 -32
  76. package/src/lib/document/directives/permission.directive.spec.ts +0 -0
  77. package/src/lib/document/directives/permission.directive.ts +0 -66
  78. package/src/lib/document/document.module.ts +0 -241
  79. package/src/lib/document/models/document-type.model.ts +0 -44
  80. package/src/lib/document/models/document.model.ts +0 -53
  81. package/src/lib/document/services/document-http.service.spec.ts +0 -119
  82. package/src/lib/document/services/document-http.service.ts +0 -125
  83. package/src/lib/document/services/document-upload.service.spec.ts +0 -99
  84. package/src/lib/document/services/document-upload.service.ts +0 -127
  85. package/src/lib/document/services/document.service.ts +0 -29
  86. package/src/lib/document/services/file-format.service.spec.ts +0 -16
  87. package/src/lib/document/services/file-format.service.ts +0 -41
  88. package/src/lib/document/state/document.query.ts +0 -52
  89. package/src/lib/document/state/document.store.ts +0 -51
  90. package/tsconfig.lib.json +0 -15
  91. package/tsconfig.lib.prod.json +0 -11
  92. package/tsconfig.spec.json +0 -15
@@ -1,312 +0,0 @@
1
- /**
2
- * The `SHARED` class contains shared constants used across the application.
3
- * These constants are related to document statuses and other shared data.
4
- */
5
- export class SHARED {
6
-
7
- /**
8
- * Represents the stores userData.
9
- */
10
- static SESSIONKEY = 'userData';
11
- /**
12
- * Represents the count of missing files.
13
- */
14
- static MISSINGCOUNT = 2;
15
-
16
- /**
17
- * Represents the count of pending files.
18
- */
19
- static PENDINGCOUNT = 3;
20
-
21
- /**
22
- * Represents an empty string.
23
- */
24
- static EMPTY = "";
25
-
26
- /**
27
- * Represents an true.
28
- * @static
29
- * @type {boolean}
30
- */
31
- static TRUE: boolean = true;
32
-
33
-
34
- /**
35
- * Represents an false.
36
- * @static
37
- * @type {boolean}
38
- */
39
- static FALSE: boolean = false;
40
-
41
- /**
42
- * Represents an INITIAL_COUNT.
43
- */
44
- static INITIAL_COUNT = 0
45
- /**
46
- * Represents an INITIAL_VALUE.
47
- */
48
- static INITIAL_VALUE = 0
49
-
50
- /**
51
- * Represents the constant value for one (1).
52
- * @static
53
- * @type {number}
54
- */
55
- static ONE: number = 1
56
-
57
- /**
58
- * Represents the constant value for two (2).
59
- * @static
60
- * @type {number}
61
- */
62
- static TWO: number = 2
63
-
64
- /**
65
- * Represents the constant value for ten (10).
66
- * @static
67
- * @type {number}
68
- */
69
- static TEN: number = 10
70
-
71
- /**
72
- * Represents the constant string value 'files' used for file-related operations.
73
- * @static
74
- * @type {string}
75
- */
76
- static FILE: string = 'file';
77
-
78
- /**
79
- * Represents the array of file size units ('B', 'KB', 'MB') used for file size formatting.
80
- * @static
81
- * @type {string[]}
82
- */
83
- static FILE_SIZE_UNITS: string[] = ['B', 'KB', 'MB'];
84
-
85
- /**
86
- * Show SEVERITY value.
87
- * @static
88
- * @type {'error'}
89
- */
90
- static SEVERITY:string = 'error'
91
- /**
92
- * Show SEVERITY value.
93
- * @static
94
- * @type {'error'}
95
- */
96
- static SUCCESS_SEVERITY:string = 'success'
97
-
98
- /**
99
- * Show upload summery if it's failed.
100
- * @static
101
- * @type {'Upload Failed'}
102
- */
103
- static UPLOAD_SUMMERY:string = 'Upload Failed'
104
-
105
- /**
106
- * Show upload summery if it's success.
107
- * @static
108
- * @type {'Document uploaded successfully.'}
109
- */
110
- static UPLOAD_SUCCESS:string = 'Document uploaded successfully.'
111
-
112
- /**
113
- * Represent empty array.
114
- * @static
115
- * @type {{}}
116
- */
117
- static EMPTY_ARRAY = []
118
-
119
- /**
120
- * Represent contextId.
121
- * @static
122
- * @type {string}
123
- */
124
- static CONTEXT_ID : string = 'contextId'
125
-
126
- /**
127
- * Represent fileSize.
128
- * @static
129
- * @type {string}
130
- */
131
- static FILE_SIZE : string = 'fileSize'
132
- /**
133
- * Represent documentName.
134
- * @static
135
- * @type {string}
136
- */
137
- static DOCUMENT_NAME : string = 'documentName'
138
- /**
139
- * Represent documentTypeId.
140
- * @static
141
- * @type {string}
142
- */
143
- static DOCUMENT_TYPE_ID : string = 'documentTypeId'
144
-
145
- /**
146
- * Represent upload summery.
147
- * @static
148
- * @type {string}
149
- */
150
- static UPLOAD_ERROR_SUMMERY : string = 'Form Data Missing'
151
-
152
- /**
153
- * Represent upload error details.
154
- * @static
155
- * @type {string}
156
- */
157
- static UPLOAD_ERROR_DETAILS : string = 'Required form data is missing. Please ensure the document and all required fields are provided.'
158
-
159
- /**
160
- * Represents the message prefix for a successful document name update.
161
- * @static
162
- * @type {string}
163
- */
164
- static UPDATE_DOCUMENT_NAME :string = 'Document name updated for ID:'
165
- }
166
-
167
- /**
168
- * `DUMMYDOCUMENTLIST` is a mock list of document objects used for testing and development purposes.
169
- * Each document includes an ID, file name, status, and document URL.
170
- */
171
- export const DUMMYDOCUMENTLIST = [
172
- {
173
- _id: 1,
174
- fileName: 'Document 1',
175
- status: 'pending',
176
- documentUrl: 'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf',
177
- },
178
- {
179
- _id: 2,
180
- fileName: 'Document 2',
181
- status: 'verified',
182
- documentUrl: 'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf',
183
- },
184
- {
185
- _id: 3,
186
- fileName: 'Document 3',
187
- status: 'sentReminder',
188
- documentUrl: 'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf',
189
- },
190
- {
191
- _id: 4,
192
- fileName: 'Document 4',
193
- status: 'pending',
194
- documentUrl: 'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf',
195
- },
196
- ];
197
-
198
- /**
199
- * `FOLDERPANEL` is a mock list of folder data representing various folders in the application.
200
- * Each folder contains an ID, file count, text description, missing files count, and pending files count.
201
- */
202
- export const FOLDERPANEL = [
203
- {
204
- _id: 'folder1',
205
- fileCount: 10,
206
- text: 'Documents',
207
- missingFiles: 3,
208
- pendingFiles: 2,
209
- },
210
- {
211
- _id: 'folder2',
212
- fileCount: 5,
213
- text: 'Images',
214
- missingFiles: 0,
215
- pendingFiles: 1,
216
- },
217
- {
218
- _id: 'folder3',
219
- fileCount: 20,
220
- text: 'Reports',
221
- missingFiles: 5,
222
- pendingFiles: 0,
223
- },
224
- {
225
- _id: 'folder4',
226
- fileCount: 8,
227
- text: 'Videos',
228
- missingFiles: 0,
229
- pendingFiles: 0,
230
- },
231
- {
232
- _id: 'folder5',
233
- fileCount: 15,
234
- text: 'Archives',
235
- missingFiles: 1,
236
- pendingFiles: 3,
237
- }
238
- ];
239
-
240
- /**
241
- * Dummy data for sumaery.
242
- * @type {{}}
243
- */
244
- export const DUMMYSUMMARY = [
245
- {
246
- status: 'Valuation report requested on 10th Oct 2024',
247
- date: '15/10/2020 10:30',
248
- icon: 'pi pi-shopping-cart',
249
- color: '#9C27B0',
250
- image: 'game-controller.jpg',
251
- },
252
- {
253
- status: 'Valuation report received on 13th Oct 2024',
254
- date: '15/10/2020 14:00',
255
- icon: 'pi pi-cog',
256
- color: '#673AB7',
257
- },
258
- {
259
- status: 'Waiting for Valuation Report to be accepted',
260
- date: '15/10/2020 16:15',
261
- icon: 'pi pi-shopping-cart',
262
- color: '#FF9800',
263
- },
264
- ];
265
-
266
- /**
267
- * Dummy data for list box.
268
- * @type {{}}
269
- */
270
- export const COUNTRIES = [
271
- { name: 'Any Word', code: 'NY', checked: false },
272
- { name: 'Case Sensitive', code: 'RM', checked: false },
273
- { name: 'Wildcard Search', code: 'LDN', checked: false },
274
- { name: 'Whole Word Only', code: 'IST', checked: false },
275
- ];
276
-
277
- /**
278
- * Default supported image types.
279
- * @type {{}}
280
- */
281
- export const SUPPORTED_IMAGE_TYPES = [
282
- 'image/png'
283
- ];
284
-
285
- /**
286
- * @constant {Array<{label: string, value: string, files: string[]}>} DOCUMENTTYPES
287
- * An array of document type objects containing labels, values, and associated files.
288
- */
289
-
290
- export const DOCUMENTTYPES= [
291
- {
292
- label: "BankStatement",
293
- value: "bank_statement",
294
- },
295
- {
296
- label: "Payslip",
297
- value: "payslip",
298
- },
299
- {
300
- label: "Selfie",
301
- value: "selfie",
302
- },
303
- {
304
- label: "Other",
305
- value: "other",
306
- }
307
- ];
308
-
309
- export const DocumentAlertList = [
310
- { status: 'Pending', isAlert: true, alertMessage: 'The name on the payslip does not match either the driver name or the policyholder name.' },
311
- { status: 'Verified', isAlert: false, alertMessage: 'Document is verified successfully.' },
312
- ];
@@ -1,19 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
-
3
- import { AppConfigService } from './app-config.service';
4
- import { HttpClientModule } from '@angular/common/http';
5
-
6
- describe('AppConfigService', () => {
7
- let service: AppConfigService;
8
-
9
- beforeEach(() => {
10
- TestBed.configureTestingModule({
11
- imports: [HttpClientModule],
12
- });
13
- service = TestBed.inject(AppConfigService);
14
- });
15
-
16
- it('should be created', () => {
17
- expect(service).toBeTruthy();
18
- });
19
- });
@@ -1,73 +0,0 @@
1
- import { HttpClient } from '@angular/common/http';
2
- import { Injectable } from '@angular/core';
3
- import { firstValueFrom } from 'rxjs';
4
- import { URLS } from '../constant/URLS';
5
-
6
- /**
7
- * Service that handles loading and providing configuration settings for the application.
8
- * It fetches configuration data from a remote server and exposes various configuration options.
9
- * @class AppConfigService
10
- * @typedef {AppConfigService}
11
- */
12
- @Injectable({
13
- providedIn: 'root'
14
- })
15
- export class AppConfigService {
16
-
17
- /**
18
- * Holds the configuration data loaded from the server.
19
- * @private
20
- * @type {*}
21
- */
22
- private appConfig: any;
23
-
24
- /**
25
- * Creates an instance of AppConfigService.
26
- * Initializes the HttpClient for making HTTP requests.
27
- * @class
28
- * @param {HttpClient} http - The HttpClient service used for making HTTP requests.
29
- */
30
- constructor(private http: HttpClient) {}
31
-
32
- /**
33
- * Loads the application configuration from the server by making an HTTP request to the configuration URL.
34
- * This method retrieves the configuration data and assigns it to the appConfig property.
35
- * @async
36
- * @returns {*}
37
- */
38
- async loadAppConfig() {
39
- try {
40
- this.appConfig = await firstValueFrom(this.http.get(URLS.CONFIGFILEURL));
41
- } catch (error) {
42
- throw new Error("Api url is missing.")
43
- }
44
- }
45
-
46
-
47
- /**
48
- * Returns the base URL for the API from the loaded configuration.
49
- * @readonly
50
- * @type {*}
51
- */
52
- get apiBaseUrl() {
53
- return this.appConfig?.documentApiUrl;
54
- }
55
-
56
- /**
57
- * Returns the local server API URL from the loaded configuration.
58
- * @readonly
59
- * @type {*}
60
- */
61
- get localServerApi() {
62
- return this.appConfig?.localServerApi;
63
- }
64
-
65
- /**
66
- * Returns the visibility options from the loaded configuration.
67
- * @readonly
68
- * @type {*}
69
- */
70
- get visibilityOptions() {
71
- return this.appConfig?.visibilityOption;
72
- }
73
- }
@@ -1,16 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
-
3
- import { SessionService } from './session.service';
4
-
5
- describe('SessionService', () => {
6
- let service: SessionService;
7
-
8
- beforeEach(() => {
9
- TestBed.configureTestingModule({});
10
- service = TestBed.inject(SessionService);
11
- });
12
-
13
- it('should be created', () => {
14
- expect(service).toBeTruthy();
15
- });
16
- });
@@ -1,76 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { Router } from '@angular/router';
3
- import { SHARED } from '../constant/SHARED';
4
-
5
- /**
6
- * Service for managing user session details.
7
- * @class SessionService
8
- * @typedef {SessionService}
9
- */
10
- @Injectable({
11
- providedIn: 'root'
12
- })
13
- export class SessionService {
14
-
15
- /**
16
- * Creates an instance of SessionService.
17
- * @param {Router} router - Angular Router for navigation.
18
- */
19
- constructor(public router: Router) {}
20
-
21
- /**
22
- * Retrieves the current user's role from local storage.
23
- * @returns {string | null} The user's role, or null if not found.
24
- */
25
- getUserRole(): string | null {
26
- return localStorage.getItem('role');
27
- }
28
-
29
- /**
30
- * Stores the user session data in local storage.
31
- * @param {any} data - The session data to store.
32
- */
33
- setUserSession(data: any): void {
34
- localStorage.setItem(SHARED.SESSIONKEY, JSON.stringify(data));
35
- }
36
-
37
- /**
38
- * Retrieves the stored user session data.
39
- * @returns {any | null} The parsed session data, or null if not found.
40
- */
41
- getUserSession(): any | null {
42
- const sessionData = localStorage.getItem(SHARED.SESSIONKEY);
43
- return sessionData ? JSON.parse(sessionData) : null;
44
- }
45
-
46
- /**
47
- * Retrieves the user's permissions from the stored session data.
48
- * @returns {any | null} The user's permissions, or null if not found.
49
- */
50
- getUserPermissions(): any | null {
51
- const sessionData = localStorage.getItem(SHARED.SESSIONKEY);
52
- return sessionData ? JSON.parse(sessionData).permissions : null;
53
- }
54
-
55
- /**
56
- * Retrieves the session ID from the stored session data.
57
- * @returns {any | null} The session ID, or null if not found.
58
- */
59
- getSessionID(): any | null {
60
- const sessionData = localStorage.getItem(SHARED.SESSIONKEY);
61
- console.log(sessionData);
62
- if (sessionData) {
63
- const sessionId = JSON.parse(sessionData);
64
- console.log(sessionId);
65
- return sessionId;
66
- }
67
- return null;
68
- }
69
-
70
- /**
71
- * Clears all stored session data from local storage.
72
- */
73
- clearSession(): void {
74
- localStorage.clear();
75
- }
76
- }
@@ -1,20 +0,0 @@
1
- {
2
- "catQwUrl": "https://qa-qw-api.dynamatix.com/api/",
3
- "apiUrl": "https://gatehouse-qa.dynamatix.com/api/",
4
- "swaggerUrl": "https://qa-qw-api.dynamatix.com/api-docs/",
5
- "adminEmail": "neeraj.kumar@catura.co.uk",
6
- "interactBaseApi": "https://qa-interact-api.dynamatix.com/api/",
7
- "actionBaseApi": "https://qa-qw-api.dynamatix.com/api/",
8
- "documentApiUrl": "http://localhost:5100/api/",
9
- "adminPhoneNumber": "+447380300545",
10
- "visibilityOption": {
11
- "isRationalVisible": false,
12
- "isChecklistVisible": false,
13
- "isAudit": false,
14
- "isConversation": true,
15
- "isOverview": true,
16
- "isDocuments": true
17
- },
18
- "env": "qa"
19
-
20
- }
@@ -1,14 +0,0 @@
1
- <div class="grid m-0 h-full">
2
- <div class="col-12 md:col-12 lg:col-12 p-0 h-full" [ngClass]="showFolderList ? 'custom-scroll' : ''">
3
- @if(showFolderList){
4
- <div>
5
- <lib-folder-container [documentList]="documentList" [folderList]="folderList" [contextId]="contextId"></lib-folder-container>
6
- </div>
7
- }
8
- <div [ngClass]="showFolderList ? 'mt-3' : ''">
9
- <lib-document-list [isCollapsed]="isCollapsed" [documentList]="documentList" [contextId]="contextId" [isUploadButtonVisible]="isUploadButtonVisible" (onRefresh)="fetchFolder()">
10
- <ng-content></ng-content>
11
- </lib-document-list>
12
- </div>
13
- </div>
14
- </div>
@@ -1,8 +0,0 @@
1
- .custom-scroll{
2
- overflow-y: hidden;
3
- scrollbar-gutter: stable;
4
- }
5
-
6
- .custom-scroll:hover {
7
- overflow-y: auto;
8
- }
@@ -1,110 +0,0 @@
1
- import { ComponentFixture, TestBed } from '@angular/core/testing';
2
- import { DocumentContainerComponent } from './document-container.component';
3
- import { of, throwError } from 'rxjs';
4
- import { DocumentHttpService } from '../../services/document-http.service';
5
- import { DocumentStore } from '../../state/document.store';
6
- import { DocumentQuery } from '../../state/document.query';
7
- import { DocumentService } from '../../state/document.service';
8
- import { CommonModule } from '@angular/common';
9
- import { HttpClientModule } from '@angular/common/http';
10
- import { SHARED } from '../../../../Shared/constant/SHARED';
11
- import { DocumentListComponent } from '../document-list/document-list.component';
12
- import { MessageService } from 'primeng/api';
13
- import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
14
- import { DialogModule } from 'primeng/dialog';
15
-
16
- describe('DocumentContainerComponent', () => {
17
- let component: DocumentContainerComponent;
18
- let fixture: ComponentFixture<DocumentContainerComponent>;
19
- let mockDocumentHttpService: jasmine.SpyObj<DocumentHttpService>;
20
- let mockDocumentStore: jasmine.SpyObj<DocumentStore>;
21
- let mockDocumentQuery: jasmine.SpyObj<DocumentQuery>;
22
- let mockDocumentService: jasmine.SpyObj<DocumentService>;
23
-
24
- const dummyFolders = [
25
- { _id: '1', name: 'Folder A', documentCount: 2 },
26
- { _id: '2', name: 'Folder B', documentCount: 0 }
27
- ];
28
-
29
- const dummyDocuments = [
30
- { _id: 'doc1', name: 'Document 1' },
31
- { _id: 'doc2', name: 'Document 2' }
32
- ];
33
-
34
- beforeEach(async () => {
35
- mockDocumentHttpService = jasmine.createSpyObj('DocumentHttpService', [
36
- 'getFoldersData',
37
- 'getDocumentByFolderID',
38
- 'getDocumentTypes' // ✅ Fix added here
39
- ]);
40
- mockDocumentHttpService.getDocumentTypes.and.returnValue(of([])); // ✅ Return dummy value
41
-
42
- mockDocumentStore = jasmine.createSpyObj('DocumentStore', ['setDocumentList']);
43
- mockDocumentQuery = jasmine.createSpyObj('DocumentQuery', ['selectParentDocumentTypeId']);
44
- mockDocumentService = jasmine.createSpyObj('DocumentService', ['dummy']);
45
-
46
- await TestBed.configureTestingModule({
47
- declarations: [DocumentContainerComponent, DocumentListComponent],
48
- imports: [CommonModule, HttpClientModule, DialogModule],
49
- providers: [
50
- { provide: DocumentHttpService, useValue: mockDocumentHttpService },
51
- { provide: DocumentStore, useValue: mockDocumentStore },
52
- { provide: DocumentQuery, useValue: mockDocumentQuery },
53
- { provide: DocumentService, useValue: mockDocumentService },
54
- MessageService
55
- ],
56
- schemas: [CUSTOM_ELEMENTS_SCHEMA]
57
- }).compileComponents();
58
- });
59
-
60
- beforeEach(() => {
61
- fixture = TestBed.createComponent(DocumentContainerComponent);
62
- component = fixture.componentInstance;
63
- component.contextId = 'abc123';
64
- });
65
-
66
- it('should create', () => {
67
- expect(component).toBeTruthy();
68
- });
69
-
70
- it('should fetch folders and documents on ngOnInit', () => {
71
- mockDocumentHttpService.getFoldersData.and.returnValue(of(dummyFolders));
72
- mockDocumentQuery.selectParentDocumentTypeId.and.returnValue(of(null));
73
- mockDocumentHttpService.getDocumentByFolderID.and.returnValue(of(dummyDocuments));
74
-
75
- fixture.detectChanges(); // triggers ngOnInit
76
-
77
- expect(mockDocumentHttpService.getFoldersData).toHaveBeenCalledWith('abc123');
78
- expect(mockDocumentHttpService.getDocumentByFolderID).toHaveBeenCalledWith('1', 'abc123');
79
- expect(mockDocumentStore.setDocumentList).toHaveBeenCalledWith(dummyDocuments);
80
- expect(component.folderList.length).toBe(1); // Only folder with doc count > 0
81
- expect(component.documentList.length).toBe(2);
82
- });
83
-
84
- it('should handle folder fetch error', () => {
85
- const consoleSpy = spyOn(console, 'error');
86
- mockDocumentHttpService.getFoldersData.and.returnValue(throwError(() => new Error('Error fetching folders')));
87
- mockDocumentQuery.selectParentDocumentTypeId.and.returnValue(of(null));
88
-
89
- fixture.detectChanges();
90
-
91
- expect(consoleSpy).toHaveBeenCalled();
92
- });
93
-
94
- it('should handle document fetch error', () => {
95
- const consoleSpy = spyOn(console, 'error');
96
- mockDocumentHttpService.getFoldersData.and.returnValue(of(dummyFolders));
97
- mockDocumentQuery.selectParentDocumentTypeId.and.returnValue(of(null));
98
- mockDocumentHttpService.getDocumentByFolderID.and.returnValue(throwError(() => new Error('Error fetching docs')));
99
-
100
- fixture.detectChanges();
101
-
102
- expect(consoleSpy).toHaveBeenCalled();
103
- });
104
-
105
- it('should unsubscribe on destroy', () => {
106
- spyOn(component['subscription'], 'unsubscribe');
107
- component.ngOnDestroy();
108
- expect(component['subscription'].unsubscribe).toHaveBeenCalled();
109
- });
110
- });