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

This commit is contained in:
Helge-Mikael Nordgård 2025-05-06 00:43:17 +02:00
parent 4ae0edad49
commit 27032c098a
6 changed files with 894 additions and 3 deletions

819
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,10 +17,12 @@
"eslint-config-prettier": "^10.0.1", "eslint-config-prettier": "^10.0.1",
"eslint-plugin-vue": "^9.32.0", "eslint-plugin-vue": "^9.32.0",
"flowbite": "^1.8.1", "flowbite": "^1.8.1",
"jsdom": "^26.1.0",
"prettier": "^3.4.2", "prettier": "^3.4.2",
"prettier-plugin-organize-imports": "^4.1.0", "prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-tailwindcss": "^0.6.11", "prettier-plugin-tailwindcss": "^0.6.11",
"typescript-eslint": "^8.23.0", "typescript-eslint": "^8.23.0",
"vitest": "^3.1.3",
"vue-tsc": "^2.2.4" "vue-tsc": "^2.2.4"
}, },
"dependencies": { "dependencies": {

View File

@ -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);
});
});
});
});

View File

@ -41,7 +41,7 @@ const activeItemStyles = computed(
const mainNavItems: NavItem[] = [ const mainNavItems: NavItem[] = [
{ {
title: 'Dashboard', title: 'Dashboard',
href: '/dashboard', href: '/dashboard/page-admin',
icon: LayoutGrid, icon: LayoutGrid,
}, },
]; ];

View File

@ -11,7 +11,7 @@ import AppLogo from './AppLogo.vue';
const mainNavItems: NavItem[] = [ const mainNavItems: NavItem[] = [
{ {
title: 'Dashboard', title: 'Dashboard',
href: '/dashboard', href: '/dashboard/page-admin',
icon: LayoutGrid, icon: LayoutGrid,
}, },
]; ];

View File

@ -3,9 +3,14 @@ import laravel from 'laravel-vite-plugin';
import path from 'path'; import path from 'path';
import tailwindcss from "@tailwindcss/vite"; import tailwindcss from "@tailwindcss/vite";
import { resolve } from 'node:path'; import { resolve } from 'node:path';
import { defineConfig } from 'vite'; import { defineConfig } from 'vitest/config';
export default defineConfig({ export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
include: ['resources/js/__tests__/**/*.test.js'],
},
plugins: [ plugins: [
laravel({ laravel({
input: ['resources/js/app.ts'], input: ['resources/js/app.ts'],