UNPKG

@adso-ts/badges

Version:
45 lines (44 loc) 8.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var badgeGenerator_1 = require("./badgeGenerator"); var colors_const_1 = require("./colors.const"); var mockedGreenBadge = "\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n width=\"110\"\n height=\"20\"\n >\n <linearGradient id=\"s\" x2=\"0\" y2=\"100%\">\n <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>\n <stop offset=\"1\" stop-opacity=\".1\"/>\n </linearGradient>\n <clipPath id=\"r\">\n <rect width=\"110\" height=\"20\" rx=\"3\" fill=\"#fff\"/>\n </clipPath>\n <g clip-path=\"url(#r)\">\n <rect width=\"65\" height=\"20\" fill=\"#555\"/>\n <rect x=\"65\" width=\"45\" height=\"20\" fill=\"#97ca00\"/>\n <rect width=\"110\" height=\"20\" fill=\"url(#s)\"/>\n </g>\n <g fill=\"#fff\" font-family=\"Tahoma,Arial\" font-size=\"110\">\n <text x=\"55\" y=\"140\" fill=\"#000\" fill-opacity=\".3\" transform=\"scale(.1)\">\n Average\n </text>\n <text x=\"50\" y=\"140\" transform=\"scale(.1)\">\n Average\n </text>\n <text x=\"700\" y=\"140\" transform=\"scale(.1)\">\n 90.2%\n </text>\n </g>\n </svg>\n"; var mockedYellowBadge = "\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n width=\"110\"\n height=\"20\"\n >\n <linearGradient id=\"s\" x2=\"0\" y2=\"100%\">\n <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>\n <stop offset=\"1\" stop-opacity=\".1\"/>\n </linearGradient>\n <clipPath id=\"r\">\n <rect width=\"110\" height=\"20\" rx=\"3\" fill=\"#fff\"/>\n </clipPath>\n <g clip-path=\"url(#r)\">\n <rect width=\"65\" height=\"20\" fill=\"#555\"/>\n <rect x=\"65\" width=\"45\" height=\"20\" fill=\"#dfb317\"/>\n <rect width=\"110\" height=\"20\" fill=\"url(#s)\"/>\n </g>\n <g fill=\"#fff\" font-family=\"Tahoma,Arial\" font-size=\"110\">\n <text x=\"55\" y=\"140\" fill=\"#000\" fill-opacity=\".3\" transform=\"scale(.1)\">\n Average\n </text>\n <text x=\"50\" y=\"140\" transform=\"scale(.1)\">\n Average\n </text>\n <text x=\"700\" y=\"140\" transform=\"scale(.1)\">\n 60.3%\n </text>\n </g>\n </svg>\n"; var mockedBlueBadge = "\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n width=\"110\"\n height=\"20\"\n >\n <linearGradient id=\"s\" x2=\"0\" y2=\"100%\">\n <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>\n <stop offset=\"1\" stop-opacity=\".1\"/>\n </linearGradient>\n <clipPath id=\"r\">\n <rect width=\"110\" height=\"20\" rx=\"3\" fill=\"#fff\"/>\n </clipPath>\n <g clip-path=\"url(#r)\">\n <rect width=\"65\" height=\"20\" fill=\"#555\"/>\n <rect x=\"65\" width=\"45\" height=\"20\" fill=\"#007ec6\"/>\n <rect width=\"110\" height=\"20\" fill=\"url(#s)\"/>\n </g>\n <g fill=\"#fff\" font-family=\"Tahoma,Arial\" font-size=\"110\">\n <text x=\"55\" y=\"140\" fill=\"#000\" fill-opacity=\".3\" transform=\"scale(.1)\">\n Average\n </text>\n <text x=\"50\" y=\"140\" transform=\"scale(.1)\">\n Average\n </text>\n <text x=\"700\" y=\"140\" transform=\"scale(.1)\">\n 76.4%\n </text>\n </g>\n </svg>\n"; var mockedRedBadge = "\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n width=\"110\"\n height=\"20\"\n >\n <linearGradient id=\"s\" x2=\"0\" y2=\"100%\">\n <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>\n <stop offset=\"1\" stop-opacity=\".1\"/>\n </linearGradient>\n <clipPath id=\"r\">\n <rect width=\"110\" height=\"20\" rx=\"3\" fill=\"#fff\"/>\n </clipPath>\n <g clip-path=\"url(#r)\">\n <rect width=\"65\" height=\"20\" fill=\"#555\"/>\n <rect x=\"65\" width=\"45\" height=\"20\" fill=\"#e05d44\"/>\n <rect width=\"110\" height=\"20\" fill=\"url(#s)\"/>\n </g>\n <g fill=\"#fff\" font-family=\"Tahoma,Arial\" font-size=\"110\">\n <text x=\"55\" y=\"140\" fill=\"#000\" fill-opacity=\".3\" transform=\"scale(.1)\">\n Average\n </text>\n <text x=\"50\" y=\"140\" transform=\"scale(.1)\">\n Average\n </text>\n <text x=\"700\" y=\"140\" transform=\"scale(.1)\">\n 30%\n </text>\n </g>\n </svg>\n"; var mockedRedFunctionBadge = "\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n width=\"110\"\n height=\"20\"\n >\n <linearGradient id=\"s\" x2=\"0\" y2=\"100%\">\n <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>\n <stop offset=\"1\" stop-opacity=\".1\"/>\n </linearGradient>\n <clipPath id=\"r\">\n <rect width=\"110\" height=\"20\" rx=\"3\" fill=\"#fff\"/>\n </clipPath>\n <g clip-path=\"url(#r)\">\n <rect width=\"65\" height=\"20\" fill=\"#555\"/>\n <rect x=\"65\" width=\"45\" height=\"20\" fill=\"#e05d44\"/>\n <rect width=\"110\" height=\"20\" fill=\"url(#s)\"/>\n </g>\n <g fill=\"#fff\" font-family=\"Tahoma,Arial\" font-size=\"110\">\n <text x=\"55\" y=\"140\" fill=\"#000\" fill-opacity=\".3\" transform=\"scale(.1)\">\n Functions\n </text>\n <text x=\"50\" y=\"140\" transform=\"scale(.1)\">\n Functions\n </text>\n <text x=\"700\" y=\"140\" transform=\"scale(.1)\">\n 30%\n </text>\n </g>\n </svg>\n"; var mockedRedStatementsBadge = "\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n width=\"110\"\n height=\"20\"\n >\n <linearGradient id=\"s\" x2=\"0\" y2=\"100%\">\n <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>\n <stop offset=\"1\" stop-opacity=\".1\"/>\n </linearGradient>\n <clipPath id=\"r\">\n <rect width=\"110\" height=\"20\" rx=\"3\" fill=\"#fff\"/>\n </clipPath>\n <g clip-path=\"url(#r)\">\n <rect width=\"65\" height=\"20\" fill=\"#555\"/>\n <rect x=\"65\" width=\"45\" height=\"20\" fill=\"#e05d44\"/>\n <rect width=\"110\" height=\"20\" fill=\"url(#s)\"/>\n </g>\n <g fill=\"#fff\" font-family=\"Tahoma,Arial\" font-size=\"110\">\n <text x=\"55\" y=\"140\" fill=\"#000\" fill-opacity=\".3\" transform=\"scale(.1)\">\n Statements\n </text>\n <text x=\"50\" y=\"140\" transform=\"scale(.1)\">\n Statements\n </text>\n <text x=\"700\" y=\"140\" transform=\"scale(.1)\">\n 30%\n </text>\n </g>\n </svg>\n"; describe('Given an example function', function () { describe('When provided with coverage of 90%', function () { it('Then it returns green badge', function () { expect(badgeGenerator_1.generateBadge('90.2%', colors_const_1.COLORS.green)).toBe(mockedGreenBadge); }); }); describe('When provided with coverage of 70%', function () { it('Then it returns blue badge', function () { expect(badgeGenerator_1.generateBadge('76.4%', colors_const_1.COLORS.blue)).toBe(mockedBlueBadge); }); }); describe('When provided with coverage of 50%', function () { it('Then it returns yellow badge', function () { expect(badgeGenerator_1.generateBadge('60.3%', colors_const_1.COLORS.yellow)).toBe(mockedYellowBadge); }); }); describe('When provided with coverage of 30%', function () { it('Then it returns green badge', function () { expect(badgeGenerator_1.generateBadge('30%', colors_const_1.COLORS.red)).toBe(mockedRedBadge); }); }); describe('When provided with coverage of 30%', function () { describe('And functions as a scope', function () { it('Then it returns green badge', function () { expect(badgeGenerator_1.generateBadge('30%', colors_const_1.COLORS.red, 'Functions')).toBe(mockedRedFunctionBadge); }); }); describe('And statements as a scope', function () { it('Then it returns green badge', function () { expect(badgeGenerator_1.generateBadge('30%', colors_const_1.COLORS.red, 'Statements')).toBe(mockedRedStatementsBadge); }); }); }); });