|
| 1 | +/* istanbul ignore file */ |
| 2 | + |
| 3 | +export class MockContext<T> implements ComponentFramework.Context<T> { |
| 4 | + constructor(parameters: T) { |
| 5 | + this.parameters = parameters; |
| 6 | + this.mode = { |
| 7 | + allocatedHeight: -1, |
| 8 | + allocatedWidth: -1, |
| 9 | + isControlDisabled: false, |
| 10 | + isVisible: true, |
| 11 | + label: '', |
| 12 | + setControlState: jest.fn(), |
| 13 | + setFullScreen: jest.fn(), |
| 14 | + trackContainerResize: jest.fn(), |
| 15 | + }; |
| 16 | + this.client = { |
| 17 | + disableScroll: false, |
| 18 | + getClient: jest.fn(), |
| 19 | + getFormFactor: jest.fn(), |
| 20 | + isOffline: jest.fn(), |
| 21 | + }; |
| 22 | + |
| 23 | + // Canvas apps currently assigns a positive tab-index |
| 24 | + // so we must use this property to assign a positive tab-index also |
| 25 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 26 | + (this as any).accessibility = { assignedTabIndex: 0 }; |
| 27 | + } |
| 28 | + client: ComponentFramework.Client; |
| 29 | + device: ComponentFramework.Device; |
| 30 | + factory: ComponentFramework.Factory; |
| 31 | + formatting: ComponentFramework.Formatting; |
| 32 | + mode: ComponentFramework.Mode; |
| 33 | + navigation: ComponentFramework.Navigation; |
| 34 | + resources: ComponentFramework.Resources; |
| 35 | + userSettings: ComponentFramework.UserSettings; |
| 36 | + utils: ComponentFramework.Utility; |
| 37 | + webAPI: ComponentFramework.WebApi; |
| 38 | + parameters: T; |
| 39 | + updatedProperties: string[] = []; |
| 40 | +} |
| 41 | + |
| 42 | +export class MockState implements ComponentFramework.Dictionary {} |
| 43 | + |
| 44 | +export class MockStringProperty implements ComponentFramework.PropertyTypes.StringProperty { |
| 45 | + constructor(raw?: string | null, formatted?: string | undefined) { |
| 46 | + this.raw = raw ?? null; |
| 47 | + this.formatted = formatted; |
| 48 | + } |
| 49 | + raw: string | null; |
| 50 | + attributes?: ComponentFramework.PropertyHelper.FieldPropertyMetadata.StringMetadata | undefined; |
| 51 | + error: boolean; |
| 52 | + errorMessage: string; |
| 53 | + formatted?: string | undefined; |
| 54 | + security?: ComponentFramework.PropertyHelper.SecurityValues | undefined; |
| 55 | + type: string; |
| 56 | +} |
| 57 | + |
| 58 | +export class MockWholeNumberProperty implements ComponentFramework.PropertyTypes.WholeNumberProperty { |
| 59 | + constructor(raw?: number | null, formatted?: string | undefined) { |
| 60 | + this.raw = raw ?? null; |
| 61 | + this.formatted = formatted; |
| 62 | + } |
| 63 | + attributes?: ComponentFramework.PropertyHelper.FieldPropertyMetadata.WholeNumberMetadata | undefined; |
| 64 | + raw: number | null; |
| 65 | + error: boolean; |
| 66 | + errorMessage: string; |
| 67 | + formatted?: string | undefined; |
| 68 | + security?: ComponentFramework.PropertyHelper.SecurityValues | undefined; |
| 69 | + type: string; |
| 70 | +} |
| 71 | + |
| 72 | +export class MockEnumProperty<T> implements ComponentFramework.PropertyTypes.EnumProperty<T> { |
| 73 | + constructor(raw?: T, type?: string) { |
| 74 | + if (raw) this.raw = raw; |
| 75 | + if (type) this.type = type; |
| 76 | + } |
| 77 | + type: string; |
| 78 | + raw: T; |
| 79 | +} |
| 80 | + |
| 81 | +export class MockTwoOptionsProperty implements ComponentFramework.PropertyTypes.TwoOptionsProperty { |
| 82 | + constructor(raw?: boolean) { |
| 83 | + if (raw) this.raw = raw; |
| 84 | + } |
| 85 | + raw: boolean; |
| 86 | + attributes?: ComponentFramework.PropertyHelper.FieldPropertyMetadata.TwoOptionMetadata | undefined; |
| 87 | + error: boolean; |
| 88 | + errorMessage: string; |
| 89 | + formatted?: string | undefined; |
| 90 | + security?: ComponentFramework.PropertyHelper.SecurityValues | undefined; |
| 91 | + type: string; |
| 92 | +} |
0 commit comments