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

Remove unused subjects.js #8783

Merged
merged 1 commit into from
Feb 22, 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
4 changes: 1 addition & 3 deletions openlibrary/plugins/openlibrary/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { enumerate, htmlquote, websafe, foreach, join, len, range } from './jsde
import initAnalytics from './ol.analytics';
import init from './ol.js';
import * as Browser from './Browser';
import { commify } from './python';
import { Subject, urlencode, slice } from './subjects';
import { commify, urlencode, slice } from './python';
import Template from './template.js';
// Add $.fn.focusNextInputField
import { truncate, cond } from './utils';
Expand Down Expand Up @@ -45,7 +44,6 @@ window.ungettext = ungettext;
window.uggettext = ugettext;

window.Browser = Browser;
window.Subject = Subject;
window.Template = Template;

// Extend existing prototypes
Expand Down
19 changes: 19 additions & 0 deletions openlibrary/plugins/openlibrary/js/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,22 @@ export function commify(n) {

return text;
}

// Implementation of Python urllib.urlencode in Javascript.
export function urlencode(query) {
var parts = [];
var k;
for (k in query) {
parts.push(`${k}=${query[k]}`);
}
return parts.join('&');
}

export function slice(array, begin, end) {
var a = [];
var i;
for (i=begin; i < Math.min(array.length, end); i++) {
a.push(array[i]);
}
return a;
}
218 changes: 0 additions & 218 deletions openlibrary/plugins/openlibrary/js/subjects.js

This file was deleted.

32 changes: 31 additions & 1 deletion tests/unit/js/python.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commify } from '../../../openlibrary/plugins/openlibrary/js/python';
import { commify, urlencode, slice } from '../../../openlibrary/plugins/openlibrary/js/python';

test('commify', () => {
expect(commify('5443232')).toBe('5,443,232');
Expand All @@ -7,3 +7,33 @@ test('commify', () => {
expect(commify(['1','2','3','45'])).toBe('1,2,3,45');
expect(commify([1, 20, 3])).toBe('1,20,3');
});

describe('urlencode', () => {
test('empty array', () => {
expect(urlencode([])).toEqual('');
});
test('array of 1', () => {
expect(urlencode(['apple'])).toEqual('0=apple');
});
test('array of 3', () => {
expect(urlencode(['apple', 'grapes', 'orange'])).toEqual('0=apple&1=grapes&2=orange');
});
});

describe('slice', () => {
test('empty array', () => {
expect(slice([], 0, 0)).toEqual([]);
});
test('array of 2', () => {
expect(slice([1, 2], 0, 1)).toEqual([1]);
});
test('arr length less than end', () => {
expect(slice([1, 2, 3], 0, 5)).toEqual([1, 2, 3]);
});
test('beginning greater than end', () => {
expect(slice([1, 2, 3, 4, 5], 4, 3)).toEqual([]);
});
test('array of 5', () => {
expect(slice([1, 2, 3, 4, 5], 0, 3)).toEqual([1, 2, 3]);
});
});
68 changes: 0 additions & 68 deletions tests/unit/js/subjects.test.js

This file was deleted.

Loading