mirror of
https://github.com/haiwen/seahub.git
synced 2025-04-27 02:51:00 +00:00
Fix get wiki page id (#7322)
* fix get wiki page link * add test workflow * add unit for wiki utils function
This commit is contained in:
parent
4b33271e5b
commit
206ecec2aa
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -49,7 +49,7 @@ jobs:
|
||||
with:
|
||||
node-version: "20.x"
|
||||
|
||||
- name: run npm lint
|
||||
- name: run npm lint and npm test
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE/tests/
|
||||
if chmod +x test_frontend_changes.sh && ./test_frontend_changes.sh; then chmod +x github_actions_npm_lint.sh && ./github_actions_npm_lint.sh; else true; fi
|
||||
|
@ -48,7 +48,12 @@ const getCurrentPageConfig = (pages, pageId) => {
|
||||
};
|
||||
|
||||
const getWikPageLink = (pageId) => {
|
||||
return window.location.url.replace(/\/[^\/]+$/, `/${pageId}`);
|
||||
let { origin, pathname } = window.location;
|
||||
let pathArr = pathname.split('/');
|
||||
// pathname is like `/wikis/${wikiId}/{pageId}/`
|
||||
pathArr[3] = pageId;
|
||||
pathname = pathArr.join('/');
|
||||
return `${origin}${pathname}`;
|
||||
};
|
||||
|
||||
const throttle = (fn, delay) => {
|
||||
|
51
frontend/src/tests/pages/wiki2/utils/index.test.js
Normal file
51
frontend/src/tests/pages/wiki2/utils/index.test.js
Normal file
@ -0,0 +1,51 @@
|
||||
import { generatorBase64Code, generateUniqueId, getWikPageLink } from '../../../../pages/wiki2/utils/index.js';
|
||||
|
||||
describe('generatorBase64Code', () => {
|
||||
it('should generate a base64 code of length 4 by default', () => {
|
||||
const code = generatorBase64Code();
|
||||
expect(code.length).toBe(4);
|
||||
});
|
||||
it('should generate a base64 code of length 6 when given 6', () => {
|
||||
const code = generatorBase64Code(6);
|
||||
expect(code.length).toBe(6);
|
||||
});
|
||||
it('should generate a base64 code which is a string', () => {
|
||||
const code = generatorBase64Code();
|
||||
expect(typeof code).toBe('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateUniqueId', () => {
|
||||
it('should generate a unique id', () => {
|
||||
const navigation = [
|
||||
{ id: 'page1', children: [] },
|
||||
{ id: 'page2', children: [{ id: 'page21', children: [] }] },
|
||||
];
|
||||
expect(generateUniqueId(navigation)).not.toMatch(/page1|page2|page21/);
|
||||
});
|
||||
it('should generate a unique id with custom length', () => {
|
||||
const navigation = [
|
||||
{ id: 'page1', children: [] },
|
||||
{ id: 'page2', children: [{ id: 'page21', children: [] }] },
|
||||
];
|
||||
expect(generateUniqueId(navigation, 6)).not.toMatch(/page1|page2|page21/);
|
||||
expect(generateUniqueId(navigation, 6).length).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getWikPageLink', () => {
|
||||
it('returns the correct URL', () => {
|
||||
const originalLocation = window.location;
|
||||
// Mock window.location
|
||||
delete window.location;
|
||||
window.location = {
|
||||
origin: 'https://cloud.seafile.com',
|
||||
pathname: '/wikis/6cbbded99bd272796a2/7Lj3/'
|
||||
};
|
||||
const pageId = 'y4Jw';
|
||||
const expectedUrl = 'https://cloud.seafile.com/wikis/6cbbded99bd272796a2/y4Jw/';
|
||||
expect(getWikPageLink(pageId)).toBe(expectedUrl);
|
||||
// Restore original window.location
|
||||
window.location = originalLocation;
|
||||
});
|
||||
});
|
@ -8,6 +8,13 @@ export const gettext = window.gettext;
|
||||
|
||||
export const internalFilePath = '/_Internal/seatable-integration.json';
|
||||
|
||||
// for unit test global variable
|
||||
if (!window.app) {
|
||||
window.app = {};
|
||||
window.app.config = {};
|
||||
window.app.pageOptions = {};
|
||||
}
|
||||
|
||||
export const siteRoot = window.app.config.siteRoot;
|
||||
export const loginUrl = window.app.config.loginUrl;
|
||||
export const avatarInfo = window.app.config.avatarInfo;
|
||||
|
@ -17,4 +17,4 @@ echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >~/.npmrc
|
||||
|
||||
cd $GITHUB_WORKSPACE
|
||||
|
||||
cd ./frontend && npm install && npm run lint
|
||||
cd ./frontend && npm install && npm run lint && npm run test
|
||||
|
Loading…
Reference in New Issue
Block a user