mirror of
https://github.com/tabler/tabler.git
synced 2026-10-13 21:57:00 +04:00
146 lines
2.7 KiB
SCSS
146 lines
2.7 KiB
SCSS
// Unit tests for the per-component token helpers in scss/mixins/:
|
|
// `defaults()` (scss/mixins/_functions.scss) builds a token map from a
|
|
// defaults map plus an overrides map, and `tokens()` (scss/mixins/_mixins.scss)
|
|
// emits that map as custom properties. Together they back the `$card-tokens`
|
|
// pattern in ui/_cards.scss, so both the compile-time `@use … with ()` path and
|
|
// runtime `.card { --card-bg: … }` overrides run through the same map.
|
|
|
|
@use '../mixins/functions' as *;
|
|
@use '../mixins/mixins' as *;
|
|
|
|
@include describe('defaults()') {
|
|
@include it('merges the overrides over the defaults, keeping the original slot order') {
|
|
@include assert-equal(
|
|
defaults(
|
|
(
|
|
--a: 1,
|
|
--b: 2,
|
|
--c: 3,
|
|
),
|
|
(
|
|
--b: 20,
|
|
)
|
|
),
|
|
(
|
|
--a: 1,
|
|
--b: 20,
|
|
--c: 3,
|
|
)
|
|
);
|
|
}
|
|
|
|
@include it('appends override-only keys after the defaults') {
|
|
@include assert-equal(
|
|
defaults(
|
|
(
|
|
--a: 1,
|
|
),
|
|
(
|
|
--b: 2,
|
|
)
|
|
),
|
|
(
|
|
--a: 1,
|
|
--b: 2,
|
|
)
|
|
);
|
|
}
|
|
|
|
@include it('expands a plain list of keys to `key: true`') {
|
|
@include assert-equal(
|
|
defaults((--a --b --c), ()),
|
|
(
|
|
--a: true,
|
|
--b: true,
|
|
--c: true,
|
|
)
|
|
);
|
|
}
|
|
|
|
@include it('removes a key whose override value is null') {
|
|
@include assert-equal(
|
|
defaults(
|
|
(
|
|
--a: 1,
|
|
--b: 2,
|
|
),
|
|
(
|
|
--b: null,
|
|
)
|
|
),
|
|
(
|
|
--a: 1,
|
|
)
|
|
);
|
|
}
|
|
|
|
@include it('keeps a null default so tokens() can still emit it') {
|
|
@include assert-equal(
|
|
defaults(
|
|
(
|
|
--a: 1,
|
|
--b: null,
|
|
),
|
|
()
|
|
),
|
|
(
|
|
--a: 1,
|
|
--b: null,
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
@include describe('tokens()') {
|
|
@include it('emits every map entry as a custom property, in map order') {
|
|
@include assert {
|
|
@include output {
|
|
.t {
|
|
@include tokens(
|
|
(
|
|
--a: 1,
|
|
--b: 2px,
|
|
--c: var(--x),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
@include expect {
|
|
.t {
|
|
--a: 1;
|
|
--b: 2px;
|
|
--c: var(--x);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@include it('applies a $card-tokens-style override through defaults()') {
|
|
$overridden: defaults(
|
|
(
|
|
--card-bg: var(--bg-surface),
|
|
--card-color: inherit,
|
|
),
|
|
(
|
|
--card-bg: red,
|
|
)
|
|
);
|
|
|
|
@include assert {
|
|
@include output {
|
|
.card {
|
|
@include tokens($overridden);
|
|
}
|
|
}
|
|
|
|
@include expect {
|
|
.card {
|
|
--card-bg: red;
|
|
--card-color: inherit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|