Skip to content

Commit

Permalink
chore: add modules unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpenkov committed Jan 16, 2025
1 parent d57abbe commit f8b1477
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
3 changes: 0 additions & 3 deletions unit-tests/color.test.js

This file was deleted.

3 changes: 3 additions & 0 deletions unit-tests/appbar.test.js → unit-tests/components.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { testKendoComponent } = require("./utility");

// AppBar
testKendoComponent("appbar", "k-appbar", []);

//TODO: Add more components here
20 changes: 20 additions & 0 deletions unit-tests/modules.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { testKendoModule } = require("./utility");

// Color System
testKendoModule("color-system", "kendo-colors", "--kendo-color");

// Spacing
testKendoModule("spacing", "kendo-spacing", "--kendo-spacing");

// Elevation
testKendoModule("elevation", "kendo-elevation", "--kendo-elevation");

// Radii
testKendoModule("radii", "kendo-border-radii", "--kendo-border-radius");

// Typography
testKendoModule("font-size", "kendo-font-sizes", "--kendo-font-size");
testKendoModule("font-weight", "kendo-font-weights", "--kendo-font-weight");
testKendoModule("font-family", "kendo-font-families", "--kendo-font-family");
testKendoModule("line-height", "kendo-line-heights", "--kendo-line-height");
testKendoModule("letter-spacing", "kendo-letter-spacings", "--kendo-letter-spacing");
50 changes: 39 additions & 11 deletions unit-tests/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ const { describe, it, expect } = require("@jest/globals");
const theme = process.env.THEME || "default";
const themeDir = path.resolve("packages", theme, "scss");
const nodeModules = path.resolve("node_modules");
const themeMetadata = path.resolve("packages", theme, "dist", "meta", "sassdoc-raw-data.json");
const themeMetadata = path.resolve("packages", theme, "dist", "meta", "sassdoc-data.json");
const data = JSON.parse(fs.readFileSync(themeMetadata));

function writeResultToDist(result, file) {
const outputPath = path.join(__dirname, "dist", `${file}.css`);
if (!fs.existsSync(path.join(__dirname, "dist"))) {
fs.mkdirSync(path.join(__dirname, "dist"));
}
fs.writeFileSync(outputPath, result);
}

function fetchComponentVariables(component) {
return data.filter((item) => item.group[0] === component).map((item) => item.context.name);
return data.variables.filter((item) => item.group[0] === component).map((item) => item.context.name);
}

function compileSassString(sassString) {
Expand Down Expand Up @@ -40,21 +48,40 @@ function compileKendoCore(configurations) {
/**
* Tests a kendo module using a jest testing template.
* @param {string} module - The module name.
* @param {string} cssVariablesPrefix - The module css variables prefix.
* @param {string[]} dependencyClassNames - The component dependencies classNames.
* @param {string} mapName - The module map name.
* @param {string} cssVariablePrefix - The module css variables prefix.
*/
function testKendoModule(module, cssVariablesPrefix = []) {
function testKendoModule(module, mapName, cssVariablePrefix) {
describe(module, () => {
const result = compileKendoCore();
const prettyValue = data.variables.filter((item) => item.context.name === mapName)[0].prettyValue;
const uniqueValues = [];
const configurations = `
$${mapName}: (
${Object.keys(prettyValue)
.map((property, index) => {
const uniqueValue = `value-${index + 1}`;
uniqueValues.push(uniqueValue);
return `${property}: ${uniqueValue},`;
})
.join("\n")}
)`;

const result = compileKendoCore(configurations);
writeResultToDist(result, module);

it("should compile", () => {
expect(result).toBeDefined();
});

cssVariablesPrefix &&
it("should compile with variable customizations", () => {
uniqueValues.forEach((value) => {
expect(result).toContain(`${value};`);
});
});

cssVariablePrefix &&
it("should compile with all css variables", () => {
cssVariablesPrefix.forEach((className) => {
expect(result).toContain(`${className}`);
});
expect(result).toContain(`${cssVariablePrefix}`);
});
});
}
Expand All @@ -71,13 +98,14 @@ function testKendoComponent(component, className, dependencyClassNames) {
const uniqueValues = [];
const configurations = variables
.map((property, index) => {
const uniqueValue = `value-${index}`; // TODO: modify the pattern for unique values
const uniqueValue = `value-${index + 1}`;
uniqueValues.push(uniqueValue);
return `$${property}: ${uniqueValue},`;
})
.join("\n");

const result = compileKendoComponent(component, configurations);
writeResultToDist(result, component);

it("should compile", () => {
expect(result).toBeDefined();
Expand Down

0 comments on commit f8b1477

Please sign in to comment.