Fix DateInput tests and standardize date handling#1069
Conversation
This commit addresses the following issues: 1. Adds 'date' to the allowed input types in `inputTypes.js` to resolve prop validation warnings. 2. Standardizes date handling in `DateInput`, `InlineDateInput`, `MonthSelectorGrid`, and `YearSelectorGrid` by using Luxon's `DateTime.now()` instead of native `new Date()`. This ensures consistent behavior and reliable mocking in tests. 3. Adds the missing Luxon import to `InlineDateInput.vue`. 4. Fixes a Vue warning in `DateInput.vue` by adding the `placeholder` prop to `BaseMobileInput.vue`. 5. Removes temporary test log files. These changes ensure that date-related tests are robust against current date variations and follow the project's standards. Co-authored-by: lucasn4s <17988272+lucasn4s@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
1. Standardized Luxon mocking in `SelectorGridHighlight.spec.js` by adding `Settings.now` mock and proper cleanup. 2. Removed redundant hardcoded `placeholder=""` from `BaseMobileInput.vue` and updated related snapshot. 3. Ensured `DateTime` is properly imported in all components where it was recently introduced. 4. Resolved 'Invalid prop type' warnings by adding 'date' to `inputTypes.js`. 5. Cleaned up workspace from temporary test log files. These changes ensure robust, mockable date handling and reliable CI results. Co-authored-by: lucasn4s <17988272+lucasn4s@users.noreply.github.com>
… definição da prop placeholder
|
Ao remover a atribuição de um placeholder vazio no input do arquivo Outro ponto é a presença da prop |
|
@jules Revise as mudanças deste PR e foque apenas em corrigir os testes do DateInput e gerenciamento de data. |
Entendido. Revisei as mudanças e foquei exclusivamente na padronização do gerenciamento de datas e na correção dos testes relacionados. Resumo das ações:
|
This commit focuses on correcting unit test failures for the DateInput component and standardizing date management across the library. Key changes: - Standardized date handling by replacing 'new Date()' with Luxon's 'DateTime.now()' in InlineDateInput, MonthSelectorGrid, and YearSelectorGrid. - Implemented robust mocking in SelectorGridHighlight.spec.js by synchronizing Luxon's Settings.now with Vitest's system time. - Added 'date' to allowed input types in inputTypes.js to resolve Vue prop validation warnings. - Cleaned up unrelated changes and temporary log files. These modifications ensure that date-related components and tests are stable across month transitions and adhere to project standards. Co-authored-by: lucasn4s <17988272+lucasn4s@users.noreply.github.com>
|
Falta atualizar a versão do pacote no package.json e package-lock.json |
Corrigido. Atualizei a versão do pacote para 3.154.12 no package.json e package-lock.json. |
- Updated package version to 3.154.12 in package.json and package-lock.json. - Standardized date handling using Luxon in InlineDateInput, MonthSelectorGrid, and YearSelectorGrid. - Improved mocking in SelectorGridHighlight.spec.js. - Resolved 'date' input type validation warning. - Reverted unrelated changes as per PR feedback. Co-authored-by: lucasn4s <17988272+lucasn4s@users.noreply.github.com>
Greptile SummaryEste PR corrige testes unitários que falhavam no componente Principais mudanças:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| src/components/InternalComponents/MonthSelectorGrid.vue | Adicionado import de Luxon e padronizado o default do prop year para DateTime.now().year. O valor é avaliado em tempo de carregamento do módulo (não por instância), o que pode tornar testes frágeis se o ano mockado diferir do ano real. |
| src/components/InternalComponents/YearSelectorGrid.vue | Adicionado import de Luxon e todayYear passou a usar DateTime.now().year. Por estar dentro do setup(), é avaliado por instância e respeita corretamente o mock de Settings.now nos testes. |
| src/tests/SelectorGridHighlight.spec.js | Adicionado mock de Settings.now do Luxon no beforeEach e limpeza no afterEach. Garante que tanto vi.useFakeTimers quanto DateTime.now() utilizem a data mockada durante os testes. |
| src/utils/constants/inputTypes.js | Adicionado 'date' à lista de tipos válidos de input, eliminando o aviso de validação de prop quando DateInput.vue passa type="date" para BaseInput.vue. |
| src/components/InlineDateInput.vue | Alterado new Date() para DateTime.now().toJSDate() no atributo dates do data(). Padroniza o uso de Luxon e permite que Settings.now funcione como mock nos testes. |
| package.json | Bump de versão: 3.154.11 → 3.154.12 (alteração também refletida no package-lock.json). |
Sequence Diagram
sequenceDiagram
participant TF as Test File
participant VT as Vitest
participant LX as Luxon Settings
participant MC as MonthSelectorGrid
participant YC as YearSelectorGrid
TF->>MC: import (módulo carregado)
Note over MC: DateTime.now().year avaliado<br/>em tempo de módulo (2026)
TF->>YC: import (módulo carregado)
loop beforeEach (cada teste)
TF->>VT: vi.useFakeTimers()
TF->>VT: vi.setSystemTime(new Date(2026, 1, 10))
TF->>LX: Settings.now = () => mockDate.getTime()
end
TF->>MC: mount(MonthSelectorGrid, props)
Note over MC: defineProps default já fixado<br/>em 2026 (módulo-level)
TF->>YC: mount(YearSelectorGrid, props)
Note over YC: setup() executa → DateTime.now().year<br/>avaliado por instância → responde ao mock
loop afterEach (cada teste)
TF->>VT: vi.useRealTimers()
TF->>LX: Settings.now = () => Date.now()
end
Last reviewed commit: 80e146a
| year: { | ||
| type: Number, | ||
| default: new Date().getFullYear(), | ||
| default: DateTime.now().year, |
There was a problem hiding this comment.
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:
| default: DateTime.now().year, | |
| default: () => DateTime.now().year, |
Rule Used: What: Components in Vue 3 must adhere to the speci... (source)
Fixed failing unit tests for the DateInput component by improving date mocking, standardizing date handling across components, and resolving prop validation and Vue warnings.
PR created automatically by Jules for task 16465431169864620625 started by @lucasn4s