Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sysvale/cuida",
"version": "3.154.11",
"version": "3.154.12",
"description": "A design system built by Sysvale, using storybook and Vue components",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/components/InlineDateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default {
inputControl: 0,
attributes: [
{
dates: new Date(),
dates: DateTime.now().toJSDate(),
dot: true,
},
],
Expand Down
3 changes: 2 additions & 1 deletion src/components/InternalComponents/MonthSelectorGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script setup>
import CdsGrid from '../Grid.vue';
import { computed, ref, onMounted, watch } from 'vue';
import { DateTime } from 'luxon';

defineOptions({ name: 'CdsMonthSelectorGrid' });

Expand All @@ -45,7 +46,7 @@ const props = defineProps({
},
year: {
type: Number,
default: new Date().getFullYear(),
default: DateTime.now().year,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Padrão default de prop avaliado em tempo de carregamento do módulo

DateTime.now().year nessa posição (dentro do objeto literal de defineProps) é avaliado uma única vez, quando o módulo é importado, e não por instância do componente. Isso acontece porque o compilador do Vue 3 extrai o objeto de defineProps para o nível de módulo (nas opções do componente), fora da função setup.

Por isso, mocks de Settings.now configurados no beforeEach dos testes não afetam esse valor padrão, pois o módulo já foi importado antes de qualquer beforeEach ser executado. Os testes atuais passam porque o ano mockado (2026) coincide com o ano real — mas isso é frágil.

A variável todayYear em YearSelectorGrid.vue não tem esse problema porque é declarada diretamente no topo do setup() (dentro do corpo da função), sendo avaliada por instância.

Para garantir que o default seja avaliado por instância e respeite mocks em testes, utilize uma factory function:

Suggested change
default: DateTime.now().year,
default: () => DateTime.now().year,

Rule Used: What: Components in Vue 3 must adhere to the speci... (source)

},
});

Expand Down
3 changes: 2 additions & 1 deletion src/components/InternalComponents/YearSelectorGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

<script setup>
import { ref, computed, onUnmounted } from 'vue';
import { DateTime } from 'luxon';
import CdsGrid from '../Grid.vue';

defineOptions({ name: 'CdsYearSelectorGrid' });
Expand Down Expand Up @@ -61,7 +62,7 @@ const props = defineProps({
const emits = defineEmits(['click']);

/* REACTIVE DATA */
const todayYear = new Date().getFullYear();
const todayYear = DateTime.now().year;
const selectedYear = computed(() => {
if (!props.selectedDate) return null;
return parseInt(props.selectedDate.split('-')[0]);
Expand Down
12 changes: 10 additions & 2 deletions src/tests/SelectorGridHighlight.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { describe, test, expect, beforeEach, vi } from 'vitest';
import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import MonthSelectorGrid from '../components/InternalComponents/MonthSelectorGrid.vue';
import YearSelectorGrid from '../components/InternalComponents/YearSelectorGrid.vue';
import { Settings } from 'luxon';

describe('SelectorGrid Highlight Fix', () => {
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(new Date(2026, 1, 10)); // Feb 10, 2026
const mockDate = new Date(2026, 1, 10); // Feb 10, 2026
vi.setSystemTime(mockDate);
Settings.now = () => mockDate.getTime();
});

afterEach(() => {
vi.useRealTimers();
Settings.now = () => Date.now();
});

describe('MonthSelectorGrid', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants/inputTypes.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default ['text', 'textarea', 'email', 'password', 'tel', 'number', 'search', 'url'];
export default ['text', 'textarea', 'email', 'password', 'tel', 'number', 'search', 'url', 'date'];
Loading