Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
montgomp committed Nov 5, 2021
1 parent 43da209 commit 6a8dc92
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('deviceSettingsPerInterfacePerSetting', () => {
expect(schemaLabel.props().children).toEqual(schema);

const valueLabel = wrapper.find(Label).at(3); // tslint:disable-line:no-magic-numbers
expect(valueLabel.props().children).toEqual('false');
expect(valueLabel.props().children).toEqual('{\"value\":false}');
});

it('renders when there is a writable property of complex type with sync status', () => {
Expand Down
14 changes: 11 additions & 3 deletions src/app/devices/pnp/sagas/getModelDefinitionSaga.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import 'jest';
import { call, put } from 'redux-saga/effects';
// tslint:disable-next-line: no-implicit-dependencies
import { SagaIteratorClone, cloneableGenerator } from '@redux-saga/testing-utils';
import { getModelDefinitionSaga,
import {
getModelDefinitionSaga,
getModelDefinition,
getModelDefinitionFromPublicRepo,
getModelDefinitionFromLocalFile,
validateModelDefinitionHelper,
getFlattenedModel, getModelDefinitionFromConfigurableRepo
getFlattenedModel,
getModelDefinitionFromConfigurableRepo,
expandFromExtendedModel
} from './getModelDefinitionSaga';
import { raiseNotificationToast } from '../../../notifications/components/notificationToast';
import { NotificationType } from '../../../api/models/notification';
Expand Down Expand Up @@ -87,10 +90,15 @@ describe('modelDefinition sagas', () => {
call(validateModelDefinitionHelper, modelDefinition, { repositoryLocationType: REPOSITORY_LOCATION_TYPE.Public })
);
});
it('checks for extends', () => {
expect(getModelDefinitionSagaGenerator.next(true).value).toEqual(
call(expandFromExtendedModel, action, { repositoryLocationType: REPOSITORY_LOCATION_TYPE.Public}, modelDefinition)
);
});

it('puts the successful action', () => {
const success = getModelDefinitionSagaGenerator.clone();
expect(success.next(true)).toEqual({
expect(success.next()).toEqual({
done: false,
value: put((getModelDefinitionAction.done({
params,
Expand Down
14 changes: 10 additions & 4 deletions src/app/devices/pnp/sagas/getModelDefinitionSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License
**********************************************************/
import { call, put } from 'redux-saga/effects';
import { call, CallEffect, put } from 'redux-saga/effects';
import { Action } from 'typescript-fsa';
import { fetchModelDefinition } from '../../../api/services/publicDigitalTwinsModelRepoService';
import { raiseNotificationToast } from '../../../notifications/components/notificationToast';
Expand Down Expand Up @@ -138,13 +138,16 @@ export function* getModelDefinition(action: Action<GetModelDefinitionActionParam
}

// tslint:disable-next-line
export function* expandFromExtendedModel(action: any, location: RepositoryLocationSettings, model: ModelDefinition) {
export function* expandFromExtendedModel(action: any, location: RepositoryLocationSettings, model: ModelDefinition): Generator<CallEffect<any>, ModelDefinition, ModelDefinition> {
const extendsVal = model.extends;
if (extendsVal) {
if (typeof (extendsVal) === 'string') {
const newAction: Action<GetModelDefinitionActionParameters> = { ...action };
newAction.payload.interfaceId = extendsVal;
const baseModel: ModelDefinition = yield call(getModelDefinition, newAction, location);
let baseModel: ModelDefinition = yield call(getModelDefinition, newAction, location);
if (baseModel.extends) {
baseModel = yield call(expandFromExtendedModel, newAction, location, baseModel);
}
model.contents = model.contents.concat(baseModel.contents);
return model;
}
Expand All @@ -153,7 +156,10 @@ export function* expandFromExtendedModel(action: any, location: RepositoryLocati
for (const newInterface of extendsVal) {
const newAction: Action<GetModelDefinitionActionParameters> = { ...action };
newAction.payload.interfaceId = newInterface;
const baseModel: ModelDefinition = yield call(getModelDefinition, newAction, location);
let baseModel: ModelDefinition = yield call(getModelDefinition, newAction, location);
if (baseModel.extends) {
baseModel = yield call(expandFromExtendedModel, newAction, location, baseModel);
}
extendedModel.contents = extendedModel.contents.concat(baseModel.contents);
}
return extendedModel;
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/utils/jsonSchemaAdaptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('parse interface model definition to Json schema', () => {
{
definitions: {},
enum: ['1', '2'],
enumNames : ['offline', 'online'],
enumNames : ['Offline', 'Online'],
required: [],
title: enumbTypeProperty.name,
type: 'string'
Expand Down

0 comments on commit 6a8dc92

Please sign in to comment.