@uxland/primary-shell 7.3.0 → 7.5.0
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.
- package/dist/component-s17Jsk26.js +47 -0
- package/dist/component-s17Jsk26.js.map +1 -0
- package/dist/index-C3997nyY.js +45157 -0
- package/dist/index-C3997nyY.js.map +1 -0
- package/dist/index.js +18 -45079
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +111 -94
- package/dist/index.umd.cjs.map +1 -1
- package/dist/primary/shell/src/UI/bootstrapper.d.ts +1 -1
- package/dist/primary/shell/src/UI/internal-views/handle-views.d.ts +1 -1
- package/dist/primary/shell/src/api/api.d.ts +4 -0
- package/dist/primary/shell/src/api/import-data-manager/component/component.d.ts +15 -0
- package/dist/primary/shell/src/api/import-data-manager/component/template.d.ts +2 -0
- package/dist/primary/shell/src/api/import-data-manager/import-data-manager-impl.d.ts +27 -0
- package/dist/primary/shell/src/api/import-data-manager/import-data-manager-impl.test.d.ts +1 -0
- package/dist/primary/shell/src/api/import-data-manager/import-data-manager.d.ts +19 -0
- package/dist/primary/shell/src/api/import-data-manager/index.d.ts +2 -0
- package/dist/primary/shell/src/api/region-manager/regions.d.ts +1 -0
- package/dist/primary/shell/src/api/user-manager/user-manager.d.ts +12 -0
- package/dist/primary/shell/src/bootstrapper.d.ts +1 -1
- package/dist/primary/shell/src/handle-plugins.d.ts +1 -1
- package/dist/primary/shell/src/locales.d.ts +8 -0
- package/package.json +1 -1
- package/src/UI/bootstrapper.ts +2 -2
- package/src/UI/internal-views/handle-views.ts +4 -3
- package/src/api/api.ts +8 -0
- package/src/api/import-data-manager/component/component.ts +34 -0
- package/src/api/import-data-manager/component/styles.css +58 -0
- package/src/api/import-data-manager/component/template.ts +24 -0
- package/src/api/import-data-manager/import-data-manager-impl.test.ts +282 -0
- package/src/api/import-data-manager/import-data-manager-impl.ts +80 -0
- package/src/api/import-data-manager/import-data-manager.ts +15 -0
- package/src/api/import-data-manager/index.ts +2 -0
- package/src/api/region-manager/regions.ts +1 -0
- package/src/api/user-manager/user-manager.ts +45 -0
- package/src/bootstrapper.ts +2 -2
- package/src/handle-plugins.ts +6 -6
- package/src/locales.ts +9 -0
- package/dist/primary/shell/src/domain/is-user-role-administrative.d.ts +0 -1
- package/src/domain/is-user-role-administrative.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useUI: (
|
|
1
|
+
export declare const useUI: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useInternalViews: (
|
|
1
|
+
export declare const useInternalViews: () => void;
|
|
@@ -9,6 +9,8 @@ import { PdfViewerManager } from './pdf-viewer-manager/pdf-viewer-manager';
|
|
|
9
9
|
import { PluginBusyManager } from './plugin-busy-manager/plugin-busy-manager';
|
|
10
10
|
import { PrimariaRegionManager } from './region-manager/region-manager';
|
|
11
11
|
import { TokenManager } from './token-manager/token-manager';
|
|
12
|
+
import { UserManager } from './user-manager/user-manager';
|
|
13
|
+
import { PrimariaImportDataManager } from './import-data-manager';
|
|
12
14
|
export interface PrimariaApi extends HarmonixApi {
|
|
13
15
|
httpClient: HttpClient;
|
|
14
16
|
interactionService: PrimariaInteractionService;
|
|
@@ -17,9 +19,11 @@ export interface PrimariaApi extends HarmonixApi {
|
|
|
17
19
|
regionManager: PrimariaRegionManager;
|
|
18
20
|
globalStateManager: PrimariaGlobalStateManager;
|
|
19
21
|
tokenManager: TokenManager;
|
|
22
|
+
userManager: UserManager;
|
|
20
23
|
ecapEventManager: EcapEventManager;
|
|
21
24
|
pluginBusyManager: PluginBusyManager;
|
|
22
25
|
pdfViewerManager: PdfViewerManager;
|
|
26
|
+
importDataManager: PrimariaImportDataManager;
|
|
23
27
|
}
|
|
24
28
|
export declare const PrimariaRegionHost: any;
|
|
25
29
|
/**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IRegion } from '@uxland/regions';
|
|
2
|
+
import { ConfirmationContentProps } from '../../interaction-service';
|
|
3
|
+
declare const ImportDataManagerModal_base: any;
|
|
4
|
+
export declare class ImportDataManagerModal extends ImportDataManagerModal_base implements ConfirmationContentProps<undefined, undefined> {
|
|
5
|
+
data: undefined;
|
|
6
|
+
setResult: (result: undefined) => void;
|
|
7
|
+
setIsValid: (isValid: boolean) => void;
|
|
8
|
+
confirm: () => void;
|
|
9
|
+
cancel: () => void;
|
|
10
|
+
importDataRegion: IRegion | undefined;
|
|
11
|
+
render(): import('lit').TemplateResult<1>;
|
|
12
|
+
static styles: import('lit').CSSResult;
|
|
13
|
+
_accept: () => void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PrimariaImportDataManager } from './import-data-manager';
|
|
2
|
+
import { PrimariaInteractionService } from '../interaction-service/interaction-service';
|
|
3
|
+
export declare class ImportDataManagerImpl implements PrimariaImportDataManager {
|
|
4
|
+
private interactionService;
|
|
5
|
+
private selectedItems;
|
|
6
|
+
private currentImporterId;
|
|
7
|
+
private pluginTexts;
|
|
8
|
+
constructor(interactionService: PrimariaInteractionService);
|
|
9
|
+
import(importerId: string): Promise<{
|
|
10
|
+
accepted: boolean;
|
|
11
|
+
data: Record<string, any[]>;
|
|
12
|
+
text: {
|
|
13
|
+
raw: string;
|
|
14
|
+
html: string;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
selectItems(payload: {
|
|
18
|
+
pluginId: string;
|
|
19
|
+
data: any[];
|
|
20
|
+
text: {
|
|
21
|
+
raw: string;
|
|
22
|
+
html: string;
|
|
23
|
+
};
|
|
24
|
+
}): void;
|
|
25
|
+
getCurrentImporterId(): string;
|
|
26
|
+
private getConcatenatedText;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface PrimariaImportDataManager {
|
|
2
|
+
import(importerId: string): Promise<{
|
|
3
|
+
accepted: boolean;
|
|
4
|
+
data: Record<string, any[]>;
|
|
5
|
+
text: {
|
|
6
|
+
raw: string;
|
|
7
|
+
html: string;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
selectItems(payload: {
|
|
11
|
+
pluginId: string;
|
|
12
|
+
data: any[];
|
|
13
|
+
text: {
|
|
14
|
+
raw: string;
|
|
15
|
+
html: string;
|
|
16
|
+
};
|
|
17
|
+
}): void;
|
|
18
|
+
getCurrentImporterId(): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TokenManager } from '../token-manager/token-manager';
|
|
2
|
+
export interface UserManager {
|
|
3
|
+
getRole: () => string | undefined;
|
|
4
|
+
isUserRoleAdministrative: () => boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class UserManagerImpl implements UserManager {
|
|
7
|
+
private tokenManager;
|
|
8
|
+
constructor(tokenManager: TokenManager);
|
|
9
|
+
getRole: () => string | undefined;
|
|
10
|
+
isUserRoleAdministrative: () => boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const createUserManager: (tokenManager: TokenManager) => UserManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const initializeShell: (hostAppElement: HTMLElement
|
|
1
|
+
export declare const initializeShell: (hostAppElement: HTMLElement) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PluginDefinition, Plugin as PluginType } from '@uxland/harmonix';
|
|
2
2
|
import { PrimariaApi } from './api/api';
|
|
3
3
|
export type { PluginDefinition, PluginInfo } from '@uxland/harmonix';
|
|
4
|
-
export declare const bootstrapPlugins: (plugins: PluginDefinition[]
|
|
4
|
+
export declare const bootstrapPlugins: (plugins: PluginDefinition[]) => Promise<void>;
|
|
5
5
|
export declare const disposePlugins: () => Promise<void[]>;
|
|
6
6
|
export type Plugin = PluginType<PrimariaApi>;
|
|
@@ -8,6 +8,7 @@ type LocaleKeys<T> = T extends object ? {
|
|
|
8
8
|
export type ShellLocales = LocaleKeys<(typeof locales)[typeof defaultLang][typeof primariaShellId]>;
|
|
9
9
|
export declare const translate: (path: ShellLocales) => any;
|
|
10
10
|
export { shellLocaleManager };
|
|
11
|
+
declare const defaultLang = "ca";
|
|
11
12
|
export declare const locales: {
|
|
12
13
|
ca: {
|
|
13
14
|
"primaria-shell": {
|
|
@@ -44,6 +45,13 @@ export declare const locales: {
|
|
|
44
45
|
pdfVisor: {
|
|
45
46
|
noPdfSelected: string;
|
|
46
47
|
};
|
|
48
|
+
importDataManager: {
|
|
49
|
+
title: string;
|
|
50
|
+
actions: {
|
|
51
|
+
cancel: string;
|
|
52
|
+
import: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
47
55
|
};
|
|
48
56
|
};
|
|
49
57
|
};
|
package/package.json
CHANGED
package/src/UI/bootstrapper.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { useComponents } from "./components/bootstrapper";
|
|
|
3
3
|
import { useSharedUI } from "./shared-components/bootstrapper";
|
|
4
4
|
import { useInternalViews } from "./internal-views/handle-views";
|
|
5
5
|
|
|
6
|
-
export const useUI = (
|
|
6
|
+
export const useUI = () => {
|
|
7
7
|
regionAdapterRegistry.registerAdapterFactory(
|
|
8
8
|
"primaria-content-switcher",
|
|
9
9
|
selectableAdapterFactory,
|
|
10
10
|
);
|
|
11
11
|
useSharedUI();
|
|
12
12
|
useComponents();
|
|
13
|
-
useInternalViews(
|
|
13
|
+
useInternalViews();
|
|
14
14
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { shellApi } from "../../api/api";
|
|
1
2
|
import { registerPDFVisorMainView } from "../../api/pdf-viewer-manager/handle-views";
|
|
2
|
-
import { isUserRoleAdministrative } from "../../domain/is-user-role-administrative";
|
|
3
3
|
import { registerAdministrativeNavMenuViews, registerDoctorNavMenuViews } from "./upper-nav-views";
|
|
4
4
|
|
|
5
5
|
const registerMainViews = () => {
|
|
6
6
|
registerPDFVisorMainView();
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export const useInternalViews = (
|
|
9
|
+
export const useInternalViews = () => {
|
|
10
10
|
registerMainViews();
|
|
11
|
-
|
|
11
|
+
const isUserRoleAdministrative = shellApi.userManager.isUserRoleAdministrative();
|
|
12
|
+
if((isUserRoleAdministrative))
|
|
12
13
|
registerAdministrativeNavMenuViews();
|
|
13
14
|
else
|
|
14
15
|
registerDoctorNavMenuViews();
|
package/src/api/api.ts
CHANGED
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
} from "./plugin-busy-manager/plugin-busy-manager";
|
|
25
25
|
import { PrimariaRegionManager, createRegionManagerProxy } from "./region-manager/region-manager";
|
|
26
26
|
import { TokenManager, createTokenManager } from "./token-manager/token-manager";
|
|
27
|
+
import { UserManager, createUserManager } from "./user-manager/user-manager";
|
|
28
|
+
import { PrimariaImportDataManager, ImportDataManagerImpl } from "./import-data-manager";
|
|
27
29
|
|
|
28
30
|
const broker = createBroker();
|
|
29
31
|
|
|
@@ -35,20 +37,24 @@ export interface PrimariaApi extends HarmonixApi {
|
|
|
35
37
|
regionManager: PrimariaRegionManager;
|
|
36
38
|
globalStateManager: PrimariaGlobalStateManager;
|
|
37
39
|
tokenManager: TokenManager;
|
|
40
|
+
userManager: UserManager;
|
|
38
41
|
ecapEventManager: EcapEventManager;
|
|
39
42
|
pluginBusyManager: PluginBusyManager;
|
|
40
43
|
pdfViewerManager: PdfViewerManager;
|
|
44
|
+
importDataManager: PrimariaImportDataManager;
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
const regionManager: RegionManager = createRegionManager("primaria");
|
|
44
48
|
export const PrimariaRegionHost: any = createRegionHost(regionManager as any);
|
|
45
49
|
const tokenManager = createTokenManager();
|
|
50
|
+
const userManager = createUserManager(tokenManager);
|
|
46
51
|
const globalStateManager: PrimariaGlobalStateManager = createGlobalStateManager(broker);
|
|
47
52
|
const pluginBusyManager = new PluginBusyManagerImpl(broker);
|
|
48
53
|
const interactionService = new ParimariaInteractionServiceImpl();
|
|
49
54
|
const notificationService = new PrimariaNotificationServiceImpl();
|
|
50
55
|
const ecapEventManager = createEcapEventManager();
|
|
51
56
|
const pdfViewerManager = createPdfViewerManager(broker, notificationService);
|
|
57
|
+
const importDataManager = new ImportDataManagerImpl(interactionService);
|
|
52
58
|
|
|
53
59
|
/**
|
|
54
60
|
* Factory function that creates a Primaria API instance.
|
|
@@ -69,11 +75,13 @@ export const primariaApiFactory: ApiFactory<PrimariaApi> = (
|
|
|
69
75
|
createLocaleManager: createLocaleManager(pluginInfo.pluginId) as any,
|
|
70
76
|
globalStateManager,
|
|
71
77
|
tokenManager,
|
|
78
|
+
userManager,
|
|
72
79
|
ecapEventManager,
|
|
73
80
|
pluginBusyManager,
|
|
74
81
|
interactionService,
|
|
75
82
|
notificationService,
|
|
76
83
|
pdfViewerManager,
|
|
84
|
+
importDataManager,
|
|
77
85
|
};
|
|
78
86
|
};
|
|
79
87
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
import { IRegion, region } from "@uxland/regions";
|
|
3
|
+
import { LitElement, css, html, unsafeCSS } from "lit";
|
|
4
|
+
import { customElement } from "lit/decorators.js";
|
|
5
|
+
import styles from "./styles.css?inline";
|
|
6
|
+
import { template } from "./template";
|
|
7
|
+
import { ConfirmationContentProps } from "../../interaction-service";
|
|
8
|
+
import { PrimariaRegionHost } from "../../api";
|
|
9
|
+
|
|
10
|
+
@customElement("import-data-manager-modal")
|
|
11
|
+
export class ImportDataManagerModal
|
|
12
|
+
extends PrimariaRegionHost(LitElement) implements ConfirmationContentProps<undefined, undefined>
|
|
13
|
+
{
|
|
14
|
+
data: undefined;
|
|
15
|
+
setResult: (result: undefined) => void;
|
|
16
|
+
setIsValid: (isValid: boolean) => void;
|
|
17
|
+
confirm: () => void;
|
|
18
|
+
cancel: () => void;
|
|
19
|
+
|
|
20
|
+
@region({ targetId: "import-data-region", name: "import-data-region" })
|
|
21
|
+
importDataRegion: IRegion | undefined;
|
|
22
|
+
|
|
23
|
+
render() {
|
|
24
|
+
return html`${template(this)}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static styles = css`
|
|
28
|
+
${unsafeCSS(styles)}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
_accept = () => {
|
|
32
|
+
this.confirm();
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
background-color: white;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
min-width: 500px;
|
|
6
|
+
width: 90vw;
|
|
7
|
+
height: 90vh;
|
|
8
|
+
border-radius: var(--dss-radius-sm);
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* .header {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: row;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: space-between;
|
|
17
|
+
text-align: center;
|
|
18
|
+
color: black;
|
|
19
|
+
padding: var(--dss-spacing-sm);
|
|
20
|
+
|
|
21
|
+
.title {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: row;
|
|
24
|
+
gap: 8px;
|
|
25
|
+
}
|
|
26
|
+
} */
|
|
27
|
+
|
|
28
|
+
.content{
|
|
29
|
+
display: grid;
|
|
30
|
+
height: 100%;
|
|
31
|
+
min-height: 1px;
|
|
32
|
+
grid-template-columns: 1fr 1fr;
|
|
33
|
+
grid-auto-rows: 1fr;
|
|
34
|
+
gap: 16px;
|
|
35
|
+
padding: 16px;
|
|
36
|
+
overflow-y: auto;
|
|
37
|
+
max-height: calc(90vh - 120px);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.content > * {
|
|
41
|
+
border: 1px solid var(--color-neutral-200);
|
|
42
|
+
border-radius: 8px;
|
|
43
|
+
padding: 16px;
|
|
44
|
+
background-color: var(--color-neutral-50);
|
|
45
|
+
min-height: 200px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.footer {
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-direction: row;
|
|
51
|
+
align-items: center;
|
|
52
|
+
background: white;
|
|
53
|
+
justify-content: end;
|
|
54
|
+
gap: 12px;
|
|
55
|
+
height: 56px;
|
|
56
|
+
border-top: 1px solid var(--color-neutral-100);
|
|
57
|
+
padding: var(--dss-spacing-sm);
|
|
58
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
import { translate } from "../../../locales";
|
|
3
|
+
import { ImportDataManagerModal } from "./component";
|
|
4
|
+
|
|
5
|
+
export const template = (props: ImportDataManagerModal) => {
|
|
6
|
+
return html`
|
|
7
|
+
<div class="container">
|
|
8
|
+
<!-- <div class="header">
|
|
9
|
+
<div class="title">
|
|
10
|
+
<div>${translate("importDataManager.title")}</div>
|
|
11
|
+
</div>
|
|
12
|
+
</div> -->
|
|
13
|
+
<div class="content" id="import-data-region"></div>
|
|
14
|
+
<div class="footer">
|
|
15
|
+
<dss-button label="${translate("importDataManager.actions.cancel")}" @click="${() => {
|
|
16
|
+
props.cancel();
|
|
17
|
+
}}" size="md" variant="secondary"></dss-button>
|
|
18
|
+
<dss-button label="${translate("importDataManager.actions.import")}" @click="${() => {
|
|
19
|
+
props._accept();
|
|
20
|
+
}}" size="md" variant="primary"></dss-button>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
`;
|
|
24
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { ImportDataManagerImpl } from './import-data-manager-impl';
|
|
3
|
+
import { PrimariaInteractionService, ConfirmationOptions, ConfirmComponentUI, ConfirmationResult } from '../interaction-service/interaction-service';
|
|
4
|
+
|
|
5
|
+
// Mock del PrimariaInteractionService
|
|
6
|
+
class MockInteractionService extends PrimariaInteractionService {
|
|
7
|
+
private mockConfirmResult: { confirmed: boolean; result?: unknown } = { confirmed: true };
|
|
8
|
+
|
|
9
|
+
// Mètode per configurar el resultat del mock
|
|
10
|
+
setMockConfirmResult(result: { confirmed: boolean; result?: unknown }) {
|
|
11
|
+
this.mockConfirmResult = result;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async confirm<TData = undefined, TResult = undefined>(
|
|
15
|
+
_data: TData | undefined,
|
|
16
|
+
_componentUI: ConfirmComponentUI<TData, TResult>,
|
|
17
|
+
_options?: ConfirmationOptions | undefined,
|
|
18
|
+
): Promise<ConfirmationResult<TResult | undefined>> {
|
|
19
|
+
return Promise.resolve(this.mockConfirmResult as ConfirmationResult<TResult | undefined>);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async confirmMessage(
|
|
23
|
+
_message: string,
|
|
24
|
+
_options?: ConfirmationOptions | undefined,
|
|
25
|
+
): Promise<ConfirmationResult> {
|
|
26
|
+
return Promise.resolve({ confirmed: this.mockConfirmResult.confirmed, result: undefined });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('ImportDataManagerImpl implements PrimariaImportDataManager', () => {
|
|
31
|
+
let importDataManager: ImportDataManagerImpl;
|
|
32
|
+
let mockInteractionService: MockInteractionService;
|
|
33
|
+
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
mockInteractionService = new MockInteractionService();
|
|
36
|
+
importDataManager = new ImportDataManagerImpl(mockInteractionService);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('getCurrentImporterId', () => {
|
|
40
|
+
it('should return empty string initially', () => {
|
|
41
|
+
expect(importDataManager.getCurrentImporterId()).toBe('');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should return the current importer ID after calling import', async () => {
|
|
45
|
+
mockInteractionService.setMockConfirmResult({ confirmed: true });
|
|
46
|
+
|
|
47
|
+
const promise = importDataManager.import('test-importer-123');
|
|
48
|
+
expect(importDataManager.getCurrentImporterId()).toBe('test-importer-123');
|
|
49
|
+
|
|
50
|
+
await promise;
|
|
51
|
+
expect(importDataManager.getCurrentImporterId()).toBe('');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('selectItems', () => {
|
|
56
|
+
it('should store selected items correctly', () => {
|
|
57
|
+
const payload = {
|
|
58
|
+
pluginId: 'test-plugin',
|
|
59
|
+
data: [{ id: '1', name: 'Test Item' }],
|
|
60
|
+
text: { raw: 'Test Item', html: '<p>Test Item</p>' }
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
importDataManager.selectItems(payload);
|
|
64
|
+
|
|
65
|
+
// Test via getCurrentImporterId and import method to verify internal state
|
|
66
|
+
expect(() => importDataManager.selectItems(payload)).not.toThrow();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should handle multiple plugin selections', () => {
|
|
70
|
+
const payload1 = {
|
|
71
|
+
pluginId: 'plugin-1',
|
|
72
|
+
data: [{ id: '1', name: 'Item 1' }],
|
|
73
|
+
text: { raw: 'Item 1', html: '<p>Item 1</p>' }
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const payload2 = {
|
|
77
|
+
pluginId: 'plugin-2',
|
|
78
|
+
data: [{ id: '2', name: 'Item 2' }],
|
|
79
|
+
text: { raw: 'Item 2', html: '<p>Item 2</p>' }
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
expect(() => {
|
|
83
|
+
importDataManager.selectItems(payload1);
|
|
84
|
+
importDataManager.selectItems(payload2);
|
|
85
|
+
}).not.toThrow();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should overwrite previous selections from same plugin', () => {
|
|
89
|
+
const payload1 = {
|
|
90
|
+
pluginId: 'test-plugin',
|
|
91
|
+
data: [{ id: '1', name: 'First Item' }],
|
|
92
|
+
text: { raw: 'First Item', html: '<p>First Item</p>' }
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const payload2 = {
|
|
96
|
+
pluginId: 'test-plugin',
|
|
97
|
+
data: [{ id: '2', name: 'Second Item' }],
|
|
98
|
+
text: { raw: 'Second Item', html: '<p>Second Item</p>' }
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
expect(() => {
|
|
102
|
+
importDataManager.selectItems(payload1);
|
|
103
|
+
importDataManager.selectItems(payload2);
|
|
104
|
+
}).not.toThrow();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('import', () => {
|
|
109
|
+
it('should return accepted result with concatenated text when confirmed', async () => {
|
|
110
|
+
mockInteractionService.setMockConfirmResult({ confirmed: true });
|
|
111
|
+
|
|
112
|
+
// Mock the import to allow setting up items during the import process
|
|
113
|
+
const originalConfirm = mockInteractionService.confirm.bind(mockInteractionService);
|
|
114
|
+
vi.spyOn(mockInteractionService, 'confirm').mockImplementation(async (...args) => {
|
|
115
|
+
// Setup some selected items during the import process (simulating user interaction)
|
|
116
|
+
importDataManager.selectItems({
|
|
117
|
+
pluginId: 'plugin-1',
|
|
118
|
+
data: [{ id: '1', name: 'Item 1' }],
|
|
119
|
+
text: { raw: 'Item 1', html: '<p>Item 1</p>' }
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
importDataManager.selectItems({
|
|
123
|
+
pluginId: 'plugin-2',
|
|
124
|
+
data: [{ id: '2', name: 'Item 2' }],
|
|
125
|
+
text: { raw: 'Item 2', html: '<p>Item 2</p>' }
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return originalConfirm(...args);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const result = await importDataManager.import('test-importer');
|
|
132
|
+
|
|
133
|
+
expect(result.accepted).toBe(true);
|
|
134
|
+
expect(result.data).toEqual({
|
|
135
|
+
'plugin-1': [{ id: '1', name: 'Item 1' }],
|
|
136
|
+
'plugin-2': [{ id: '2', name: 'Item 2' }]
|
|
137
|
+
});
|
|
138
|
+
expect(result.text.raw).toBe('Item 1\n\nItem 2');
|
|
139
|
+
expect(result.text.html).toBe('<p>Item 1</p><br><br><p>Item 2</p>');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should return cancelled result with empty data when not confirmed', async () => {
|
|
143
|
+
mockInteractionService.setMockConfirmResult({ confirmed: false });
|
|
144
|
+
|
|
145
|
+
// Setup some selected items
|
|
146
|
+
importDataManager.selectItems({
|
|
147
|
+
pluginId: 'plugin-1',
|
|
148
|
+
data: [{ id: '1', name: 'Item 1' }],
|
|
149
|
+
text: { raw: 'Item 1', html: '<p>Item 1</p>' }
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const result = await importDataManager.import('test-importer');
|
|
153
|
+
|
|
154
|
+
expect(result.accepted).toBe(false);
|
|
155
|
+
expect(result.data).toEqual({});
|
|
156
|
+
expect(result.text.raw).toBe('');
|
|
157
|
+
expect(result.text.html).toBe('');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should clear state after successful import', async () => {
|
|
161
|
+
mockInteractionService.setMockConfirmResult({ confirmed: true });
|
|
162
|
+
|
|
163
|
+
// Setup selected items
|
|
164
|
+
importDataManager.selectItems({
|
|
165
|
+
pluginId: 'test-plugin',
|
|
166
|
+
data: [{ id: '1', name: 'Test Item' }],
|
|
167
|
+
text: { raw: 'Test Item', html: '<p>Test Item</p>' }
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await importDataManager.import('test-importer');
|
|
171
|
+
|
|
172
|
+
// Verify state is cleared
|
|
173
|
+
expect(importDataManager.getCurrentImporterId()).toBe('');
|
|
174
|
+
|
|
175
|
+
// Verify that subsequent import returns empty data
|
|
176
|
+
const result = await importDataManager.import('another-importer');
|
|
177
|
+
expect(result.data).toEqual({});
|
|
178
|
+
expect(result.text.raw).toBe('');
|
|
179
|
+
expect(result.text.html).toBe('');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should clear state after cancelled import', async () => {
|
|
183
|
+
mockInteractionService.setMockConfirmResult({ confirmed: false });
|
|
184
|
+
|
|
185
|
+
// Setup selected items
|
|
186
|
+
importDataManager.selectItems({
|
|
187
|
+
pluginId: 'test-plugin',
|
|
188
|
+
data: [{ id: '1', name: 'Test Item' }],
|
|
189
|
+
text: { raw: 'Test Item', html: '<p>Test Item</p>' }
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
await importDataManager.import('test-importer');
|
|
193
|
+
|
|
194
|
+
// Verify state is cleared
|
|
195
|
+
expect(importDataManager.getCurrentImporterId()).toBe('');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should handle empty selections', async () => {
|
|
199
|
+
mockInteractionService.setMockConfirmResult({ confirmed: true });
|
|
200
|
+
|
|
201
|
+
const result = await importDataManager.import('test-importer');
|
|
202
|
+
|
|
203
|
+
expect(result.accepted).toBe(true);
|
|
204
|
+
expect(result.data).toEqual({});
|
|
205
|
+
expect(result.text.raw).toBe('');
|
|
206
|
+
expect(result.text.html).toBe('');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should handle error and clear state', async () => {
|
|
210
|
+
mockInteractionService.setMockConfirmResult({ confirmed: true });
|
|
211
|
+
|
|
212
|
+
// Mock the interaction service to throw an error
|
|
213
|
+
vi.spyOn(mockInteractionService, 'confirm').mockRejectedValueOnce(new Error('Test error'));
|
|
214
|
+
|
|
215
|
+
// Setup selected items
|
|
216
|
+
importDataManager.selectItems({
|
|
217
|
+
pluginId: 'test-plugin',
|
|
218
|
+
data: [{ id: '1', name: 'Test Item' }],
|
|
219
|
+
text: { raw: 'Test Item', html: '<p>Test Item</p>' }
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
await expect(importDataManager.import('test-importer')).rejects.toThrow('Test error');
|
|
223
|
+
|
|
224
|
+
// Verify state is cleared even after error
|
|
225
|
+
expect(importDataManager.getCurrentImporterId()).toBe('');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('should handle text concatenation correctly with multiple plugins', async () => {
|
|
229
|
+
mockInteractionService.setMockConfirmResult({ confirmed: true });
|
|
230
|
+
|
|
231
|
+
// Mock the import to allow setting up items during the import process
|
|
232
|
+
const originalConfirm = mockInteractionService.confirm.bind(mockInteractionService);
|
|
233
|
+
vi.spyOn(mockInteractionService, 'confirm').mockImplementation(async (...args) => {
|
|
234
|
+
importDataManager.selectItems({
|
|
235
|
+
pluginId: 'diagnostics',
|
|
236
|
+
data: [{ code: 'E11.9', name: 'Diabetes' }],
|
|
237
|
+
text: { raw: 'E11.9 - Diabetes', html: '<p><strong>E11.9</strong> - Diabetes</p>' }
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
importDataManager.selectItems({
|
|
241
|
+
pluginId: 'allergies',
|
|
242
|
+
data: [{ name: 'Penicillin', severity: 'High' }],
|
|
243
|
+
text: { raw: 'Penicillin - High severity', html: '<p><strong>Penicillin</strong> - High severity</p>' }
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
return originalConfirm(...args);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const result = await importDataManager.import('test-importer');
|
|
250
|
+
|
|
251
|
+
expect(result.text.raw).toBe('E11.9 - Diabetes\n\nPenicillin - High severity');
|
|
252
|
+
expect(result.text.html).toBe('<p><strong>E11.9</strong> - Diabetes</p><br><br><p><strong>Penicillin</strong> - High severity</p>');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('should handle empty text values in concatenation', async () => {
|
|
256
|
+
mockInteractionService.setMockConfirmResult({ confirmed: true });
|
|
257
|
+
|
|
258
|
+
// Mock the import to allow setting up items during the import process
|
|
259
|
+
const originalConfirm = mockInteractionService.confirm.bind(mockInteractionService);
|
|
260
|
+
vi.spyOn(mockInteractionService, 'confirm').mockImplementation(async (...args) => {
|
|
261
|
+
importDataManager.selectItems({
|
|
262
|
+
pluginId: 'plugin-1',
|
|
263
|
+
data: [{ id: '1' }],
|
|
264
|
+
text: { raw: '', html: '' }
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
importDataManager.selectItems({
|
|
268
|
+
pluginId: 'plugin-2',
|
|
269
|
+
data: [{ id: '2' }],
|
|
270
|
+
text: { raw: 'Item 2', html: '<p>Item 2</p>' }
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
return originalConfirm(...args);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const result = await importDataManager.import('test-importer');
|
|
277
|
+
|
|
278
|
+
expect(result.text.raw).toBe('Item 2');
|
|
279
|
+
expect(result.text.html).toBe('<p>Item 2</p>');
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|