Skip to content

Commit 90a214e

Browse files
committed
feat: refactor ZIM file creation handling and validation
- Add split-by-grapheme npm package to handle grapheme counting accurately. - Modify ZimFile.vue to implement grapheme counting for title, description, and long description fields - Introduce new exceptions for invalid ZIM metadata: InvalidZimTitleError, InvalidZimDescriptionError, and InvalidZimLongDescriptionError. - Add regex python module to Pipfile and rebuilt Pipfile.lock - Enhance backend logic in builder.py and zimfarm.py to validate ZIM metadata against grapheme limits using regex module - Update unit tests to cover new validation rules and exceptions for ZIM metadata. - Update ZIM file creation tests to check for disabled state of the request button - Add frontend and backend validation of long description (max length, min lenght and difference to description)
1 parent fbe059a commit 90a214e

File tree

11 files changed

+317
-78
lines changed

11 files changed

+317
-78
lines changed

Pipfile

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pytest-cov = "*"
3131
supervisor = "~=4.2"
3232
yoyo-migrations = "==7.3.2"
3333
pysocks = "*"
34+
regex = "==2024.11.6"
3435

3536
# Versions required for dependabot
3637
sqlparse = "~=0.5.0"

Pipfile.lock

+116-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp1-frontend/cypress/e2e/zimFile.cy.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ describe('the zim file creation page', () => {
5454

5555
it('displays the Request ZIM file button', () => {
5656
cy.get('#request').should('be.visible');
57-
cy.get('#request').should('not.have.attr', 'disabled');
57+
cy.get('#request').should('have.attr', 'disabled');
5858
});
5959

60-
describe('when the description is missing and the submit button is clicked', () => {
60+
describe('when the description is missing', () => {
6161
beforeEach(() => {
6262
cy.intercept('POST', 'v1/builders/1/zim', () => {
6363
throw new Error(
@@ -66,14 +66,14 @@ describe('the zim file creation page', () => {
6666
}).as('request');
6767
});
6868

69-
it('does not submit the form', () => {
70-
cy.get('#request').click();
71-
});
69+
it('disables the submit button', () => {
70+
cy.get('#request').should('have.attr', 'disabled');
71+
});
7272

73-
it('shows the error message', () => {
74-
cy.get('#request').click();
73+
it('shows the error message', () => {
74+
cy.get('#request').click({ force: true });
7575
cy.get('#desc-group > .invalid-feedback').should('be.visible');
76-
});
76+
});
7777
});
7878

7979
describe('when the Request ZIM file button is clicked', () => {
@@ -167,7 +167,7 @@ describe('the zim file creation page', () => {
167167

168168
it('displays the Request ZIM file button', () => {
169169
cy.get('#request').should('be.visible');
170-
cy.get('#request').should('not.have.attr', 'disabled');
170+
cy.get('#request').should('have.attr', 'disabled');
171171
});
172172

173173
describe('when the Request ZIM file button is clicked', () => {
@@ -209,7 +209,7 @@ describe('the zim file creation page', () => {
209209

210210
it('displays the Request ZIM file button', () => {
211211
cy.get('#request').should('be.visible');
212-
cy.get('#request').should('not.have.attr', 'disabled');
212+
cy.get('#request').should('have.attr', 'disabled');
213213
});
214214
});
215215
});

wp1-frontend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"popper.js": "^1.16.0",
5454
"postcss": "^8.4.31",
5555
"serialize-javascript": "^3.1.0",
56+
"split-by-grapheme": "^1.0.1",
5657
"vite": "^3.2.11",
5758
"vue": "^2.7.14",
5859
"vue-router": "^3.1.6",

0 commit comments

Comments
 (0)