Skip to content

Commit

Permalink
removed unused utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMrSheldon committed Aug 1, 2024
1 parent fa14f59 commit 707a12e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 88 deletions.
76 changes: 19 additions & 57 deletions frontend/src/__tests__/url-extraction-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
extractTaskFromCurrentUrl,
extractDatasetFromCurrentUrl,
extractSubView,
extractSubSubView,
extractCurrentStepFromCurrentUrl,
extractSubmissionTypeFromCurrentUrl,
extractUserFromCurrentUrl,
Expand All @@ -12,20 +10,20 @@ import {
} from '../utils'

Object.defineProperty((window as Window), 'location', {
value: {
href: ''
},
writable: true // possibility to override
});
value: {
href: ''
},
writable: true // possibility to override
});

test('Task from current Url should be Null.', () => {
(window as Window).location.href = "http://dummy.com";
expect(extractTaskFromCurrentUrl()).toBeNull();
(window as Window).location.href = "http://dummy.com";
expect(extractTaskFromCurrentUrl()).toBeNull();
});

test('Task from Url without Subpath Should be correct.', () => {
(window as Window).location.href = 'task-overview/abc'
expect(extractTaskFromCurrentUrl()).toStrictEqual('abc');
(window as Window).location.href = 'task-overview/abc'
expect(extractTaskFromCurrentUrl()).toStrictEqual('abc');
});

