Skip to content

Commit 2723b4f

Browse files
authored
Merge pull request #797 from Plant-Tracer/773-ditch-jquery
removed JQuery
2 parents b2d7551 + 92829db commit 2723b4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2458
-2126
lines changed

.eslintrc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ env:
55

66
extends: eslint:recommended
77

8+
ignorePatterns: ["unzipit-worker.module.mjs", "unzipit.module.mjs"]
9+
810
parserOptions:
911
ecmaVersion: latest
1012

13+
overrides:
14+
- files: ["*.js"]
15+
1116
rules:
1217
"no-unused-vars": ["error", { "args": "all", "argsIgnorePattern" : "^_" }]

.github/workflows/continuous-integration-pip.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
# 2025-06-15 - slg - Complete rewrite to avoid MySQL and use DynamoDB and S3 local variants.
33
# These are automatically configured with install-ubuntu or install-macos
44
name: CI (pip)
5-
on: [push, pull_request]
5+
on:
6+
push:
7+
branches:
8+
- main
9+
- dev
10+
pull_request:
11+
12+
# Cancel in-progress runs when a new run is triggered
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
15+
cancel-in-progress: true
616

717
jobs:
818
build:

.github/workflows/documentation.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# https://coderefinery.github.io/documentation/gh_workflow/
22
name: documentation
33

4-
on: [push, pull_request, workflow_dispatch]
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- dev
9+
pull_request:
10+
workflow_dispatch:
11+
12+
# Cancel in-progress runs when a new run is triggered
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
15+
cancel-in-progress: true
516

617
permissions:
718
contents: write

jstests/list_movies.test.js

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ beforeAll(() => {
2222
});
2323

