Skip to content

Commit

Permalink
Merge GT-2095-Tool-Groups into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-branch-merger[bot] authored Oct 31, 2023
2 parents 91f4fa9 + 984cebc commit ce06643
Show file tree
Hide file tree
Showing 21 changed files with 575 additions and 868 deletions.
54 changes: 33 additions & 21 deletions src/app/_tests/toolGroupMocks.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { LanguageBCP47 } from "../service/languages-bcp47-tag.service";
import { Resource } from "../models/resource";
import { CountriesType, ToolGroup } from "../models/tool-group";
import { Language } from '../models/language';
import { Resource } from '../models/resource';
import { CountriesType, ToolGroup } from '../models/tool-group';

export class ToolGroupMocks {

languageUKMock = {
code: 'en-GB',
language: 'English',
region: 'United Kingdom',
name: 'English (British)',
} as LanguageBCP47;
id: 5,
customPages: null,
canConfirmDelete: null,
} as Language;

languageUSMock = {
code: 'en-US',
language: 'English',
region: 'United States of America',
name: 'English (American)',
} as LanguageBCP47;
id: 2,
customPages: null,
canConfirmDelete: null,
} as Language;

countryUKMock = {
code: 'GB',
Expand All @@ -26,7 +27,7 @@ export class ToolGroupMocks {
continent: 'EU',
capital: 'London',
currency: ['GBP'],
languages: ['en']
languages: ['en'],
} as CountriesType;

countryUSMock = {
Expand All @@ -37,16 +38,27 @@ export class ToolGroupMocks {
continent: 'NA',
capital: 'Washington D.C.',
currency: ['USD', 'USN', 'USS'],
languages: ['en']
languages: ['en'],
} as CountriesType;

getLanguagesResponse = [
{
code: 'ar-SA',
name: 'Arabic (Saudi Arabia)',
id: 9,
customPages: null,
canConfirmDelete: null,
},
this.languageUKMock,
this.languageUSMock,
] as Language[];

toolGroupFullDetails = () => {
const resource = new Resource();
resource.id = 13;
resource.name = 'Test Resource';

return {
return ({
id: 8,
'suggestions-weight': '3.0',
name: 'Test Tool Group',
Expand All @@ -58,7 +70,7 @@ export class ToolGroupMocks {
id: 8,
},
countries: [this.countryUKMock.code, this.countryUSMock.code],
}
},
],
'rules-language': [
{
Expand All @@ -68,7 +80,7 @@ export class ToolGroupMocks {
id: 8,
},
languages: [this.languageUKMock.code, this.languageUSMock.code],
}
},
],
'rules-praxis': [
{
Expand All @@ -77,9 +89,9 @@ export class ToolGroupMocks {
'tool-group': {
id: 8,
},
confidence: ['1','2'],
confidence: ['1', '2'],
openness: ['3'],
}
},
],
tools: [
{
Expand All @@ -89,13 +101,13 @@ export class ToolGroupMocks {
tool: {
...resource,
id: 15,
name: 'Resource Name'
name: 'Resource Name',
},
'tool-group': {
id: 8,
},
}
},
],
} as unknown as ToolGroup;
}
} as unknown) as ToolGroup;
};
}
2 changes: 0 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import { ToolGroupsComponent } from './components/tool-groups/tool-groups.compon
import { ToolGroupService } from './service/tool-group/tool-group.service';
import { CreateToolGroupComponent } from './components/edit-tool-group/create-tool-group/create-tool-group.component';
import { ToolGroupComponent } from './components/tool-group/tool-group.component';
import { LanguageBCP47Service } from './service/languages-bcp47-tag.service';
import { UpdateToolGroupComponent } from './components/edit-tool-group/update-tool-group/update-tool-group.component';
import { ToolGroupRuleComponent } from './components/edit-tool-group-rule/tool-group-rule.component';
import { ToolGroupRuleReuseableComponent } from './components/edit-tool-group-rule-reuseable/tool-group-rule-reuseable.component';
Expand Down Expand Up @@ -132,7 +131,6 @@ import { ToolGroupResourceComponent } from './components/edit-tool-group-resourc
UserAuthSessionService,
AttributeTranslationService,
ToolGroupService,
LanguageBCP47Service,
],
entryComponents: [
UpdateResourceComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { ToolGroupService } from '../../service/tool-group/tool-group.service';
import { ResourceService } from '../../service/resource/resource.service';
import { Resource } from '../../models/resource';
import { ToolGroupMocks } from '../../_tests/toolGroupMocks'
import { ToolGroupMocks } from '../../_tests/toolGroupMocks';
import { ToolGroupResourceComponent } from './tool-group-resource.component';
import { ToolGroupToolReuseableComponent } from '../edit-tool-group-tool-reuseable/tool-group-tool-reuseable.component';
import { Tools } from '../../models/tool-group';
Expand Down Expand Up @@ -34,8 +34,8 @@ describe('ToolGroupResourceComponent', () => {
...new Resource(),
id: 13,
name: 'Test Resource',
}
]
},
];
const mocks = new ToolGroupMocks();
const toolGroupFullDetails = mocks.toolGroupFullDetails();