test('Task from Url without Subpath Should be correct with question mark.', () => {
Expand All @@ -39,8 +37,8 @@ test('Task from Url without Subpath Should be correct with # symbol.', () => {
});

test('Task from Url with Subpath Should be correct.', () => {
(window as Window).location.href = 'task-overview/1234/'
expect(extractTaskFromCurrentUrl()).toStrictEqual('1234');
(window as Window).location.href = 'task-overview/1234/'
expect(extractTaskFromCurrentUrl()).toStrictEqual('1234');
});

test('Dataset from Url without dataset should be the empty string.', () => {
Expand Down Expand Up @@ -81,7 +79,7 @@ test('Dataset from Url with Subpath Should be correct.', () => {
test('Dataset is extracted with precedence from the default_choice if available.', () => {
(window as Window).location.href = 'task-overview/abc/ds'

let options = [{'dataset_id': 'ds'}, {'dataset_id': 'something-is-selected'}, {'dataset_id': 'ds2'}]
let options = [{ 'dataset_id': 'ds' }, { 'dataset_id': 'something-is-selected' }, { 'dataset_id': 'ds2' }]
let selectedDataset = 'something-is-selected'

expect(extractDatasetFromCurrentUrl(options, selectedDataset)).toStrictEqual('something-is-selected');
Expand All @@ -90,7 +88,7 @@ test('Dataset is extracted with precedence from the default_choice if available.
test('First Dataset is extracted if the default_choice is not available.', () => {
(window as Window).location.href = 'task-overview/abc'

let options = [{'dataset_id': 'ds'}, {'dataset_id': 'something-is-selected'}, {'dataset_id': 'ds2'}]
let options = [{ 'dataset_id': 'ds' }, { 'dataset_id': 'something-is-selected' }, { 'dataset_id': 'ds2' }]
let selectedDataset = 'does-not-exist'

expect(extractDatasetFromCurrentUrl(options, selectedDataset)).toStrictEqual('ds');
Expand All @@ -100,7 +98,7 @@ test('First Dataset is extracted if the default_choice is not available.', () =>
test('Dataset from URL is extracted if default_choice is wrong.', () => {
(window as Window).location.href = 'task-overview/abc/ds2'

let options = [{'dataset_id': 'ds'}, {'dataset_id': 'something-is-selected'}, {'dataset_id': 'ds2'}]
let options = [{ 'dataset_id': 'ds' }, { 'dataset_id': 'something-is-selected' }, { 'dataset_id': 'ds2' }]
let selectedDataset = 'does-not-exist'

expect(extractDatasetFromCurrentUrl(options, selectedDataset)).toStrictEqual('ds2');
Expand All @@ -109,7 +107,7 @@ test('Dataset from URL is extracted if default_choice is wrong.', () => {
test('Dataset from URL is extracted if no default_choice is available.', () => {
(window as Window).location.href = 'task-overview/abc/ds2'

let options = [{'dataset_id': 'ds'}, {'dataset_id': 'something-is-selected'}, {'dataset_id': 'ds2'}]
let options = [{ 'dataset_id': 'ds' }, { 'dataset_id': 'something-is-selected' }, { 'dataset_id': 'ds2' }]
let selectedDataset = ''

expect(extractDatasetFromCurrentUrl(options, selectedDataset)).toStrictEqual('ds2');
Expand All @@ -119,7 +117,7 @@ test('Dataset from URL is extracted if no default_choice is available.', () => {
test('First dataset is used if dataset from URL does not exist.', () => {
(window as Window).location.href = 'task-overview/abc/ds2'

let options = [{'dataset_id': 'ds'}, {'dataset_id': 'something-is-selected'}, {'dataset_id': 'ds22'}]
let options = [{ 'dataset_id': 'ds' }, { 'dataset_id': 'something-is-selected' }, { 'dataset_id': 'ds22' }]
let selectedDataset = ''

expect(extractDatasetFromCurrentUrl(options, selectedDataset)).toStrictEqual('ds');
Expand Down Expand Up @@ -195,48 +193,12 @@ test('Expect current step from subpath to be null if not exists', () => {
test('First dataset is used if dataset from URL does not exist and default_choise is wrong.', () => {
(window as Window).location.href = 'task-overview/abc/ds2'

let options = [{'dataset_id': 'ds'}, {'dataset_id': 'something-is-selected'}, {'dataset_id': 'ds3'}]
let options = [{ 'dataset_id': 'ds' }, { 'dataset_id': 'something-is-selected' }, { 'dataset_id': 'ds3' }]
let selectedDataset = 'does-not-exist'

expect(extractDatasetFromCurrentUrl(options, selectedDataset)).toStrictEqual('ds');
});

test('No sub-view and sub-sub-view exist 1.', () => {
(window as Window).location.href = 'task-overview/1234/'
expect(extractSubView()).toBeNull;
expect(extractSubSubView()).toBeNull;
});

test('No sub-view and sub-sub-view exist 2.', () => {
(window as Window).location.href = 'task-overview/1234/23'
expect(extractSubView()).toBeNull;
expect(extractSubSubView()).toBeNull;
});

test('No sub-view and sub-sub-view exist 2.', () => {
(window as Window).location.href = 'dummy/1234/23/hello/world/how'
expect(extractSubView()).toBeNull;
expect(extractSubSubView()).toBeNull;
});

test('Sub-view exists but no sub-sub-view 1.', () => {
(window as Window).location.href = 'task-overview/1234/23/sub-view-1'
expect(extractSubView()).toStrictEqual('sub-view-1');
expect(extractSubSubView()).toBeNull;
});

test('Sub-view exists but no sub-sub-view 2.', () => {
(window as Window).location.href = 'task-overview/1234/23/1234'
expect(extractSubView()).toStrictEqual('1234');
expect(extractSubSubView()).toBeNull;
});

test('Sub-view exists and sub-sub-view 1.', () => {
(window as Window).location.href = 'task-overview/1234/23/1234/sub-sub-view'
expect(extractSubView()).toStrictEqual('1234');
expect(extractSubSubView()).toStrictEqual('sub-sub-view');
});

test('No component_type, no focus_type and no search_query exists', () => {
(window as Window).location.href = 'dummy/1234/23/hello/world/how'
expect(extractFocusTypesFromCurrentUrl()).toStrictEqual([]);
Expand Down Expand Up @@ -321,7 +283,7 @@ test('Component_type and focus and search query exist 2', () => {

test('Multiple component_type and focus and search query exist ', () => {
(window as Window).location.href = 'components/TIREx,Code,Tutorial/Precision,Recall/Dense%20Retrieval/'
expect(extractComponentTypesFromCurrentUrl()).toStrictEqual(['TIREx','Code','Tutorial']);
expect(extractFocusTypesFromCurrentUrl()).toStrictEqual(['Precision','Recall']);
expect(extractComponentTypesFromCurrentUrl()).toStrictEqual(['TIREx', 'Code', 'Tutorial']);
expect(extractFocusTypesFromCurrentUrl()).toStrictEqual(['Precision', 'Recall']);
expect(extractSearchQueryFromCurrentUrl()).toStrictEqual('dense retrieval');
});
31 changes: 0 additions & 31 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,37 +84,6 @@ export function extractDatasetFromCurrentUrl(options: Array<any> = [], default_c
return ret
}

export function extractSubView() {
return extracSubViewForLevel(1)
}

export function extractSubSubView() {
return extracSubViewForLevel(2)
}

export function extracSubViewForLevel(level: number) {
let loc = ref(window.location).value.href.split('#')[0].split('?')[0]
let to_split = 'task-overview/' + extractTaskFromCurrentUrl() + '/'

if (loc.includes(to_split)) {
let ret = loc.split(to_split)[1].split('/')
if (ret.length >= level) {
return ret[level]
}
}

return null
}

export function chanceCurrentUrlToDataset(dataset: string) {
var loc = ref(window.location).value.href

if (loc.includes('task-overview/')) {
loc = loc.split('task-overview/')[0] + 'task-overview/' + loc.split('task-overview/')[1].split('/')[0] + '/' + dataset
history.replaceState({ 'url': loc }, 'TIRA', loc)
}
}

export async function fetchUserInfo(): Promise<UserInfo> {
const response = await fetch(inject("REST base URL") + '/api/role', { credentials: 'include' })
// TODO: better error handling (to be implemented with the new REST API with problem+json; and the overhauled UI)
Expand Down

0 comments on commit 707a12e

Please sign in to comment.