Skip to content

Commit 2811da8

Browse files
committed
fix: orgbook search and tests
Only included BC Hydro and Power Authority if searchTag matches companyName Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
1 parent 0c92c82 commit 2811da8

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

frontend/src/components/electrification/project/ProjectFormNavigator.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,13 @@ async function getOrgBookOptions(companyNameRegistered: string) {
275275
registeredName: obo.value,
276276
registeredId: obo.topic_source_id
277277
}));
278-
orgBookOptions.value.push({
279-
registeredName: BC_HYDRO_POWER_AUTHORITY,
280-
registeredId: ''
281-
});
278+
// If the searched company name includes BC Hydro Power Authority, add it as an option since it is not registered
279+
if (BC_HYDRO_POWER_AUTHORITY.includes(companyNameRegistered.toUpperCase())) {
280+
orgBookOptions.value.push({
281+
registeredName: BC_HYDRO_POWER_AUTHORITY,
282+
registeredId: ''
283+
});
284+
}
282285
// sort options alphabetically
283286
orgBookOptions.value.sort((a, b) => a.registeredName.localeCompare(b.registeredName));
284287
}

frontend/src/components/electrification/project/ProjectIntakeForm.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,13 @@ async function onRegisteredNameInput(e: AutoCompleteCompleteEvent) {
141141
registeredName: obo.value,
142142
registeredId: obo.topic_source_id
143143
}));
144-
orgBookOptions.value.push({
145-
registeredName: BC_HYDRO_POWER_AUTHORITY,
146-
registeredId: ''
147-
});
144+
// If the searched company name includes BC Hydro Power Authority, add it as an option since it is not registered
145+
if (BC_HYDRO_POWER_AUTHORITY.includes(e.query.toUpperCase())) {
146+
orgBookOptions.value.push({
147+
registeredName: BC_HYDRO_POWER_AUTHORITY,
148+
registeredId: ''
149+
});
150+
}
148151
// sort options alphabetically
149152
orgBookOptions.value.sort((a, b) => a.registeredName.localeCompare(b.registeredName));
150153
}

frontend/tests/unit/components/electrification/project/ProjectForm.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('onRegisteredNameInput', () => {
9292
vi.clearAllMocks();
9393
});
9494

95-
it('should not call searchOrgBook when query length is less than 2', async () => {
95+
it('should call searchOrgBook once when query length is less than 2', async () => {
9696
const wrapper = mount(ProjectForm, wrapperSettingsForm());
9797
await nextTick();
9898
await nextTick();
@@ -109,7 +109,7 @@ describe('onRegisteredNameInput', () => {
109109
expect(searchOrgBookSpy).toHaveBeenCalledOnce();
110110
});
111111

112-
it('should call searchOrgBook when query length is 2 or more', async () => {
112+
it('should call searchOrgBook twice when query length is 2 or more', async () => {
113113
const mockResponse = {
114114
data: {
115115
results: [
@@ -166,15 +166,15 @@ describe('onRegisteredNameInput', () => {
166166

167167
// Access internal state through wrapper
168168
const orgBookOptions = (wrapper.vm as any).orgBookOptions; // eslint-disable-line @typescript-eslint/no-explicit-any
169-
expect(orgBookOptions).toHaveLength(3);
169+
expect(orgBookOptions).toHaveLength(2);
170170
expect(orgBookOptions[0]).toEqual({
171-
registeredName: 'BC HYDRO AND POWER AUTHORITY',
172-
registeredId: ''
173-
});
174-
expect(orgBookOptions[1]).toEqual({
175171
registeredName: 'Test Company Ltd',
176172
registeredId: 'FM0001234'
177173
});
174+
expect(orgBookOptions[1]).toEqual({
175+
registeredName: 'Test Corp',
176+
registeredId: 'FM0005678'
177+
});
178178
});
179179

180180
it('should handle empty results from searchOrgBook', async () => {
@@ -200,7 +200,7 @@ describe('onRegisteredNameInput', () => {
200200
await nextTick();
201201

202202
const orgBookOptions = (wrapper.vm as any).orgBookOptions; // eslint-disable-line @typescript-eslint/no-explicit-any
203-
expect(orgBookOptions).toHaveLength(1);
203+
expect(orgBookOptions).toHaveLength(0);
204204
});
205205

206206
it('should handle results with only non-name types', async () => {
@@ -229,7 +229,7 @@ describe('onRegisteredNameInput', () => {
229229
await nextTick();
230230

231231
const orgBookOptions = (wrapper.vm as any).orgBookOptions; // eslint-disable-line @typescript-eslint/no-explicit-any
232-
expect(orgBookOptions).toHaveLength(1);
232+
expect(orgBookOptions).toHaveLength(0);
233233
});
234234

235235
it('should call searchOrgBook with exact query string', async () => {

0 commit comments

Comments
 (0)