diff --git a/packages/components/src/components/iot-bar-chart/iot-bar-chart.spec.ts b/packages/components/src/components/iot-bar-chart/iot-bar-chart.spec.ts index 2d62c11b1..415e74a3e 100644 --- a/packages/components/src/components/iot-bar-chart/iot-bar-chart.spec.ts +++ b/packages/components/src/components/iot-bar-chart/iot-bar-chart.spec.ts @@ -8,6 +8,7 @@ import { DATA_STREAM } from '../../testing/mockWidgetProperties'; import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector'; import { CustomHTMLElement } from '../../testing/types'; import { update } from '../../testing/update'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const viewport: MinimalLiveViewport = { duration: 1000, @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = { const barChartSpecPage = async (propOverrides: Partial = {}) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, }); appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM])); diff --git a/packages/components/src/components/iot-kpi/iot-kpi.spec.ts b/packages/components/src/components/iot-kpi/iot-kpi.spec.ts index b68239b3d..8110535c6 100644 --- a/packages/components/src/components/iot-kpi/iot-kpi.spec.ts +++ b/packages/components/src/components/iot-kpi/iot-kpi.spec.ts @@ -8,6 +8,7 @@ import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time import { CustomHTMLElement } from '../../testing/types'; import { update } from '../../testing/update'; import { DATA_STREAM } from '../../testing/mockWidgetProperties'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const viewport: MinimalLiveViewport = { duration: 1000, @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = { const kpiSpecPage = async (propOverrides: Partial = {}) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, }); appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM])); diff --git a/packages/components/src/components/iot-line-chart/iot-line-chart.spec.ts b/packages/components/src/components/iot-line-chart/iot-line-chart.spec.ts index 8018b3fbd..0667743d7 100644 --- a/packages/components/src/components/iot-line-chart/iot-line-chart.spec.ts +++ b/packages/components/src/components/iot-line-chart/iot-line-chart.spec.ts @@ -8,6 +8,7 @@ import { CustomHTMLElement } from '../../testing/types'; import { initialize, query, SiteWiseDataStreamQuery } from '@iot-app-kit/core'; import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector'; import { update } from '../../testing/update'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const viewport: MinimalLiveViewport = { duration: 1000, @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = { const lineChartSpecPage = async (propOverrides: Partial = {}) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, }); appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM])); diff --git a/packages/components/src/components/iot-resource-explorer/iot-resource-explorer.spec.ts b/packages/components/src/components/iot-resource-explorer/iot-resource-explorer.spec.ts index f0c496c02..835696d64 100644 --- a/packages/components/src/components/iot-resource-explorer/iot-resource-explorer.spec.ts +++ b/packages/components/src/components/iot-resource-explorer/iot-resource-explorer.spec.ts @@ -1,4 +1,4 @@ -import { createMockSiteWiseSDK, initialize, IoTAppKitInitInputs } from '@iot-app-kit/core'; +import { initialize, IoTAppKitInitInputs, createMockSiteWiseSDK } from '@iot-app-kit/core'; import { newSpecPage } from '@stencil/core/testing'; import { IotResourceExplorer } from './iot-resource-explorer'; import { Components } from '../../components.d'; @@ -7,6 +7,7 @@ import { update } from '../../testing/update'; import { ResourceExplorerQuery } from './types'; import flushPromises from 'flush-promises'; import { mocklistAssetsResponse } from '../../testing/mocks/data/listAssetsResponse'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const resourceExplorerSpec = async ( propOverrides: Partial, @@ -14,8 +15,7 @@ const resourceExplorerSpec = async ( ) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, ...appKitInitOverrides, }); const page = await newSpecPage({ diff --git a/packages/components/src/components/iot-resource-explorer/sitewise-resource-explorer.spec.ts b/packages/components/src/components/iot-resource-explorer/sitewise-resource-explorer.spec.ts index bd27ae312..989b048f4 100644 --- a/packages/components/src/components/iot-resource-explorer/sitewise-resource-explorer.spec.ts +++ b/packages/components/src/components/iot-resource-explorer/sitewise-resource-explorer.spec.ts @@ -1,4 +1,4 @@ -import { createMockSiteWiseSDK, initialize, IoTAppKitInitInputs } from '@iot-app-kit/core'; +import { initialize, IoTAppKitInitInputs, createMockSiteWiseSDK } from '@iot-app-kit/core'; import * as core from '@iot-app-kit/core'; import { newSpecPage } from '@stencil/core/testing'; import { SitewiseResourceExplorer } from './sitewise-resource-explorer'; @@ -7,6 +7,7 @@ import { CustomHTMLElement } from '../../testing/types'; import { update } from '../../testing/update'; import { SitewiseAssetResource } from './types'; import flushPromises from 'flush-promises'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; import { mocklistAssetsResponse } from '../../testing/mocks/data/listAssetsResponse'; const columnDefinitions = [ @@ -24,8 +25,7 @@ const sitewiseResourceExplorerSpec = async ( ) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, ...appKitInitOverrides, }); diff --git a/packages/components/src/components/iot-scatter-chart/iot-scatter-chart.spec.ts b/packages/components/src/components/iot-scatter-chart/iot-scatter-chart.spec.ts index cd58fd6fb..1f11417d3 100644 --- a/packages/components/src/components/iot-scatter-chart/iot-scatter-chart.spec.ts +++ b/packages/components/src/components/iot-scatter-chart/iot-scatter-chart.spec.ts @@ -8,6 +8,7 @@ import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time import { CustomHTMLElement } from '../../testing/types'; import { DATA_STREAM } from '../../testing/mockWidgetProperties'; import { update } from '../../testing/update'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const viewport: MinimalLiveViewport = { duration: 1000, @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = { const scatterChartSpecPage = async (propOverrides: Partial = {}) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, }); appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM])); diff --git a/packages/components/src/components/iot-status-grid/iot-status-grid.spec.ts b/packages/components/src/components/iot-status-grid/iot-status-grid.spec.ts index 45aee331d..60933e81e 100644 --- a/packages/components/src/components/iot-status-grid/iot-status-grid.spec.ts +++ b/packages/components/src/components/iot-status-grid/iot-status-grid.spec.ts @@ -8,6 +8,7 @@ import { DATA_STREAM } from '../../testing/mockWidgetProperties'; import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector'; import { CustomHTMLElement } from '../../testing/types'; import { update } from '../../testing/update'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const viewport: MinimalLiveViewport = { duration: 1000, @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = { const statusGridSpecPage = async (propOverrides: Partial = {}) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, }); appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM])); diff --git a/packages/components/src/components/iot-status-timeline/iot-status-timeline.spec.ts b/packages/components/src/components/iot-status-timeline/iot-status-timeline.spec.ts index 733c62418..562d1a7d5 100644 --- a/packages/components/src/components/iot-status-timeline/iot-status-timeline.spec.ts +++ b/packages/components/src/components/iot-status-timeline/iot-status-timeline.spec.ts @@ -8,6 +8,7 @@ import { DATA_STREAM } from '../../testing/mockWidgetProperties'; import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector'; import { CustomHTMLElement } from '../../testing/types'; import { update } from '../../testing/update'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const viewport: MinimalLiveViewport = { duration: 1000, @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = { const statusTimelineSpecPage = async (propOverrides: Partial = {}) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, }); appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM])); diff --git a/packages/components/src/components/iot-table/iot-table.spec.ts b/packages/components/src/components/iot-table/iot-table.spec.ts index 2f548b7ab..5fb54dad3 100644 --- a/packages/components/src/components/iot-table/iot-table.spec.ts +++ b/packages/components/src/components/iot-table/iot-table.spec.ts @@ -8,6 +8,7 @@ import { DATA_STREAM } from '../../testing/mockWidgetProperties'; import { IotTimeSeriesConnector } from '../iot-time-series-connector.ts/iot-time-series-connector'; import { CustomHTMLElement } from '../../testing/types'; import { update } from '../../testing/update'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const viewport: MinimalLiveViewport = { duration: 1000, @@ -16,8 +17,7 @@ const viewport: MinimalLiveViewport = { const tableSpecPage = async (propOverrides: Partial = {}) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, }); appKit.registerTimeSeriesDataSource(createMockSource([DATA_STREAM])); diff --git a/packages/components/src/components/iot-time-series-connector.ts/iot-time-series-connector.spec.ts b/packages/components/src/components/iot-time-series-connector.ts/iot-time-series-connector.spec.ts index 5ee86c1cc..5edd1032c 100644 --- a/packages/components/src/components/iot-time-series-connector.ts/iot-time-series-connector.spec.ts +++ b/packages/components/src/components/iot-time-series-connector.ts/iot-time-series-connector.spec.ts @@ -5,8 +5,8 @@ import { initialize, SiteWiseDataStreamQuery, IoTAppKitInitInputs, - createMockSiteWiseSDK, query, + createMockSiteWiseSDK, } from '@iot-app-kit/core'; import { IotTimeSeriesConnector } from './iot-time-series-connector'; import { createMockSource } from '../../testing/createMockSource'; @@ -16,6 +16,7 @@ import { DATA_STREAM, DATA_STREAM_2 } from '../../testing/mockWidgetProperties'; import { toSiteWiseAssetProperty } from '../../testing/dataStreamId'; import { Components } from '../../components'; import { DescribeAssetResponse, DescribeAssetModelResponse } from '@aws-sdk/client-iotsitewise'; +import { mockSiteWiseSDK } from '../../testing/mocks/siteWiseSDK'; const createAssetResponse = ({ assetId, @@ -69,8 +70,7 @@ const viewport: MinimalLiveViewport = { const initializeAppKit = (appKitInitOverrides?: Partial) => { const appKit = initialize({ registerDataSources: false, - awsCredentials: { accessKeyId: 'test', secretAccessKey: 'test' }, - awsRegion: 'test', + iotSiteWiseClient: mockSiteWiseSDK, ...appKitInitOverrides, }); diff --git a/packages/components/src/testing/mocks/siteWiseSDK.ts b/packages/components/src/testing/mocks/siteWiseSDK.ts new file mode 100644 index 000000000..320d70c3e --- /dev/null +++ b/packages/components/src/testing/mocks/siteWiseSDK.ts @@ -0,0 +1,32 @@ +import { + createMockSiteWiseSDK, + createAssetResponse, + createAssetModelResponse, + ASSET_PROPERTY_VALUE_HISTORY, +} from '@iot-app-kit/core'; + +const PROPERTY_ID = 'some-property-id'; +const ASSET_MODEL_ID = 'some-asset-model-id'; +const PROPERTY_NAME = 'some-property-name'; + +const getAssetPropertyValueHistory = jest.fn().mockResolvedValue(ASSET_PROPERTY_VALUE_HISTORY); +const describeAsset = jest + .fn() + .mockImplementation(({ assetId }) => + Promise.resolve(createAssetResponse({ assetId: assetId as string, assetModelId: ASSET_MODEL_ID })) + ); +const describeAssetModel = jest.fn().mockImplementation(({ assetModelId }) => + Promise.resolve( + createAssetModelResponse({ + assetModelId: assetModelId as string, + propertyId: PROPERTY_ID, + propertyName: PROPERTY_NAME, + }) + ) +); + +export const mockSiteWiseSDK = createMockSiteWiseSDK({ + describeAsset, + describeAssetModel, + getAssetPropertyValueHistory, +}); diff --git a/packages/core/src/data-module/IotAppKitDataModule.spec.ts b/packages/core/src/data-module/IotAppKitDataModule.spec.ts index cd6e361d8..de0fa3af7 100644 --- a/packages/core/src/data-module/IotAppKitDataModule.spec.ts +++ b/packages/core/src/data-module/IotAppKitDataModule.spec.ts @@ -5,10 +5,9 @@ import { DataPoint } from '@synchro-charts/core'; import { TimeSeriesDataRequest, TimeSeriesDataRequestSettings } from './data-cache/requestTypes'; import { DataStreamsStore, DataStreamStore } from './data-cache/types'; import * as caching from './data-cache/caching/caching'; -import { createMockSiteWiseDataSource } from '../testing/mock-data-source/data-source'; +import { createMockSiteWiseDataSource } from '../iotsitewise/__mocks__/data-source'; import { HOUR_IN_MS, MINUTE_IN_MS, MONTH_IN_MS, SECOND_IN_MS } from '../common/time'; import { IotAppKitDataModule } from './IotAppKitDataModule'; - import { SITEWISE_DATA_SOURCE } from '../iotsitewise/time-series-data/data-source'; import { SiteWiseDataStreamQuery } from '../iotsitewise/time-series-data/types'; import { toDataStreamId, toSiteWiseAssetProperty } from '../iotsitewise/time-series-data/util/dataStreamId'; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 3381f143e..bb742ce2b 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,7 +1,7 @@ export * from './data-module/index'; export * from './asset-modules/index'; export * from './iotAppKit'; -export * from './iotsitewise/__mocks__/iotsitewiseSDK'; export * from './module-namespace'; export * from './query-namespace'; export * from './iotsitewise/time-series-data/provider'; +export * from './testing'; // @todo: build as a separate bundle diff --git a/packages/core/src/iotsitewise/__mocks__/assetPropertyValue.ts b/packages/core/src/iotsitewise/__mocks__/assetPropertyValue.ts index 27628c519..f0b899db4 100644 --- a/packages/core/src/iotsitewise/__mocks__/assetPropertyValue.ts +++ b/packages/core/src/iotsitewise/__mocks__/assetPropertyValue.ts @@ -3,8 +3,8 @@ import { GetAssetPropertyAggregatesResponse, GetAssetPropertyValueHistoryResponse, GetAssetPropertyValueResponse, - Quality -} from "@aws-sdk/client-iotsitewise"; + Quality, +} from '@aws-sdk/client-iotsitewise'; /** * Mocks, related to a SiteWise Assert property value @@ -99,6 +99,6 @@ export const samplePropertyValue: AssetPropertyValue = { quality: Quality.GOOD, timestamp: { timeInSeconds: 100, - offsetInNanos: 100 - } + offsetInNanos: 100, + }, }; diff --git a/packages/core/src/testing/mock-data-source/data-source.ts b/packages/core/src/iotsitewise/__mocks__/data-source.ts similarity index 100% rename from packages/core/src/testing/mock-data-source/data-source.ts rename to packages/core/src/iotsitewise/__mocks__/data-source.ts diff --git a/packages/core/src/iotsitewise/__mocks__/index.ts b/packages/core/src/iotsitewise/__mocks__/index.ts new file mode 100644 index 000000000..f185c92f3 --- /dev/null +++ b/packages/core/src/iotsitewise/__mocks__/index.ts @@ -0,0 +1,6 @@ +export * from './asset'; +export * from './assetModel'; +export * from './assetPropertyValue'; +export * from './iotsitewiseSDK'; +export * from './mockWidgetProperties'; +export * from './data-source'; diff --git a/packages/core/src/testing/index.ts b/packages/core/src/testing/index.ts index 8c5f7e7bd..608f3db50 100644 --- a/packages/core/src/testing/index.ts +++ b/packages/core/src/testing/index.ts @@ -1 +1 @@ -export * from './wait'; +export * from '../iotsitewise/__mocks__'; diff --git a/packages/core/src/testing/mock-data-source/index.ts b/packages/core/src/testing/mock-data-source/index.ts deleted file mode 100644 index af1d9b898..000000000 --- a/packages/core/src/testing/mock-data-source/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './data-source'; diff --git a/packages/core/src/testing/wait.ts b/packages/core/src/testing/wait.ts deleted file mode 100755 index 1448b0f92..000000000 --- a/packages/core/src/testing/wait.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Provide a simple way to wait a given period of time -export const wait = (waitMS: number = 100) => - new Promise((resolve) => { - setTimeout(() => { - resolve(undefined); - }, waitMS); - });