Skip to content

Commit

Permalink
remove @ngxp/store-service dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
luchsamapparat committed Mar 22, 2024
1 parent 57d506e commit b21c7f6
Show file tree
Hide file tree
Showing 27 changed files with 286 additions and 223 deletions.
17 changes: 0 additions & 17 deletions components/tasklist-angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion components/tasklist-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@ngrx/effects": "^16.3.0",
"@ngrx/store": "^16.3.0",
"@ngrx/store-devtools": "^16.3.0",
"@ngxp/store-service": "^16.0.0",
"@popperjs/core": "^2.11.8",
"bootstrap": "^5.3.3",
"font-awesome": "4.7.0",
Expand Down
18 changes: 12 additions & 6 deletions ...try-list/datanetry-list.component.spec.ts → ...try-list/dataentry-list.component.spec.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { provideMockStore } from '@ngrx/store/testing';

import { DataentryListComponent } from 'app/dataentry/dataentry-list/dataentry-list.component';
import { FormsModule } from '@angular/forms';
import { DataentryListComponent } from 'app/dataentry/dataentry-list/dataentry-list.component';

import { provideStoreServiceMock } from '@ngxp/store-service/testing';
import { DataentryStoreService } from 'app/dataentry/state/dataentry.store-service';
import { SharedModule } from 'app/shared/shared.module';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { SharedModule } from 'app/shared/shared.module';
import { dataEntries } from '../state/dataentry.selectors';
import { DataentryStoreService } from '../state/dataentry.store-service';

