Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiya1155 committed Feb 27, 2024
1 parent 8085a4e commit 7c920d3
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 21 deletions.
6 changes: 3 additions & 3 deletions client/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module.exports = {
],
coverageThreshold: {
global: {
branches: 6,
functions: 16,
lines: 13,
branches: 10,
functions: 21,
lines: 18,
},
},
};
132 changes: 132 additions & 0 deletions client/src/utils/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ParsedQueryTypeEnum } from '../types/general';
import {
concatenateParsedQuery,
getCommonFolder,
getFileExtensionForLang,
humanNumber,
mergeRanges,
splitUserInputAfterAutocomplete,
} from './index';

Expand Down Expand Up @@ -102,6 +105,23 @@ describe('Utils', () => {
]),
);
});
test('repo filter after lang filter in the middle', () => {
expect(
JSON.stringify(
splitUserInputAfterAutocomplete(
'my |lang:TypeScript| simple |repo:BloopAI/bloop| string',
),
),
).toEqual(
JSON.stringify([
{ type: ParsedQueryTypeEnum.TEXT, text: 'my ' },
{ type: ParsedQueryTypeEnum.LANG, text: 'TypeScript' },
{ type: ParsedQueryTypeEnum.TEXT, text: ' simple ' },
{ type: ParsedQueryTypeEnum.REPO, text: 'BloopAI/bloop' },
{ type: ParsedQueryTypeEnum.TEXT, text: ' string' },
]),
);
});
});
describe('getFileExtensionForLang', () => {
test('main languages', () => {
Expand Down Expand Up @@ -166,4 +186,116 @@ describe('Utils', () => {
expect(getCommonFolder([])).toEqual('/');
});
});
describe('concatenateParsedQuery', () => {
test('no filters used', () => {
expect(
concatenateParsedQuery([
{ type: ParsedQueryTypeEnum.TEXT, text: 'Hello world!' },
]),
).toEqual('Hello world!');
expect(
concatenateParsedQuery([
{ type: ParsedQueryTypeEnum.TEXT, text: 'Hello' },
{ type: ParsedQueryTypeEnum.TEXT, text: ' world!' },
]),
).toEqual('Hello world!');
});
test('filters used', () => {
expect(
concatenateParsedQuery([
{ type: ParsedQueryTypeEnum.TEXT, text: 'Hello ' },
{ type: ParsedQueryTypeEnum.LANG, text: 'js' },
{ type: ParsedQueryTypeEnum.TEXT, text: ' world ' },
{ type: ParsedQueryTypeEnum.REPO, text: 'BloopAI/bloop' },
{ type: ParsedQueryTypeEnum.TEXT, text: ' ' },
{ type: ParsedQueryTypeEnum.PATH, text: 'src/index.js' },
{ type: ParsedQueryTypeEnum.TEXT, text: ' ? ' },
{ type: ParsedQueryTypeEnum.BRANCH, text: 'origin/main' },
{ type: ParsedQueryTypeEnum.PATH, text: 'src/components/index.js' },
]),
).toEqual(
'Hello |lang:js| world |repo:BloopAI/bloop| |path:src/index.js| ? |path:src/components/index.js|',
);
});
});
describe('mergeRanges', () => {
test('empty ranges', () => {
expect(mergeRanges([])).toEqual([]);
});
test('no overlap ranges', () => {
expect(
mergeRanges([
[1, 5],
[7, 10],
]),
).toEqual([
[1, 5],
[7, 10],
]);
expect(
mergeRanges([
[7, 10],
[1, 5],
]),
).toEqual([
[1, 5],
[7, 10],
]);
});
test('no overlap ranges next to each other', () => {
expect(
mergeRanges([
[1, 5],
[6, 10],
]),
).toEqual([[1, 10]]);
expect(
mergeRanges([
[7, 10],
[1, 5],
[11, 15],
]),
).toEqual([
[1, 5],
[7, 15],
]);
});
test('overlap ranges', () => {
expect(
mergeRanges([
[1, 5],
[3, 10],
]),
).toEqual([[1, 10]]);
expect(
mergeRanges([
[7, 10],
[1, 5],
[9, 15],
]),
).toEqual([
[1, 5],
[7, 15],
]);
});
});
describe('humanNumber', () => {
test('< 1000', () => {
expect(humanNumber(123)).toEqual('123');
expect(humanNumber(999)).toEqual('999');
expect(humanNumber(5)).toEqual('5');
});
test('> 1000', () => {
expect(humanNumber(1000)).toEqual('1k');
expect(humanNumber(1001)).toEqual('1k');
expect(humanNumber(5432)).toEqual('5.4k');
expect(humanNumber(5999)).toEqual('6k');
expect(humanNumber(10009)).toEqual('10k');
expect(humanNumber(100009)).toEqual('100k');
expect(humanNumber(1000009)).toEqual('1000k');
});
test('none', () => {
expect(humanNumber(0)).toEqual(0);
});
});
});
18 changes: 0 additions & 18 deletions client/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,22 +470,4 @@ export function concatenateParsedQuery(query: ParsedQueryType[]) {
return result;
}

type InputEditorTextContent = {
type: 'text';
text: string;
};

type InputEditorMentionContent = {
type: 'mention';
attrs: {
type: 'lang' | 'path' | 'repo';
id: string;
display: string;
};
};

export type InputEditorContent =
| InputEditorTextContent
| InputEditorMentionContent;

export const noOp = () => {};

0 comments on commit 7c920d3

Please sign in to comment.