Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-382 Fix to load tree with default filters #385

Merged
merged 2 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ModelSelectorTreeComponent } from './model-selector-tree.component';
import { UIRouterModule } from '@uirouter/angular';
import { ToastrModule } from 'ngx-toastr';
Expand All @@ -29,12 +28,24 @@ import { FoldersTreeModule } from '@mdm/folders-tree/folders-tree.module';
import { MdmResourcesService } from '@mdm/modules/resources';
import { ByteArrayToBase64Pipe } from '@mdm/pipes/byte-array-to-base64.pipe';
import { MatTooltipModule } from '@angular/material/tooltip';
import { SecurityHandlerService } from '@mdm/services';
import { empty } from 'rxjs';
import { ContainerDomainType } from '@maurodatamapper/mdm-resources';

interface SecurityHandlerServiceStub {
isLoggedIn: jest.Mock;
}

describe('ModelSelectorTreeComponent', () => {
let component: ModelSelectorTreeComponent;
let fixture: ComponentFixture<ModelSelectorTreeComponent>;

let treeSpy: any;

const securityHandler: SecurityHandlerServiceStub = {
isLoggedIn: jest.fn(() => false)
};

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
Expand All @@ -57,6 +68,10 @@ describe('ModelSelectorTreeComponent', () => {
}
}
},
{
provide: SecurityHandlerService,
useValue: securityHandler
},
ElementTypesService
],
declarations: [
Expand All @@ -72,9 +87,21 @@ describe('ModelSelectorTreeComponent', () => {
fixture = TestBed.createComponent(ModelSelectorTreeComponent);
component = fixture.componentInstance;
fixture.detectChanges();

treeSpy = spyOn(component['resources'].tree, 'list').and.callThrough();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('load tree with filter applied', () => {
const defaultQueryStringParams: any = {
includeDocumentSuperseded: true,
includeModelSuperseded: true,
includeDeleted: true
};
component.reload();
expect(treeSpy).toHaveBeenCalledWith(ContainerDomainType.Folders, defaultQueryStringParams);
});
});
4 changes: 2 additions & 2 deletions src/app/model-selector-tree/model-selector-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class ModelSelectorTreeComponent implements OnInit, OnChanges {
loadTree(model) {
const id = (model && model.id) ? model.id : null;
this.loading = true;
let options = {};
let options: any = {};
if (!this.doNotApplySettingsFilter && this.securityHandler.isLoggedIn()) {
if (this.userSettingsHandler.get('includeSupersededDocModels') || false) {
options = {
Expand All @@ -262,7 +262,7 @@ export class ModelSelectorTreeComponent implements OnInit, OnChanges {
};
}

let method = this.resources.tree.list(ContainerDomainType.Folders, options);
let method = this.resources.tree.list(ContainerDomainType.Folders, options.queryStringParams);


if (id) {
Expand Down