-
Notifications
You must be signed in to change notification settings - Fork 39
feat(atomic): migrate atomic-timeframe to Lit #6793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1153252
Initial plan
Copilot 942fb1b
feat(atomic): migrate atomic-timeframe component to Lit
Copilot 515802f
test(atomic): add comprehensive unit tests for atomic-timeframe
Copilot d4acc8c
docs(atomic): add MDX documentation for atomic-timeframe
Copilot ad69289
chore(atomic): update auto-generated files for atomic-timeframe
Copilot 9df4a0e
Merge branch 'main' into copilot/migrate-atomic-timeframe
fbeaudoincoveo 245d2ea
Add generated files
developer-experience-bot[bot] c0ddb31
refactor(atomic): add validation and error handling to atomic-timeframe
Copilot 0cc8621
refactor(atomic): improve atomic-timeframe tests and JSDoc
Copilot 5f1568d
Merge branch 'main' into copilot/migrate-atomic-timeframe
fbeaudoincoveo 5f31800
Add generated files
developer-experience-bot[bot] 070e914
reorder atomic-timeframe import in lazy-index
fbeaudoincoveo 814d35d
Merge branch 'copilot/migrate-atomic-timeframe' of https://github.comβ¦
fbeaudoincoveo 5df4a32
Improve typing
fbeaudoincoveo ee47f5e
Update comments in atomic-timeframe component for clarity
fbeaudoincoveo 6b41383
refactor(atomic): add MSW API mocking to atomic-timeframe stories
Copilot 82eeb11
Fix stories
fbeaudoincoveo 92a9d2a
Update docs
fbeaudoincoveo 19bd431
Merge branch 'main' into copilot/migrate-atomic-timeframe
fbeaudoincoveo 8c80d46
Commit generated files
fbeaudoincoveo d36076a
refactor(atomic): simplify period test to create element with desiredβ¦
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/atomic/src/components/common/atomic-timeframe/atomic-timeframe.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { Meta } from '@storybook/addon-docs/blocks'; | ||
| import * as AtomicTimeframeStories from './atomic-timeframe.new.stories'; | ||
| import { AtomicDocTemplate } from '@/storybook-utils/documentation/atomic-doc-template'; | ||
|
|
||
|
|
||
| <Meta of={AtomicTimeframeStories} /> | ||
|
|
||
| <AtomicDocTemplate | ||
| stories={AtomicTimeframeStories} | ||
| githubPath="common/atomic-timeframe/atomic-timeframe.ts" | ||
| tagName="atomic-timeframe" | ||
| className="AtomicTimeframe" | ||
| > | ||
|
|
||
| ## Usage | ||
|
|
||
| The `atomic-timeframe` component defines a timeframe for an `atomic-timeframe-facet` component. It must be defined within an `atomic-timeframe-facet` component to function properly. | ||
|
|
||
| A timeframe represents a span of time from now to a specific time in the past (or future). | ||
|
|
||
| ### Basic Example | ||
|
|
||
| ```html | ||
| <atomic-timeframe-facet field="date"> | ||
| <atomic-timeframe unit="day"></atomic-timeframe> | ||
| <atomic-timeframe unit="week"></atomic-timeframe> | ||
| <atomic-timeframe unit="month"></atomic-timeframe> | ||
| <atomic-timeframe unit="year"></atomic-timeframe> | ||
| </atomic-timeframe-facet> | ||
| ``` | ||
|
|
||
| ### With Custom Amounts | ||
|
|
||
| ```html | ||
| <atomic-timeframe-facet field="date"> | ||
| <atomic-timeframe unit="day" amount="7" label="Last week"></atomic-timeframe> | ||
| <atomic-timeframe unit="month" amount="3" label="Last quarter"></atomic-timeframe> | ||
| <atomic-timeframe unit="year" amount="1" label="Last year"></atomic-timeframe> | ||
| </atomic-timeframe-facet> | ||
| ``` | ||
|
|
||
| ### Future Timeframes | ||
|
|
||
| ```html | ||
| <atomic-timeframe-facet field="date"> | ||
| <atomic-timeframe period="next" unit="day" amount="7" label="Next week"></atomic-timeframe> | ||
| <atomic-timeframe period="next" unit="month" label="Next month"></atomic-timeframe> | ||
| </atomic-timeframe-facet> | ||
| ``` | ||
|
|
||
| ## Related Components | ||
|
|
||
| - [atomic-timeframe-facet](../?path=/docs/atomic-timeframe-facet--default) - Search timeframe facet | ||
| - [atomic-commerce-timeframe-facet](../?path=/docs/atomic-commerce-timeframe-facet--default) - Commerce timeframe facet | ||
| - [atomic-insight-timeframe-facet](../?path=/docs/atomic-insight-timeframe-facet--default) - Insight timeframe facet | ||
|
|
||
| </AtomicDocTemplate> |
144 changes: 144 additions & 0 deletions
144
packages/atomic/src/components/common/atomic-timeframe/atomic-timeframe.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import {html} from 'lit'; | ||
| import {describe, expect, it} from 'vitest'; | ||
| import {renderFunctionFixture} from '@/vitest-utils/testing-helpers/fixture'; | ||
| import type {AtomicTimeframe} from './atomic-timeframe'; | ||
| import './atomic-timeframe'; | ||
|
|
||
| describe('atomic-timeframe', () => { | ||
| const renderTimeframe = async ({ | ||
| period = 'past', | ||
| unit = 'day', | ||
| amount = 1, | ||
| label, | ||
| }: { | ||
| period?: 'past' | 'next'; | ||
| unit?: string; | ||
| amount?: number; | ||
| label?: string; | ||
| } = {}) => { | ||
| const element = await renderFunctionFixture(html` | ||
| <atomic-timeframe | ||
| period=${period} | ||
| unit=${unit} | ||
| amount=${amount} | ||
| label=${label ?? ''} | ||
| ></atomic-timeframe> | ||
| `); | ||
|
|
||
| const timeframe = element.querySelector( | ||
| 'atomic-timeframe' | ||
| ) as AtomicTimeframe; | ||
|
|
||
| return {element, timeframe}; | ||
| }; | ||
|
|
||
| describe('default properties', () => { | ||
| it('should have default period of "past"', async () => { | ||
| const {timeframe} = await renderTimeframe(); | ||
| expect(timeframe.period).toBe('past'); | ||
| }); | ||
|
|
||
| it('should have default amount of 1', async () => { | ||
| const {timeframe} = await renderTimeframe(); | ||
| expect(timeframe.amount).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when setting period', () => { | ||
| it('should set period to "past"', async () => { | ||
| const {timeframe} = await renderTimeframe({period: 'past'}); | ||
| expect(timeframe.period).toBe('past'); | ||
| }); | ||
|
|
||
| it('should set period to "next"', async () => { | ||
| const {timeframe} = await renderTimeframe({period: 'next'}); | ||
| expect(timeframe.period).toBe('next'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when setting unit', () => { | ||
| it('should set unit to "day"', async () => { | ||
| const {timeframe} = await renderTimeframe({unit: 'day'}); | ||
| expect(timeframe.unit).toBe('day'); | ||
| }); | ||
|
|
||
| it('should set unit to "month"', async () => { | ||
| const {timeframe} = await renderTimeframe({unit: 'month'}); | ||
| expect(timeframe.unit).toBe('month'); | ||
| }); | ||
|
|
||
| it('should set unit to "year"', async () => { | ||
| const {timeframe} = await renderTimeframe({unit: 'year'}); | ||
| expect(timeframe.unit).toBe('year'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when setting amount', () => { | ||
| it('should set amount to 1', async () => { | ||
| const {timeframe} = await renderTimeframe({amount: 1}); | ||
| expect(timeframe.amount).toBe(1); | ||
| }); | ||
|
|
||
| it('should set amount to 10', async () => { | ||
| const {timeframe} = await renderTimeframe({amount: 10}); | ||
| expect(timeframe.amount).toBe(10); | ||
| }); | ||
|
|
||
| it('should set amount to 365', async () => { | ||
| const {timeframe} = await renderTimeframe({amount: 365}); | ||
| expect(timeframe.amount).toBe(365); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when setting label', () => { | ||
| it('should set custom label', async () => { | ||
| const label = 'Last month'; | ||
| const {timeframe} = await renderTimeframe({label}); | ||
| expect(timeframe.label).toBe(label); | ||
| }); | ||
|
|
||
| it('should set label to "Past year"', async () => { | ||
| const label = 'Past year'; | ||
| const {timeframe} = await renderTimeframe({label}); | ||
| expect(timeframe.label).toBe(label); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Timeframe interface implementation', () => { | ||
| it('should implement all Timeframe interface properties', async () => { | ||
| const {timeframe} = await renderTimeframe({ | ||
| period: 'past', | ||
| unit: 'month', | ||
| amount: 3, | ||
| label: 'Last quarter', | ||
| }); | ||
|
|
||
| expect(timeframe).toHaveProperty('period'); | ||
| expect(timeframe).toHaveProperty('unit'); | ||
| expect(timeframe).toHaveProperty('amount'); | ||
| expect(timeframe).toHaveProperty('label'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('property reflection', () => { | ||
| it('should reflect period attribute', async () => { | ||
| const {timeframe} = await renderTimeframe({period: 'next'}); | ||
| expect(timeframe.getAttribute('period')).toBe('next'); | ||
| }); | ||
|
|
||
| it('should reflect unit attribute', async () => { | ||
| const {timeframe} = await renderTimeframe({unit: 'week'}); | ||
| expect(timeframe.getAttribute('unit')).toBe('week'); | ||
| }); | ||
|
|
||
| it('should reflect amount attribute', async () => { | ||
| const {timeframe} = await renderTimeframe({amount: 7}); | ||
| expect(timeframe.getAttribute('amount')).toBe('7'); | ||
| }); | ||
|
|
||
| it('should reflect label attribute when set', async () => { | ||
| const {timeframe} = await renderTimeframe({label: 'Custom Label'}); | ||
| expect(timeframe.getAttribute('label')).toBe('Custom Label'); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.