describe('Component: DataentrylistComponent', () => {

Expand All @@ -25,8 +26,11 @@ describe('Component: DataentrylistComponent', () => {
DataentryListComponent
],
providers: [
provideStoreServiceMock(DataentryStoreService, {
dataEntries$: []
DataentryStoreService,
provideMockStore({
selectors: [
{ selector: dataEntries, value: [] }
]
}),
],
}).compileComponents().then(() => {
Expand All @@ -41,6 +45,8 @@ describe('Component: DataentrylistComponent', () => {
});
}));



it('should create', () => {
expect(component).toBeDefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { DataentryStoreService } from 'app/dataentry/state/dataentry.store-servi
})
export class DataentryListComponent {

dataEntries$ = this.dataEntryStore.dataEntries$();
dataEntries$ = this.dataEntryStore.dataEntries$;
currentDataTab = 'description';
itemsPerPage: number;
totalItems: any;
page: number;

constructor(
private dataEntryStore: DataentryStoreService,
) { }
) { }

toFieldSet(payload: any) {
const payloadProps = Object.keys(payload);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { DataentryEffects } from './dataentry.effects';
import { Action } from '@ngrx/store';
import { of } from 'rxjs';
import { Actions } from '@ngrx/effects';
import { BusinessDataService } from 'tasklist/services';
import { UserStoreService } from 'app/user/state/user.store-service';
import { createStoreServiceMock } from '@ngxp/store-service/testing';
import { Action } from '@ngrx/store';
import { createMockStore } from '@ngrx/store/testing';
import { dataEntriesLoaded, loadDataEntries } from 'app/dataentry/state/dataentry.actions';
import { DataEntry } from 'app/dataentry/state/dataentry.reducer';
import { currentUserId } from 'app/user/state/user.selectors';
import { UserStoreService } from 'app/user/state/user.store-service';
import { of } from 'rxjs';
import { BusinessDataService } from 'tasklist/services';
import { DataentryEffects } from './dataentry.effects';

describe('DataEntryEffects', () => {

Expand All @@ -16,8 +17,11 @@ describe('DataEntryEffects', () => {
beforeEach(() => {
businessDataService = new BusinessDataService(null, null);
// default user store to be overridden in test if needed.
userStore = createStoreServiceMock(UserStoreService,
{ userId$: 'kermit' });
userStore = new UserStoreService(createMockStore({
selectors: [
{ selector: currentUserId, value: 'kermit' }
]
}))
});

function effectsFor(action: Action): DataentryEffects {
Expand All @@ -36,10 +40,12 @@ describe('DataEntryEffects', () => {

// when:
effectsFor(action).loadDataEntries$.subscribe((newAction) => {
expect(newAction).toEqual(dataEntriesLoaded({dataEntries: [
{ name: 'foo', description: '', url: '', type: 'type', payload: {}, currentState: 'MY STATE', currentStateType: '', protocol: [] },
{ name: 'bar', description: '', url: '', type: 'type2', payload: {}, currentState: 'MY STATE2', currentStateType: '', protocol: [] }
]}));
expect(newAction).toEqual(dataEntriesLoaded({
dataEntries: [
{ name: 'foo', description: '', url: '', type: 'type', payload: {}, currentState: 'MY STATE', currentStateType: '', protocol: [] },
{ name: 'bar', description: '', url: '', type: 'type2', payload: {}, currentState: 'MY STATE2', currentStateType: '', protocol: [] }
]
}));
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { UserStoreService } from 'app/user/state/user.store-service';
import { BusinessDataService } from 'tasklist/services';
import { dataEntriesLoaded, loadDataEntries } from 'app/dataentry/state/dataentry.actions';
import { catchError, filter, map, mergeMap, withLatestFrom } from 'rxjs/operators';
import { DataEntry as DataEntryDto } from 'tasklist/models';
import { DataEntry } from 'app/dataentry/state/dataentry.reducer';
import { selectUser } from 'app/user/state/user.actions';
import { StrictHttpResponse } from 'tasklist/strict-http-response';
import { UserStoreService } from 'app/user/state/user.store-service';
import { of } from 'rxjs';
import { catchError, filter, map, mergeMap, withLatestFrom } from 'rxjs/operators';
import { DataEntry as DataEntryDto } from 'tasklist/models';
import { BusinessDataService } from 'tasklist/services';
import { StrictHttpResponse } from 'tasklist/strict-http-response';

@Injectable()
export class DataentryEffects {
Expand All @@ -27,12 +27,12 @@ export class DataentryEffects {

loadDataEntries$ = createEffect(() => this.actions$.pipe(
ofType(loadDataEntries),
withLatestFrom(this.userStore.userId$()),
withLatestFrom(this.userStore.userId$),
mergeMap(([_, userId]) => this.businessDataService.getBusinessDataEntries$Response({
'X-Current-User-ID': userId
})),
map(dataEntriesDtos => mapFromDto(dataEntriesDtos)),
map(dataEntries => dataEntriesLoaded({dataEntries})),
map(dataEntries => dataEntriesLoaded({ dataEntries })),
catchError(err => {
console.log('Error loading data entries:', err);
return of();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {dataEntries, StateWithDataEntries} from 'app/dataentry/state/dataentry.selectors';
import { dataEntries, StateWithDataEntries } from 'app/dataentry/state/dataentry.selectors';

describe('user selectors', () => {
describe('data entry selectors', () => {
const state: StateWithDataEntries = {
archive: {
dataEntries: [
{name: 'foo', description: '', url: '', type: 'type', payload: {}, currentState: 'MY STATE', currentStateType: '', protocol: []},
{name: 'bar', description: '', url: '', type: 'type2', payload: {}, currentState: 'MY STATE2', currentStateType: '', protocol: []}
{ name: 'foo', description: '', url: '', type: 'type', payload: {}, currentState: 'MY STATE', currentStateType: '', protocol: [] },
{ name: 'bar', description: '', url: '', type: 'type2', payload: {}, currentState: 'MY STATE2', currentStateType: '', protocol: [] }
]
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Injectable } from '@angular/core';
import { dispatch, select, StoreService } from '@ngxp/store-service';
import { DataEntryState } from './dataentry.reducer';
import { dataEntries } from './dataentry.selectors';
import { Store } from '@ngrx/store';
import { loadDataEntries } from './dataentry.actions';
import { dataEntries, StateWithDataEntries } from './dataentry.selectors';

@Injectable()
export class DataentryStoreService extends StoreService<DataEntryState> {
export class DataentryStoreService {

dataEntries$ = select(dataEntries);
constructor(
private store: Store<StateWithDataEntries>
) { }

loadDataEntries = dispatch(loadDataEntries);
dataEntries$ = this.store.select(dataEntries);

loadDataEntries() {
this.store.dispatch(loadDataEntries());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import {ProcesslistComponent} from './process-list.component';
import {FormsModule} from '@angular/forms';
import {provideStoreServiceMock} from '@ngxp/store-service/testing';
import {ProcessStoreService} from 'app/process/state/process.store-service';
import { FormsModule } from '@angular/forms';
import { provideMockStore } from '@ngrx/store/testing';
import { startableProcesses } from '../state/process.selectors';
import { ProcessStoreService } from '../state/process.store-service';
import { ProcesslistComponent } from './process-list.component';

describe('Component: TasklistComponent', () => {

Expand All @@ -20,7 +21,12 @@ describe('Component: TasklistComponent', () => {
ProcesslistComponent
],
providers: [
provideStoreServiceMock(ProcessStoreService)
ProcessStoreService,
provideMockStore({
selectors: [
{ selector: startableProcesses, value: [] }
]
})
],
}).compileComponents().then(() => {
// create component and test fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ProcessStoreService } from 'app/process/state/process.store-service';
})
export class ProcesslistComponent {

processes$ = this.processStore.startableProcesses$();
processes$ = this.processStore.startableProcesses$;

constructor(
private processStore: ProcessStoreService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ProcessEffects } from './process.effects';
import { Action } from '@ngrx/store';
import { of } from 'rxjs';
import { Actions } from '@ngrx/effects';
import { ProcessService } from 'tasklist/services';
import { UserStoreService } from 'app/user/state/user.store-service';
import { createStoreServiceMock } from '@ngxp/store-service/testing';
import { Action } from '@ngrx/store';
import { createMockStore } from '@ngrx/store/testing';
import { loadStartableProcessDefinitions } from 'app/process/state/process.actions';
import { currentUserId } from 'app/user/state/user.selectors';
import { UserStoreService } from 'app/user/state/user.store-service';
import { of } from 'rxjs';
import { ProcessDefinition as ApiProcessDefinition } from 'tasklist/models/process-definition';
import { ProcessService } from 'tasklist/services';
import { ProcessEffects } from './process.effects';

describe('ProcessEffects', () => {

Expand All @@ -16,8 +17,11 @@ describe('ProcessEffects', () => {
beforeEach(() => {
processService = new ProcessService(null, null);
// default user store to be overridden in test if needed.
userStore = createStoreServiceMock(UserStoreService,
{userId$: 'kermit'});
userStore = new UserStoreService(createMockStore({
selectors: [
{ selector: currentUserId, value: 'kermit' }
]
}));
});

function effectsFor(action: Action): ProcessEffects {
Expand All @@ -28,19 +32,23 @@ describe('ProcessEffects', () => {
// given:
const action = loadStartableProcessDefinitions();
const procDtos: ApiProcessDefinition[] = [
{processName: 'foo', description: '', url: '', candidateGroups: [], candidateUsers: [], definitionId: 'foo-id',
definitionKey: 'foo-key', definitionVersion: '', versionTag: '1'},
{processName: 'bar', description: '', url: '', candidateGroups: [], candidateUsers: [], definitionId: 'foo-id',
definitionKey: 'foo-key', definitionVersion: '', versionTag: '2'}
{
processName: 'foo', description: '', url: '', candidateGroups: [], candidateUsers: [], definitionId: 'foo-id',
definitionKey: 'foo-key', definitionVersion: '', versionTag: '1'
},
{
processName: 'bar', description: '', url: '', candidateGroups: [], candidateUsers: [], definitionId: 'foo-id',
definitionKey: 'foo-key', definitionVersion: '', versionTag: '2'
}
];
const serviceSpy = spyOn(processService, 'getStartableProcesses').and.returnValue(of(procDtos));

// when:
effectsFor(action).loadStartableProcesses$.subscribe((newAction) => {
expect(serviceSpy).toHaveBeenCalled();
expect(newAction.definitions).toEqual([
{ name: 'foo', description: '', url: ''},
{ name: 'bar', description: '', url: ''}
{ name: 'foo', description: '', url: '' },
{ name: 'bar', description: '', url: '' }
]);
done();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { UserStoreService } from 'app/user/state/user.store-service';
import { ProcessService } from 'tasklist/services';
import { loadStartableProcessDefinitions, startableProcessDefinitionsLoaded } from 'app/process/state/process.actions';
import { filter, map, mergeMap, withLatestFrom } from 'rxjs/operators';
import { ProcessDefinition as ProcessDto } from 'tasklist/models';
import { ProcessDefinition } from 'app/process/state/process.reducer';
import { selectUser } from 'app/user/state/user.actions';
import { UserStoreService } from 'app/user/state/user.store-service';
import { filter, map, mergeMap, withLatestFrom } from 'rxjs/operators';
import { ProcessDefinition as ProcessDto } from 'tasklist/models';
import { ProcessService } from 'tasklist/services';

@Injectable()
export class ProcessEffects {
Expand All @@ -25,12 +25,12 @@ export class ProcessEffects {

loadStartableProcesses$ = createEffect(() => this.actions$.pipe(
ofType(loadStartableProcessDefinitions),
withLatestFrom(this.userStore.userId$()),
withLatestFrom(this.userStore.userId$),
mergeMap(([_, userId]) => this.processService.getStartableProcesses({
'X-Current-User-ID': userId
})),
map(procDtos => mapFromDto(procDtos)),
map(definitions => startableProcessDefinitionsLoaded({definitions}))
map(definitions => startableProcessDefinitionsLoaded({ definitions }))
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Injectable } from '@angular/core';
import { dispatch, select, StoreService } from '@ngxp/store-service';
import { ProcessState } from './process.reducer';
import { startableProcesses } from './process.selectors';
import { Store } from '@ngrx/store';
import { loadStartableProcessDefinitions } from './process.actions';
import { StateWithProcesses, startableProcesses } from './process.selectors';

@Injectable()
export class ProcessStoreService extends StoreService<ProcessState> {
export class ProcessStoreService {

startableProcesses$ = select(startableProcesses);
constructor(
private store: Store<StateWithProcesses>
) { }

loadStartableProcessDefinitions = dispatch(loadStartableProcessDefinitions);
startableProcesses$ = this.store.select(startableProcesses);

loadStartableProcessDefinitions() {
this.store.dispatch(loadStartableProcessDefinitions());
}
}
Loading

0 comments on commit b21c7f6

Please sign in to comment.