-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Update comments for clarity and add tests for date formatti…
…ng functions
- Loading branch information
1 parent
4f494e5
commit c7bece8
Showing
5 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,37 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import TimeZoneToggle from '../TimeZoneToggle.react'; | ||
|
||
describe('TimeZoneToggle', () => { | ||
it('should render UTC text when value is false', () => { | ||
const wrapper = mount(<TimeZoneToggle value={false} onChange={() => {}} />); | ||
expect(wrapper.find('.option').text()).toBe('UTC'); | ||
expect(wrapper.find('.switch').hasClass('left')).toBe(true); | ||
}); | ||
|
||
it('should render Local text when value is true', () => { | ||
const wrapper = mount(<TimeZoneToggle value={true} onChange={() => {}} />); | ||
expect(wrapper.find('.option').text()).toBe('Local'); | ||
expect(wrapper.find('.switch').hasClass('right')).toBe(true); | ||
}); | ||
|
||
it('should call onChange with opposite value when clicked', () => { | ||
const onChange = jest.fn(); | ||
const wrapper = mount(<TimeZoneToggle value={false} onChange={onChange} />); | ||
|
||
wrapper.find('.container').simulate('click'); | ||
expect(onChange).toHaveBeenCalledWith(true); | ||
|
||
wrapper.setProps({ value: true }); | ||
wrapper.find('.container').simulate('click'); | ||
expect(onChange).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('should have correct background color based on value', () => { | ||
const wrapper = mount(<TimeZoneToggle value={false} onChange={() => {}} />); | ||
expect(wrapper.find('.switch').prop('style').backgroundColor).toBe('rgb(204, 204, 204)'); | ||
|
||
wrapper.setProps({ value: true }); | ||
expect(wrapper.find('.switch').prop('style').backgroundColor).toBe('rgb(0, 219, 124)'); | ||
}); | ||
}); |
This file contains 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,39 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import DataBrowser from '../DataBrowser.react'; | ||
|
||
describe('DataBrowser TimeZone Feature', () => { | ||
let wrapper; | ||
const mockLocalStorage = { | ||
getItem: jest.fn(), | ||
setItem: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
global.localStorage = mockLocalStorage; | ||
}); | ||
|
||
it('should initialize with stored timezone preference', () => { | ||
mockLocalStorage.getItem.mockReturnValue('true'); | ||
wrapper = mount(<DataBrowser {...defaultProps} />); | ||
expect(wrapper.state().useLocalTime).toBe(true); | ||
}); | ||
|
||
it('should toggle timezone and save preference', () => { | ||
wrapper = mount(<DataBrowser {...defaultProps} />); | ||
|
||
wrapper.instance().toggleTimeZone(); | ||
expect(mockLocalStorage.setItem).toHaveBeenCalledWith( | ||
'parse_dashboard_useLocalTime', | ||
'true' | ||
); | ||
expect(wrapper.state().useLocalTime).toBe(true); | ||
|
||
wrapper.instance().toggleTimeZone(); | ||
expect(mockLocalStorage.setItem).toHaveBeenCalledWith( | ||
'parse_dashboard_useLocalTime', | ||
'false' | ||
); | ||
expect(wrapper.state().useLocalTime).toBe(false); | ||
}); | ||
}); |
This file contains 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 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