Expand Down Expand Up @@ -63,124 +63,117 @@ describe('ToolGroupResourceComponent', () => {
providers: [
{ provide: ToolGroupService, useValue: toolGroupServiceStub },
{ provide: ResourceService, useValue: resourceServiceStub },
{ provide: NgbActiveModal, useValue: activeModalStub },
{ provide: NgbActiveModal, useValue: activeModalStub },
],
}).compileComponents();

fixture = TestBed.createComponent(ToolGroupResourceComponent);
comp = fixture.componentInstance;


comp.toolGroup = toolGroupFullDetails
comp.toolGroup = toolGroupFullDetails;
comp.resources = resources;
});

describe('ngOnInit', () => {

it('should assign tools', () => {
comp.ngOnInit();
expect(comp.initialTools).toEqual(toolGroupFullDetails.tools)
expect(comp.tools).toEqual(toolGroupFullDetails.tools)
expect(comp.initialTools).toEqual(toolGroupFullDetails.tools);
expect(comp.tools).toEqual(toolGroupFullDetails.tools);
});

it('should create new Tool', () => {
comp.toolGroup.tools = []
comp.toolGroup.tools = [];
comp.ngOnInit();
expect(comp.initialTools).toEqual([])
expect(comp.tools[0].tool).toEqual(undefined)
expect(comp.initialTools).toEqual([]);
expect(comp.tools[0].tool).toEqual(undefined);
});


it('should re-fetch resources', () => {
comp.resources = []
comp.resources = [];
comp.ngOnInit();
expect(resourceServiceStub.getResources).toHaveBeenCalled();
});
});

describe('updateTool() & deleteTool()', () => {
const tool = toolGroupFullDetails.tools[0] as unknown as Tools;
const tool = (toolGroupFullDetails.tools[0] as unknown) as Tools;
beforeEach(() => {
comp.ngOnInit();
comp.tools = [
{
...tool
...tool,
},
{
...tool,
id: '5',
}
]
})
},
];
});

it('should update suggestionsWeight - updateTool()', (done) => {
tool.suggestionsWeight = '50';
comp.updateTool(tool);
setTimeout(() => {
console.log('comp.tools', comp.tools)
expect(comp.tools[0].suggestionsWeight).toEqual('50')
done()
})
expect(comp.tools[0].suggestionsWeight).toEqual('50');
done();
});
});

it('should delete tool - deleteTool()', () => {
expect(comp.tools.length).toEqual(2)
expect(comp.tools.length).toEqual(2);
comp.deleteTool('5');
expect(comp.tools.length).toEqual(1)
expect(comp.tools.length).toEqual(1);
});

});



describe('createOrUpdate()', () => {
const tool = toolGroupFullDetails.tools[0] as unknown as Tools;
const tool = (toolGroupFullDetails.tools[0] as unknown) as Tools;
beforeEach(() => {
comp.ngOnInit();
})
});

it('should create one tool and update another', (done) => {
comp.tools = [
{
...tool
...tool,
},
{
...tool,
id: '5',
}
]
},
];
comp.createOrUpdate();
setTimeout(() => {
expect(toolGroupServiceStub.addOrUpdateTool).toHaveBeenCalledTimes(2)
expect(toolGroupServiceStub.addOrUpdateTool).toHaveBeenCalledTimes(2);
// Second request
expect(toolGroupServiceStub.addOrUpdateTool).toHaveBeenCalledWith(
comp.toolGroup.id,
comp.tools[1].id,
comp.tools[1].tool.id.toString(),
comp.tools[1].suggestionsWeight,
false,
)
);
expect(activeModalStub.close).toHaveBeenCalled();
done()
})
done();
});
});

it('should just update one tool', (done) => {
comp.initialTools = [tool]
comp.tools = [tool]
comp.initialTools = [tool];
comp.tools = [tool];
comp.createOrUpdate();
setTimeout(() => {
expect(toolGroupServiceStub.addOrUpdateTool).toHaveBeenCalledTimes(1)
expect(toolGroupServiceStub.addOrUpdateTool).toHaveBeenCalledTimes(1);
expect(toolGroupServiceStub.addOrUpdateTool).toHaveBeenCalledWith(
comp.toolGroup.id,
comp.tools[0].id,
comp.tools[0].tool.id.toString(),
comp.tools[0].suggestionsWeight,
true,
)
);
expect(activeModalStub.close).toHaveBeenCalled();
done()
})
done();
});
});
});
});
Loading

0 comments on commit ce06643

Please sign in to comment.