Skip to content
代码片段 群组 项目
未验证 提交 12d75bbd 编辑于 作者: Alexander Turinske's avatar Alexander Turinske
浏览文件

Add fallback for yaml editor

- sometimes getModel returns nul and the ui errors
- add a check for this
- update tests

Changelog: fixed
上级 d0d4fe04
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
...@@ -2,6 +2,8 @@ import { registerSchema } from '~/ide/utils'; ...@@ -2,6 +2,8 @@ import { registerSchema } from '~/ide/utils';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { getBaseURL, joinPaths } from '~/lib/utils/url_utility'; import { getBaseURL, joinPaths } from '~/lib/utils/url_utility';
const DEFAULT_FILENAME = '*.yaml';
export const getSecurityPolicyListUrl = ({ namespacePath, namespaceType = 'group' }) => { export const getSecurityPolicyListUrl = ({ namespacePath, namespaceType = 'group' }) => {
const isGroup = namespaceType === 'group'; const isGroup = namespaceType === 'group';
return joinPaths( return joinPaths(
...@@ -62,7 +64,7 @@ export class SecurityPolicySchemaExtension { ...@@ -62,7 +64,7 @@ export class SecurityPolicySchemaExtension {
namespaceType, namespaceType,
policyType, policyType,
}); });
const modelFileName = instance.getModel().uri.path.split('/').pop(); const modelFileName = instance.getModel()?.uri.path.split('/').pop() || DEFAULT_FILENAME;
registerSchema({ registerSchema({
uri: getSecurityPolicySchemaUrl({ namespacePath, namespaceType }), uri: getSecurityPolicySchemaUrl({ namespacePath, namespaceType }),
...@@ -76,7 +78,7 @@ export class SecurityPolicySchemaExtension { ...@@ -76,7 +78,7 @@ export class SecurityPolicySchemaExtension {
namespacePath: projectPath, namespacePath: projectPath,
namespaceType: 'project', namespaceType: 'project',
}); });
const modelFileName = instance.getModel().uri.path.split('/').pop(); const modelFileName = instance.getModel()?.uri.path.split('/').pop() || DEFAULT_FILENAME;
registerSchema({ registerSchema({
uri, uri,
......
...@@ -246,6 +246,23 @@ describe('SecurityPolicySchemaExtension', () => { ...@@ -246,6 +246,23 @@ describe('SecurityPolicySchemaExtension', () => {
fileMatch: ['policy.yml'], fileMatch: ['policy.yml'],
}); });
}); });
it('registers the schema even if `getModel` fails', async () => {
instance.getModel = jest.fn().mockImplementation(() => undefined);
await instance.registerSecurityPolicyEditorSchema({
namespacePath: mockNamespacePath,
namespaceType: 'project',
policyType: 'scan_execution_policy',
});
expect(registerSchema).toHaveBeenCalledTimes(1);
expect(registerSchema).toHaveBeenCalledWith({
uri: `${TEST_HOST}/${mockNamespacePath}/-/security/policies/schema`,
schema: mockScanExecutionPolicyProperties,
fileMatch: ['*.yaml'],
});
});
}); });
}); });
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册