2424
describe('list_movies_data', () => {
25+
let mockElements;
26+
2527
beforeEach(() => {
2628
jest.clearAllMocks();
2729
// Assign global variables from globalData
@@ -36,6 +38,18 @@ describe('list_movies_data', () => {
3638
global.UNDELETE_BUTTON = globalData.UNDELETE_BUTTON;
3739
global.TABLE_HEAD = globalData.TABLE_HEAD;
3840
global.user_primary_course_id = parseInt(globalData.user_primary_course_id, 10);
41+
42+
// Mock document.querySelector to return mock elements with innerHTML setter
43+
mockElements = {};
44+
document.querySelector = jest.fn((selector) => {
45+
if (!mockElements[selector]) {
46+
mockElements[selector] = { innerHTML: '', style: {} };
47+
}
48+
return mockElements[selector];
49+
});
50+
51+
// Mock document.querySelectorAll for hiding movie players
52+
document.querySelectorAll = jest.fn(() => []);
3953
});
4054

4155
test('should create the correct HTML for published movies', () => {
@@ -57,25 +71,25 @@ describe('list_movies_data', () => {
5771
}
5872
];
5973

60-
$.fn.html = jest.fn();
6174
list_movies_data(movies);
62-
expect($.fn.html).toHaveBeenCalledTimes(4);
63-
64-
const expectedPublishedHtml = expect.stringContaining("<table><tbody><tr><td><i>");
65-
expect($.fn.html).toHaveBeenCalledWith(expectedPublishedHtml);
75+
expect(document.querySelector).toHaveBeenCalledTimes(4);
76+
77+
// Check that the published movies div was populated
78+
const publishedHtml = mockElements['#your-published-movies'].innerHTML;
79+
expect(publishedHtml).toContain("<table>");
80+
expect(publishedHtml).toContain("Movie Title");
6681
});
6782

6883
test('should handle an empty list of movies gracefully', () => {
6984
const movies = [];
7085

71-
$.fn.html = jest.fn();
7286
list_movies_data(movies);
73-
expect($.fn.html).toHaveBeenCalledTimes(4);
87+
expect(document.querySelector).toHaveBeenCalledTimes(4);
7488

75-
// Simson broke this with the dynamodb update. It needs to be fixed.
76-
//const expectedEmptyHtml = expect.stringContaining('<table><tbody><tr><td><i>No movies</i></td></tr></tbody></table>');
77-
const expectedEmptyHtml = expect.stringContaining("<table><tbody><tr><td><i>No movies</i></td></tr><tr><td colspan=\"6\"><a href=\"/upload\">Click here to upload a movie</a></td></tr></tbody></table>");
78-
expect($.fn.html).toHaveBeenCalledWith(expectedEmptyHtml);
89+
// Check that empty movies show the right message
90+
const publishedHtml = mockElements['#your-published-movies'].innerHTML;
91+
expect(publishedHtml).toContain("No movies");
92+
expect(publishedHtml).toContain('<a href="/upload">Click here to upload a movie</a>');
7993
});
8094

8195
test('should correctly classify and display course movies', () => {
@@ -98,36 +112,35 @@ describe('list_movies_data', () => {
98112
}
99113
];
100114

101-
$.fn.html = jest.fn();
102115
list_movies_data(movies);
103-
expect($.fn.html).toHaveBeenCalledTimes(4);
116+
expect(document.querySelector).toHaveBeenCalledTimes(4);
104117

105-
const expectedCourseHtml = expect.stringContaining('<table>');
106-
expect($.fn.html).toHaveBeenCalledWith(expectedCourseHtml);
118+
// Check that course movies are shown in the right section
119+
const courseHtml = mockElements['#course-movies'].innerHTML;
120+
expect(courseHtml).toContain('<table>');
107121
});
108122

109123
test('should display a link to upload movies for non-demo users', () => {
110124
const movies = [];
111125
global.demo_mode = false;
112-
$.fn.html = jest.fn();
113126
list_movies_data(movies);
114-
expect($.fn.html).toHaveBeenCalledTimes(4);
127+
expect(document.querySelector).toHaveBeenCalledTimes(4);
115128

116-
const expectedUploadLinkHtml = expect.stringContaining('<table><tbody><tr><td><i>No movies</i></td></tr><tr><td colspan="6"><a href="/upload">Click here to upload a movie</a></td></tr></tbody></table>');
117-
expect($.fn.html).toHaveBeenCalledWith(expectedUploadLinkHtml);
129+
const publishedHtml = mockElements['#your-published-movies'].innerHTML;
130+
expect(publishedHtml).toContain('No movies');
131+
expect(publishedHtml).toContain('<a href="/upload">Click here to upload a movie</a>');
118132
});
119133

120134
test('should not display upload link for demo users', () => {
121135
const movies = [];
122136

123137
global.demo_mode = true;
124138

125-
$.fn.html = jest.fn();
126139
list_movies_data(movies);
127-
expect($.fn.html).toHaveBeenCalledTimes(4);
140+
expect(document.querySelector).toHaveBeenCalledTimes(4);
128141

129-
const notExpectedUploadLinkHtml = expect.not.stringContaining('Click here to upload a movie');
130-
expect($.fn.html).toHaveBeenCalledWith(notExpectedUploadLinkHtml);
142+
const publishedHtml = mockElements['#your-published-movies'].innerHTML;
143+
expect(publishedHtml).not.toContain('Click here to upload a movie');
131144
});
132145

133146
// Action Button Tests
@@ -142,14 +155,20 @@ describe('list_movies_data', () => {
142155
published: 0,
143156
deleted: 0,
144157
title: 'Unpublished Movie',
158+
date_uploaded: 1627689600,
159+
width: 1280,
160+
height: 720,
161+
total_bytes: 2000000,
162+
fps: '30',
163+
total_frames: 3600,
164+
orig_movie: false,
145165
}
146166
];
147167

148-
$.fn.html = jest.fn();
149168
list_movies_data(movies);
150169

151-
const expectedButtonHtml = expect.stringContaining(`<td> Status: Not published<br/>`);
152-
expect($.fn.html).toHaveBeenCalledWith(expectedButtonHtml);
170+
const unpublishedHtml = mockElements['#your-unpublished-movies'].innerHTML;
171+
expect(unpublishedHtml).toContain('Status: Not published');
153172
});
154173

155174
test('should display an unpublish button for published movies', () => {
@@ -160,13 +179,19 @@ describe('list_movies_data', () => {
160179
published: 1,
161180
deleted: 0,
162181
title: 'Published Movie',
182+
date_uploaded: 1627689600,
183+
width: 1280,
184+
height: 720,
185+
total_bytes: 2000000,
186+
fps: '30',
187+
total_frames: 3600,
188+
orig_movie: false,
163189
}
164190
];
165191

166-
$.fn.html = jest.fn();
167192
list_movies_data(movies);
168193

169-
const expectedButtonHtml = expect.stringContaining(`<td> Status: <b>Published</b>`);
170-
expect($.fn.html).toHaveBeenCalledWith(expectedButtonHtml);
194+
const publishedHtml = mockElements['#your-published-movies'].innerHTML;
195+
expect(publishedHtml).toContain('Status: <b>Published</b>');
171196
});
172197
});

0 commit comments

Comments
 (0)