Implemented vite test to make sure blocks.js maintains it's integrity and validates

This commit is contained in:
2025-05-06 00:43:17 +02:00
parent 4ae0edad49
commit 27032c098a
6 changed files with 894 additions and 3 deletions
@@ -0,0 +1,65 @@
import blocks from '@/Utils/blocks';
import path from 'path';
import fs from 'fs';
import { expect } from 'vitest';
describe('blocks.js structure', () => {
it('should contain uuid, componentName, renderComponentName and description for every block', () => {
blocks.groups.forEach(group => {
group.blocks.forEach(block => {
expect(block).toHaveProperty('uuid');
expect(typeof block.uuid).toBe('string');
expect(block).toHaveProperty('componentName');
expect(typeof block.componentName).toBe('string');
expect(block).toHaveProperty('renderComponentName');
expect(typeof block.renderComponentName).toBe('string');
expect(block).toHaveProperty('description');
expect(typeof block.description).toBe('string');
});
});
});
it('should contain optionsComponentName if block is not static', () => {
blocks.groups.forEach(group => {
group.blocks.forEach(block => {
if (!block.static) {
expect(block).toHaveProperty('optionsComponentName');
expect(typeof block.optionsComponentName).toBe('string');
}
});
});
});
it('should not require optionsComponentName if block is static', () => {
blocks.groups.forEach(group => {
group.blocks.forEach(block => {
if (block.static) {
if (block.hasOwnProperty('optionsComponentName')) {
expect(typeof block.optionsComponentName).toBe('string');
}
}
});
});
});
it('should contain a valid thumbUrl that points to an existing file, for each block', () => {
const publicDir = path.resolve(__dirname, '../../../../public');
blocks.groups.forEach(group => {
group.blocks.forEach(block => {
expect(block).toHaveProperty('thumbUrl');
expect(typeof block.thumbUrl).toBe('string');
const isValid = /^\/img\/blocks\/[^\/]+\.(jpg|png)$/.test(block.thumbUrl);
expect(isValid).toBe(true);
const fullPath = path.join(publicDir, block.thumbUrl);
const exists = fs.existsSync(fullPath);
expect(exists).toBe(true);
});
});
});
});
+1 -1
View File
@@ -41,7 +41,7 @@ const activeItemStyles = computed(
const mainNavItems: NavItem[] = [
{
title: 'Dashboard',
href: '/dashboard',
href: '/dashboard/page-admin',
icon: LayoutGrid,
},
];
+1 -1
View File
@@ -11,7 +11,7 @@ import AppLogo from './AppLogo.vue';
const mainNavItems: NavItem[] = [
{
title: 'Dashboard',
href: '/dashboard',
href: '/dashboard/page-admin',
icon: LayoutGrid,
},
];