Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Apps Sort as expected when Sorting on Display Name #230

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jhub_apps/static/js/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const serverApps = {
user_options: {
name: 'test-app-3',
jhub_app: true,
display_name: 'Test App 3',
display_name: 'TEST App 3',
description:
'Lorem ipsum dolor sit amet consectetur. Sit vestibulum facilisis auctor pulvinar ac. Dras.',
thumbnail: DEFAULT_APP_LOGO,
Expand Down
68 changes: 65 additions & 3 deletions ui/src/utils/jupyterhub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
filterAndSortApps,
getAppLogoUrl,
getApps,
getFriendlyDateStr,
getFriendlyDisplayName,
getFriendlyFrameworkName,
getJhData,
Expand Down Expand Up @@ -94,6 +95,43 @@ describe('JupyterHub utils', () => {
expect(result).toBe('Python');
});

test('returns a friendly date string for recent change', () => {
const result = getFriendlyDateStr(new Date());
expect(result).toBe('Just now');
});

test('returns a friendly date string for change within 1 minute', () => {
const currentDate = new Date();
const result = getFriendlyDateStr(
new Date(currentDate.setMinutes(currentDate.getMinutes() - 1)),
);
expect(result).toBe('1 minute ago');
});

test('returns a friendly date string for change within minutes', () => {
const currentDate = new Date();
const result = getFriendlyDateStr(
new Date(currentDate.setMinutes(currentDate.getMinutes() - 5)),
);
expect(result).toBe('5 minutes ago');
});

test('returns a friendly date string for change within hours', () => {
const currentDate = new Date();
const result = getFriendlyDateStr(
new Date(currentDate.setHours(currentDate.getHours() - 5)),
);
expect(result).toBe('5 hours ago');
});

test('returns a friendly date string for change within days', () => {
const currentDate = new Date();
const result = getFriendlyDateStr(
new Date(currentDate.setHours(currentDate.getHours() - 120)),
);
expect(result).toBe('5 days ago');
});

aktech marked this conversation as resolved.
Show resolved Hide resolved
test('gets app theme url window object', () => {
const result = getAppLogoUrl();
expect(result).toBe('/img/logo.png');
Expand All @@ -105,15 +143,39 @@ describe('JupyterHub utils', () => {
expect(document.location.href).toBe(mockUrl);
});

test('filters and sorts apps', () => {
test('filters and sorts apps by recently modified', () => {
const apps = filterAndSortApps(
serverApps,
currentUser,
'',
'all',
[],
'Recently modified',
);
expect(apps[0].name).toBe('Test App');
});

test('filters and sorts apps by name asc', () => {
const apps = filterAndSortApps(
serverApps,
currentUser,
'',
'all',
[],
'Name: A-Z',
);
expect(apps[0].name).toBe('App with a long name that should be truncated');
});

test('filters and sorts apps by name desc', () => {
const apps = filterAndSortApps(
serverApps,
currentUser,
'',
'all',
[],
'name',
'Name: Z-A',
);
expect(apps.length).toBe(5);
expect(apps[0].name).toBe('TEST App 3');
});
});
6 changes: 3 additions & 3 deletions ui/src/utils/jupyterhub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const filterAndSortApps = (
: 'all';

// Get Apps based on ownership type and search value
const apps = getApps(data, ownershipType, currentUser?.name ?? '')
const apps = getApps(data, ownershipType, currentUser.name)
.filter(
(app) =>
app.name.toLowerCase().includes(searchToLower) ||
Expand All @@ -226,9 +226,9 @@ export const filterAndSortApps = (
if (sortByValue === 'Recently modified') {
return a.last_activity > b.last_activity ? -1 : 1;
} else if (sortByValue === 'Name: A-Z') {
return a.name > b.name ? 1 : -1;
return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1;
}
return a.name > b.name ? -1 : 1;
return a.name.toLowerCase() > b.name.toLowerCase() ? -1 : 1;
});
return apps;
};
Loading