Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit cb0f924

Browse files
committed
fixed tests
1 parent e5845e0 commit cb0f924

File tree

13 files changed

+80
-64
lines changed

13 files changed

+80
-64
lines changed

benchmark/runtime/benchmarkTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,4 @@ export const startBundleBench = async (entry: string, isDev: boolean) => {
146146
);
147147

148148
console.log(metafile);
149-
// TODO analyze metafile
150149
};

packages/core/src/collection/group/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class Group<
155155
softRebuild: true,
156156
any: {},
157157
});
158-
config.any['trackedChanges'] = []; // TODO might be improved since the 'any' property is very vague
158+
config.any['trackedChanges'] = []; // TODO should be improved since the 'any' property is very vague
159159

160160
// Remove itemKeys from Group
161161
_itemKeys.forEach((itemKey) => {
@@ -228,7 +228,7 @@ export class Group<
228228
softRebuild: true,
229229
any: {},
230230
});
231-
config.any['trackedChanges'] = []; // TODO might be improved since the 'any' property is very vague
231+
config.any['trackedChanges'] = []; // TODO should be improved since the 'any' property is very vague
232232

233233
// Add itemKeys to Group
234234
_itemKeys.forEach((itemKey) => {
@@ -545,15 +545,18 @@ export enum TrackedChangeMethod {
545545

546546
export interface TrackedChangeInterface {
547547
/**
548-
* TODO
548+
* What type of change the tracked change is.
549+
* @default undefined
549550
*/
550551
method: TrackedChangeMethod;
551552
/**
552-
* TODO
553+
* Item key of the tracked change.
554+
* @default undefined
553555
*/
554556
key: ItemKey;
555557
/**
556-
* TODO
558+
* Current index in the Group value of the tracked change.
559+
* @default undefined
557560
*/
558561
index: number;
559562
}

packages/core/src/runtime/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './subscription';
21
export * from './runtime';
2+
export * from './subscription';
33
export * from './observer';
44
export * from './runtime.job';

packages/core/tests/unit/agile.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ import testIntegration from '../helper/test.integration';
33
import { LogMock } from '../helper/logMock';
44

55
// https://github.com/facebook/jest/issues/5023
6-
jest.mock('../../src/runtime', () => {
6+
jest.mock('../../src/runtime/runtime', () => {
77
return {
88
// https://jestjs.io/docs/mock-function-api#mockfnmockimplementationfn
9-
Runtime: jest.fn().mockImplementation(() => {
10-
return {
11-
ingest: jest.fn(),
12-
};
13-
}),
9+
Runtime: jest.fn(),
1410
};
1511
});
1612
jest.mock('../../src/runtime/subscription/sub.controller', () => {
@@ -21,7 +17,7 @@ jest.mock('../../src/runtime/subscription/sub.controller', () => {
2117

2218
// https://gist.github.com/virgs/d9c50e878fc69832c01f8085f2953f12
2319
// https://medium.com/@masonlgoetz/mock-static-class-methods-in-jest-1ceda967b47f
24-
jest.mock('../../src/integrations', () => {
20+
jest.mock('../../src/integrations/integrations', () => {
2521
const mockedInstances = {
2622
// https://jestjs.io/docs/mock-function-api#mockfnmockimplementationfn
2723
Integrations: jest.fn().mockImplementation(() => {
@@ -32,9 +28,8 @@ jest.mock('../../src/integrations', () => {
3228
}),
3329
};
3430
// @ts-ignore
35-
mockedInstances.Integrations.onRegisteredExternalIntegration = jest.fn();
36-
// @ts-ignore
3731
mockedInstances.Integrations.initialIntegrations = [];
32+
3833
return mockedInstances;
3934
});
4035

packages/core/tests/unit/state/state.enhanced.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,49 @@ describe('Enhanced State Tests', () => {
143143
});
144144

145145
describe('setKey function tests', () => {
146-
// TODO
146+
beforeEach(() => {
147+
numberState.persistent = new StatePersistent(numberState);
148+
149+
numberState.persistent.setKey = jest.fn();
150+
jest.spyOn(State.prototype, 'setKey');
151+
});
152+
153+
it("should call 'setKey()' in the State and update the Persistent key", () => {
154+
if (numberState.persistent)
155+
numberState.persistent._key = numberState._key as any;
156+
157+
numberState.setKey('newKey');
158+
159+
expect(State.prototype.setKey).toHaveBeenCalledWith('newKey');
160+
expect(numberState.persistent?.setKey).toHaveBeenCalledWith('newKey');
161+
});
162+
163+
it(
164+
"should call 'setKey()' in the State " +
165+
"and shouldn't update the Persistent key if the specified StateKey and PersistKey differentiate",
166+
() => {
167+
if (numberState.persistent) numberState.persistent._key = 'randomKey';
168+
169+
numberState.setKey('newKey');
170+
171+
expect(State.prototype.setKey).toHaveBeenCalledWith('newKey');
172+
expect(numberState.persistent?.setKey).not.toHaveBeenCalled();
173+
}
174+
);
175+
176+
it(
177+
"should call 'setKey()' in the State " +
178+
"and shouldn't update the Persistent key if the specified StateKey is undefined",
179+
() => {
180+
if (numberState.persistent)
181+
numberState.persistent._key = numberState._key as any;
182+
183+
numberState.setKey(undefined);
184+
185+
expect(State.prototype.setKey).toHaveBeenCalledWith(undefined);
186+
expect(numberState.persistent?.setKey).not.toHaveBeenCalled();
187+
}
188+
);
147189
});
148190

149191
describe('undo function tests', () => {

packages/core/tests/unit/state/state.test.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
} from '../../../src';
88
import { LogMock } from '../../helper/logMock';
99

10-
jest.mock('../../../src/state/state.persistent');
11-
1210
describe('State Tests', () => {
1311
let dummyAgile: Agile;
1412

@@ -164,29 +162,13 @@ describe('State Tests', () => {
164162
numberState.observers['output'] = dummyOutputObserver;
165163
});
166164

167-
it('should update existing Key in all instances', () => {
165+
it('should update the key indicator of the State and all associated Observers', () => {
168166
numberState.setKey('newKey');
169167

170168
expect(numberState._key).toBe('newKey');
171169
expect(numberState.observers['value']._key).toBe('newKey');
172170
expect(numberState.observers['output']._key).toBe('newKey');
173171
});
174-
175-
it("should update existing Key in all instances except persistent if the StateKey and PersistKey aren't equal", () => {
176-
numberState.setKey('newKey');
177-
178-
expect(numberState._key).toBe('newKey');
179-
expect(numberState.observers['value']._key).toBe('newKey');
180-
expect(numberState.observers['output']._key).toBe('newKey');
181-
});
182-
183-
it('should update existing Key in all instances except persistent if new StateKey is undefined', () => {
184-
numberState.setKey(undefined);
185-
186-
expect(numberState._key).toBeUndefined();
187-
expect(numberState.observers['value']._key).toBeUndefined();
188-
expect(numberState.observers['output']._key).toBeUndefined();
189-
});
190172
});
191173

192174
describe('set function tests', () => {
@@ -249,10 +231,9 @@ describe('State Tests', () => {
249231

250232
LogMock.hasNotLogged('warn');
251233
LogMock.hasNotLogged('error');
252-
expect(numberState.observers['value'].ingestValue).toHaveBeenCalledWith(
253-
'coolValue',
254-
{ force: false }
255-
);
234+
expect(
235+
numberState.observers['value'].ingestValue
236+
).toHaveBeenCalledWith('coolValue', { force: false });
256237
});
257238
});
258239

packages/event/src/event/event.observer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
ObserverKey,
55
SubscriptionContainer,
66
} from '@agile-ts/core';
7-
import { Event } from '../internal';
7+
import { Event } from './event';
88

99
export class EventObserver<PayloadType = any> extends Observer {
1010
public event: () => Event<PayloadType>;

packages/event/src/event/event.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {
55
LogCodeManager,
66
Observer,
77
} from '@agile-ts/core';
8-
import { EventObserver, EventRuntimeJob } from '../internal';
98
import { defineConfig } from '@agile-ts/utils';
9+
import { EventObserver } from './event.observer';
10+
import { EventRuntimeJob } from './event.runtime.job';
1011

1112
export class Event<PayloadType = DefaultEventPayload> {
1213
public agileInstance: () => Agile;

packages/event/src/event/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { CreateAgileSubInstanceInterface, shared } from '@agile-ts/core';
2+
import { defineConfig, removeProperties } from '@agile-ts/utils';
13
import {
24
CreateEventConfigInterface,
35
DefaultEventPayload,
46
Event,
57
} from './event';
6-
import { defineConfig, removeProperties } from '@agile-ts/utils';
7-
import { CreateAgileSubInstanceInterface, shared } from '@agile-ts/core';
88

99
export * from './event';
10-
// export * from './event.observer';
11-
// export * from './event.job';
10+
export * from './event.observer';
11+
export * from './event.runtime.job';
1212

1313
export function createEvent<PayloadType = DefaultEventPayload>(
1414
config: CreateEventConfigInterfaceWithAgile = {}

packages/event/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Event } from './internal';
1+
import { Event } from './event';
22

3-
export * from './internal';
3+
export * from './event';
44
export default Event;

0 commit comments

Comments
 (0)