Skip to content

Commit

Permalink
feat(vite-plugin/testing): add sass/scss transform tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Apr 24, 2024
1 parent 73c1992 commit 17a8ef5
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 5 deletions.
7 changes: 4 additions & 3 deletions vite-plugin/playground/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<template>
<SassTransform />

<AssetTransform />

<JsScriptSetup />
Expand All @@ -8,12 +10,11 @@
<TsScript />

<JsPug />

<!-- TODO: Add tests for 'pascal' and 'combined' too -->
<!-- TODO: Add SCSS Transforms -->
</template>

<script setup>
import SassTransform from './components/SassTransform.vue'
import AssetTransform from './components/AssetTransform.vue'
import JsScriptSetup from './components/JsScriptSetup.vue'
Expand Down
17 changes: 17 additions & 0 deletions vite-plugin/playground/src/components/SassTransform.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<h4>Sass Transform</h4>

<div>
<ColorOverride />
<ColorSassUse />
<ColorScssUse />
<PaddingTest />
</div>
</template>

<script setup>
import ColorOverride from './sass-transform/ColorOverride.vue'
import ColorSassUse from './sass-transform/ColorSassUse.vue'
import ColorScssUse from './sass-transform/ColorScssUse.vue'
import PaddingTest from './sass-transform/PaddingTest.vue'
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<h6>Color Override</h6>

<div>
<q-icon name="map" color="primary" size="50px" />
<q-btn icon="map" color="secondary" round />
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<h6>Color Use (Sass)</h6>

<div class="row justify-center">
<div class="my-colored-div rounded-borders">
&nbsp;
</div>
</div>
</template>

<style lang="sass" scoped>
.my-colored-div
background-color: $primary
width: 50px
height: 50px
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<h6>Color Use (Scss)</h6>

<div class="row justify-center">
<div class="my-colored-div rounded-borders">
&nbsp;
</div>
</div>
</template>

<style lang="scss" scoped>
.my-colored-div {
background-color: $primary;
width: 50px;
height: 50px;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<h6>Padding with $toolbar-padding</h6>

<div class="row justify-center">
<div class="my-div">
&nbsp;
</div>
</div>
</template>

<style lang="sass" scoped>
.my-div
padding: $toolbar-padding
background-color: $secondary
</style>
7 changes: 6 additions & 1 deletion vite-plugin/playground/src/quasar-variables.sass
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// $primary : #1976D2
$primary: #388310
$secondary : #26A69A
// $secondary : #26A69A
$secondary : #a62659

$accent : #9C27B0

$dark : #1D1D1D
Expand All @@ -9,3 +11,6 @@ $positive : #21BA45
$negative : #C10015
$info : #31CCEC
$warning : #F2C037

// $toolbar-padding: 0 12px
$toolbar-padding: 100px
29 changes: 29 additions & 0 deletions vite-plugin/testing/runtime/tests/sass-transform.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, test } from 'vitest'
import { mount } from '@vue/test-utils'

import 'quasar/src/css/index.sass'

import { QToolbar } from 'quasar'
import PaddingTest from 'playground/sass-transform/PaddingTest.vue'

describe('Sass Transform', () => {
test('variables file is taken into account', () => {
const wrapper = mount(QToolbar)

const { element } = wrapper.get('div')
expect(
window.getComputedStyle(element)
.getPropertyValue('padding')
).toBe('100px')
})

test('correctly uses sass variables', () => {
const wrapper = mount(PaddingTest)

const { element } = wrapper.get('div.my-div')
expect(
window.getComputedStyle(element)
.getPropertyValue('padding')
).toBe('100px')
})
})
2 changes: 1 addition & 1 deletion vite-plugin/testing/runtime/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineConfig(() => {

quasar({
devTreeshaking: true,
sassVariables: false,
sassVariables: resolve('src/quasar-variables.sass'),
autoImportComponentCase: 'combined'
})
],
Expand Down

0 comments on commit 17a8ef5

Please sign in to comment.