Skip to content

Commit

Permalink
IEN-949 | Search ATS1_ID (#696)
Browse files Browse the repository at this point in the history
* add search ats1_id

* fix unit test

* fix unit test

* fix unit test

---------

Co-authored-by: Jerry Wang <jerryappleid761208@gmail.com>
  • Loading branch information
jerry-ey and c1495616js authored Jan 7, 2025
1 parent 4706e25 commit ea7823c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
4 changes: 2 additions & 2 deletions apps/api/src/applicant/ienapplicant.util.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IENJobTitle } from './entity/ienjobtitles.entity';
import { IENJobLocation } from './entity/ienjoblocation.entity';
import { IENStatusReason } from './entity/ienstatus-reason.entity';
import { IENMasterService } from './ien-master.service';
import { searchNames } from '../common/search-names';
import { searchNamesAndAts1Id } from 'src/common/search-names';

@Injectable()
export class IENApplicantUtilService {
Expand Down Expand Up @@ -93,7 +93,7 @@ export class IENApplicantUtilService {
}
}
if (name) {
searchNames(builder, 'applicant.name', name);
searchNamesAndAts1Id(builder, ['applicant.name', 'applicant.ats1_id'], name);
}

if (sortKey === 'recruiter') {
Expand Down
38 changes: 38 additions & 0 deletions apps/api/src/common/search-names.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
import { Brackets, WhereExpressionBuilder } from 'typeorm';

const ATS1_ID_LENGTH = 6;
export const searchNamesAndAts1Id = (
builder: WhereExpressionBuilder,
fields: [nameField: string, ats1IdField: string],
keyword: string,
) => {
const keywords = keyword
.trim()
.split(' ')
.filter(item => item.length);

// Check if the keyword is a potential ATS1 ID
if (
keywords.length === 1 &&
keywords[0].length === ATS1_ID_LENGTH &&
!isNaN(Number(keywords[0]))
) {
searchAts1Id(builder, fields[1], keyword);
} else {
searchNames(builder, fields[0], keyword);
}
};

export const searchNames = (builder: WhereExpressionBuilder, field: string, keyword: string) => {
const keywords = keyword
.trim()
Expand Down Expand Up @@ -30,3 +53,18 @@ export const searchNames = (builder: WhereExpressionBuilder, field: string, keyw
builder.andWhere(`${field} ilike :name`, { name: `%${keyword.trim()}%` });
}
};

export const searchAts1Id = (builder: WhereExpressionBuilder, field: string, keyword: string) => {
const keywords = keyword
.trim()
.split(' ')
.filter(item => item.length);

if (
keywords.length === 1 &&
keywords[0].length === ATS1_ID_LENGTH &&
!isNaN(Number(keywords[0]))
) {
builder.andWhere(`${field} = :ats1_id`, { ats1_id: `${keyword.trim()}` });
}
};
13 changes: 10 additions & 3 deletions apps/web/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ export const Search = (props: SearchProps) => {

const getResultText = (applicant: ApplicantRO) => {
if (!isHmbc(authUser) || !applicant.status) {
return <b>{applicant.name}</b>;
return (
<b>
{applicant.ats1_id} - {applicant.name}
</b>
);
}
return (
<>
<b>{applicant.name}</b> found in <b>{applicant.status.status}</b>
<b>
{applicant.ats1_id} - {applicant.name}
</b>{' '}
found in <b>{applicant.status.status}</b>
</>
);
};
Expand All @@ -74,7 +81,7 @@ export const Search = (props: SearchProps) => {
onChange={handleChange}
onFocus={() => handleFocus(true)}
onKeyDown={handleEnter}
placeholder='Search by first name or last name'
placeholder='Search by first name, last name or ATS1 ID'
className='flex-grow focus:outline-none placeholder-bcGray'
data-cy='search-input'
/>
Expand Down
15 changes: 10 additions & 5 deletions apps/web/tests/components/form/Search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ describe('Search', () => {
it('renders a search box', async () => {
const mock = jest.fn();
const searchData = [
{ id: '1', name: 'Jane Doe', status: { id: 1, status: 'Recruitment' } },
{ id: '2', name: 'Mark Twain', status: { id: 5, status: 'Final Milestone' } },
{ ats1_id: '111111', id: '1', name: 'Jane Doe', status: { id: 1, status: 'Recruitment' } },
{
ats1_id: '222222',
id: '2',
name: 'Mark Twain',
status: { id: 5, status: 'Final Milestone' },
},
];
const search = async (): Promise<any[]> => searchData;

render(<Search onChange={mock} onSelect={mock} keyword='' search={search} />);

const input = screen.getByPlaceholderText('Search by first name or last name');
const input = screen.getByPlaceholderText('Search by first name, last name or ATS1 ID');
expect(input).toBeInTheDocument();

input.focus();
fireEvent.change(input, { target: { value: 'Mark' } });
for (const { name } of searchData) {
for (const { name, ats1_id } of searchData) {
await waitFor(() => {
expect(screen.getByText(name)).toBeInTheDocument();
expect(screen.getByText(`${ats1_id} - ${name}`)).toBeInTheDocument();
});
}

Expand Down

0 comments on commit ea7823c

Please sign in to comment.