first commit

This commit is contained in:
armansansd
2023-07-12 16:31:19 +01:00
commit 3424b1927b
23306 changed files with 2217776 additions and 0 deletions
+159
View File
@@ -0,0 +1,159 @@
@import "true";
@import '../../scss/util/unit';
@import '../../scss/util/breakpoint';
@include test-module('Breakpoint') {
@include test('Breakpoint (Named to Em) [function]') {
$test: breakpoint(medium);
$expect: '(min-width: 40em)';
@include assert-equal($test, $expect,
'Converts a named breakpoint to an em value');
}
@include test('Breakpoint (Rem/Px to Em) [function]') {
$expect: '(min-width: 1em)';
@include assert-equal(breakpoint(16px), $expect,
'Converts a pixel breakpoint to em');
@include assert-equal(breakpoint(1rem), $expect,
'Converts a rem breakpoint to em');
}
@include test('Breakpoint (Only Range) [function]') {
$test: breakpoint(medium only);
$expect: '(min-width: 40em) and (max-width: 63.99875em)';
$test-lowest: breakpoint(small only);
$expect-lowest: '(max-width: 39.99875em)';
$test-highest: breakpoint(xxlarge only);
$expect-highest: '(min-width: 90em)';
@include assert-equal($test, $expect,
'Creates a min/max-width range out of a named breakpoint');
@include assert-equal($test-lowest, $expect-lowest,
'Creates a max-width range if the breakpoint is the lowest');
@include assert-equal($test-highest, $expect-highest,
'Creates a min-width range if the breakpoint is the highest');
}
@include test('Breakpoint (Named Down Range) [function]') {
$test: breakpoint(medium down);
$expect: '(max-width: 63.99875em)';
@include assert-equal($test, $expect,
'Creates a down range out of a medium breakpoint');
$test-lowest: breakpoint(small down);
$expect-lowest: '(max-width: 39.99875em)';
@include assert-equal($test-lowest, $expect-lowest,
'Creates a down range out of a small breakpoint');
$test-highest: breakpoint(xxlarge down);
$expect-highest: '';
@include assert-equal($test-highest, $expect-highest,
'Skips media query creation for xxlarge down');
}
@include test('Breakpoint (Value Down Range) [function]') {
$expect: '(max-width: 1em)';
@include assert-equal(breakpoint(16px down), $expect,
'Creates a down range out of a pixel value');
@include assert-equal(breakpoint(1rem down), $expect,
'Creates a down range out of a rem value');
@include assert-equal(breakpoint(1em down), $expect,
'Creates a down range out of an em value');
}
@include test('Breakpoint (Empty String) [function]') {
$expect: '';
@include assert-equal(breakpoint(small up), $expect,
'Returns an empty string for the value small up');
@include assert-equal(breakpoint(0 down), $expect,
'Returns an empty string for the value 0 down');
@include assert-equal(breakpoint(0 up), $expect,
'Returns an empty string for the value 0 up');
}
@include test('Breakpoint (Orientation/Retina) [function]') {
@include assert-equal(breakpoint(landscape), '(orientation: landscape)',
'Creates special media query for landscape');
@include assert-equal(breakpoint(portrait), '(orientation: portrait)',
'Creates special media query for portrait');
@include assert-equal(breakpoint(retina), '(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)',
'Creates special media query for retina');
}
@include test('Breakpoint (Unknown Value) [function]') {
@include assert-equal(breakpoint(xxxxlarge), '', 'Returns an empty string for non-existant media queries');
}
@include test('Map Serialize [function]') {
$input: (
small: 1em,
medium: 2em,
large: 3em,
);
$test: -zf-bp-serialize($input);
$expect: 'small=1em&medium=2em&large=3em';
@include assert-equal($test, $expect,
'Converts a Sass map into a string');
}
@include test('Map Next [function]') {
$input: (
one: 'One',
two: 'Two',
three: 'Three',
);
$test_next: -zf-map-next($input, two);
$expect_next: map-get($input, three);
@include assert-equal($test_next, $expect_next,
'Returns the next value in a map');
$test_last: -zf-map-next($input, three);
$expect_last: null;
@include assert-equal($test_last, $expect_last,
'Returns null if the key is last in the map');
$test_null: -zf-map-next($input, four);
$expect_null: null;
@include assert-equal($test_null, $expect_null,
'Returns null if the key is not in the map');
}
@include test('Get Breakpoint Value [function]') {
$config: (
small: 0,
large: 1,
);
$test_kittens: -zf-get-bp-val($config, kittens);
$expect_kittens: null;
@include assert-equal($test_kittens, $expect_kittens,
'Given a non-existant breakpoint name, return null');
$test_match: -zf-get-bp-val($config, large);
$expect_match: 1;
@include assert-equal($test_match, $expect_match,
'Given a matching breakpoint, returns the exact value');
@include assert-equal(-zf-get-bp-val($config, medium), 0,
'Given a nearby breakpoint, returns the next lowest value');
@include assert-equal(-zf-get-bp-val($config, xlarge), 1,
'Given a nearby breakpoint, returns the next lowest value');
}
}
+47
View File
@@ -0,0 +1,47 @@
@import "true";
@import '../../scss/global';
@import '../../scss/util/color';
@include test-module('Color') {
@include test('Foreground (Black) [function]') {
$test: color-pick-contrast($white);
$expect: $black;
@include assert-equal($test, $expect,
'Returns black if the input color is light');
}
@include test('Foreground (White) [function]') {
$test: color-pick-contrast($black);
$expect: $white;
@include assert-equal($test, $expect,
'Returns white if the input color is dark');
}
@include test('Smart Scale (Darken) [function]') {
$color: $white;
$scale: 5%;
$threshold: 60%;
$test: smart-scale($color, $scale, $threshold);
$expect: scale-color($color, $lightness: -$scale);
@include assert-equal($test, $expect,
'Darkens a light color');
}
@include test('Smart Scale (Lighten) [function]') {
$color: $black;
$scale: 5%;
$threshold: 60%;
$test: smart-scale($color, $scale, $threshold);
$expect: scale-color($color, $lightness: $scale);
@include assert-equal($test, $expect,
'Lightens a dark color');
}
}
+42
View File
@@ -0,0 +1,42 @@
@import "true";
@import '../../scss/util/math';
@import '../../scss/global';
@import '../../scss/components/responsive-embed';
@import '../../scss/grid/grid';
@include test-module('Components') {
@include test('Ratio to Percentage [function]') {
$test: ratio-to-percentage(3 by 4);
$expect: 4 / 3 * 100%;
@include assert-equal($test, $expect,
'Creates a percentage value from a ratio');
}
@include test('Grid Column [function]') {
@include assert-equal(grid-column(6), 50%,
'Creates a column width from a column count');
@include assert-equal(grid-column(0.5), 50%,
'Creates a column width from a decimal value');
@include assert-equal(grid-column(50%), 50%,
'Creates a column width from a percentage value');
}
@include test('Flex Grid Column [function]') {
@include assert-equal(flex-grid-column(), 1 1 0px,
'Creates an expanding flex property when passed no value');
@include assert-equal(flex-grid-column(shrink), 0 0 auto,
'Creates a shrinking flex property when passed shrink');
@include assert-equal(flex-grid-column(6), 0 0 50%,
'Creates a fixed flex property from a column count');
@include assert-equal(flex-grid-column(0.5), 0 0 50%,
'Creates a fixed flex property from a decimal value');
@include assert-equal(flex-grid-column(50%), 0 0 50%,
'Creates a fixed flex property from a percentage value');
@include assert-equal(flex-grid-column(1 of 2), 0 0 50%,
'Creates a fixed flex property from an x of y value');
}
}
+27
View File
@@ -0,0 +1,27 @@
@import "true";
@import '../../scss/util/selector';
@include test-module('Selector') {
@include test('Selector [function]') {
$test: #{text-inputs(text password)};
$expect: "[type='text'], [type='password']";
//@debug $test;
@include assert-equal($test, $expect,
'Creates a selector out of a list of text input types');
}
@include test('Selector (with modifiers) [function]') {
$test: #{text-inputs(text password, $modifier: ':focus')};
$expect: "[type='text']:focus, [type='password']:focus";
//@debug $test;
@include assert-equal($test, $expect,
'Creates a selector out of a list of text input types with a modifier');
}
}
+50
View File
@@ -0,0 +1,50 @@
@import "true";
@import '../../scss/util/unit';
@include test-module('Units') {
// Strip Units
@include test('Strip Units [function]') {
$expect: 20;
@include assert-equal(strip-unit(20px), $expect,
'Strips the unit from a number');
@include assert-equal(strip-unit(20), $expect,
'Returns the same number when given a unitless value');
}
// Convert To Rem
@include test('Convert To Rem [function]') {
$expect: 2rem;
@include assert-equal(-zf-to-rem(32, 16), $expect,
'Converts a unit to the equivalent in rems');
@include assert-equal(-zf-to-rem(2rem, 16), $expect,
'Keeps rem values the same');
}
// Rem Calculator
@include test('Rem Calculator [function]') {
$test: rem-calc((8 16 32 64), 16);
$expect: 0.5rem 1rem 2rem 4rem;
@include assert-equal($test, $expect,
'Converts an arbitrary number of values into rem equivalents');
}
// Breakpoint to Em
@include test('Breakpoint To Em [function]') {
$expect: 1em;
@include assert-equal(-zf-bp-to-em(16), $expect,
'Converts a unitless value to em');
@include assert-equal(-zf-bp-to-em(16px), $expect,
'Converts a pixel value to em');
@include assert-equal(-zf-bp-to-em(1rem), $expect,
'Converts a rem value to em');
@include assert-equal(-zf-bp-to-em(1em), $expect,
'Converts an em value to em');
}
}
+128
View File
@@ -0,0 +1,128 @@
@import "true";
@import '../../scss/util/unit';
@import '../../scss/util/value';
@include test-module('Value') {
@include test('Value (Not Falsey) [function]') {
$boolean: has-value(true);
$number: has-value(1px);
$color: has-value(#000);
$list: has-value(1px solid black);
$description: 'Returns true if the value is not falsey';
@include assert-equal($boolean, true, $description);
@include assert-equal($number, true, $description);
@include assert-equal($color, true, $description);
@include assert-equal($list, true, $description);
}
@include test('Value (Falsey) [function]') {
$zero: has-value(0px);
$null: has-value(null);
$none: has-value(none);
$empty: has-value(());
$description: 'Returns false if the value is falsey';
@include assert-equal($zero, false, $description);
@include assert-equal($null, false, $description);
@include assert-equal($none, false, $description);
@include assert-equal($empty, false, $description);
}
@include test('Get Side [function]') {
$valueOne: 1rem;
$testOne: (
get-side($valueOne, top),
get-side($valueOne, right),
get-side($valueOne, bottom),
get-side($valueOne, left),
);
$expectOne: (1rem, 1rem, 1rem, 1rem,);
@include assert-equal($testOne, $expectOne,
'Returns correct sides when given one side value');
$valueTwo: 1rem 2rem;
$testTwo: (
get-side($valueTwo, top),
get-side($valueTwo, right),
get-side($valueTwo, bottom),
get-side($valueTwo, left),
);
$expectTwo: (1rem, 2rem, 1rem, 2rem,);
@include assert-equal($testTwo, $expectTwo,
'Returns correct sides when given two side values');
$valueThree: 1rem 2rem 3rem;
$testThree: (
get-side($valueThree, top),
get-side($valueThree, right),
get-side($valueThree, bottom),
get-side($valueThree, left),
);
$expectThree: (1rem, 2rem, 3rem, 2rem,);
@include assert-equal($testThree, $expectThree,
'Returns correct sides when given three side values');
$valueFour: 1rem 2rem 3rem 4rem;
$testFour: (
get-side($valueFour, top),
get-side($valueFour, right),
get-side($valueFour, bottom),
get-side($valueFour, left),
);
$expectFour: (1rem, 2rem, 3rem, 4rem,);
@include assert-equal($testFour, $expectFour,
'Returns correct sides when given four side values');
}
@include test('Get Border Value [function]') {
$value: 10px dashed green;
$width: get-border-value($value, width);
$style: get-border-value($value, style);
$color: get-border-value($value, color);
$description: 'Returns the right value of a border property';
@include assert-equal($width, 10px, $description);
@include assert-equal($style, dashed, $description);
@include assert-equal($color, green, $description);
$defaultWidth: get-border-value(solid black, width);
$defaultStyle: get-border-value(10px black, style);
$defaultColor: get-border-value(10px solid, color);
$defaultDescription: 'Returns a default value if a property is missing';
@include assert-equal($defaultWidth, 0, $defaultDescription);
@include assert-equal($defaultStyle, solid, $defaultDescription);
@include assert-equal($defaultColor, black, $defaultDescription);
}
@include test('Map Deep Get [function]') {
$map: (
one: (
two: 'three',
),
);
$expect: 'three';
@include assert-equal(map-deep-get($map, one, two), $expect,
'Gets a value from a nested map');
}
@include test('Map Safe Get [function]') {
$map: (
one: 'two'
);
$expect: 'two';
@include assert-equal(map-safe-get($map, one), $expect,
'Safely return a value from a map');
}
// TODO: Add spec for pow()
}
+18
View File
@@ -0,0 +1,18 @@
var path = require('path');
var sassTrue = require('sass-true');
// Test Files
var breakpointFile = path.join(__dirname, '_breakpoint.scss');
var colorFile = path.join(__dirname, '_color.scss');
var selectorFile = path.join(__dirname, '_selector.scss');
var unitFile = path.join(__dirname, '_unit.scss');
var valueFile = path.join(__dirname, '_value.scss');
var componentsFile = path.join(__dirname, '_components.scss');
// Run Tests
sassTrue.runSass({file: breakpointFile}, describe, it);
sassTrue.runSass({file: colorFile}, describe, it);
sassTrue.runSass({file: selectorFile}, describe, it);
sassTrue.runSass({file: unitFile}, describe, it);
sassTrue.runSass({file: valueFile}, describe, it);
sassTrue.runSass({file: componentsFile}, describe, it);