-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: testing quick order, istanbul install (#752)
* feat: testing quick order, istanbul install * fix: reducing to one omounted test * fix: render testing * fix: lint * style: separating mock info
- Loading branch information
Showing
7 changed files
with
310 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vitest.config.ts |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { format, subDays } from 'date-fns' | ||
|
||
const distanceDay = (distanceDay = 0, dateFormat = 'yyyy-MM-dd'): string => | ||
format(subDays(new Date(), distanceDay), dateFormat) | ||
const distanceDay = (_distanceDay = 0, dateFormat = 'yyyy-MM-dd'): string => | ||
format(subDays(new Date(), _distanceDay), dateFormat) | ||
|
||
export default distanceDay |
44 changes: 44 additions & 0 deletions
44
apps/storefront/tests/components/quickOrder/QuickOrder.test.tsx
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,44 @@ | ||
import { beforeEach, describe, it, vi } from 'vitest' | ||
|
||
import { ThemeFrame } from '@/components' | ||
import Quickorder from '@/pages/quickorder/Quickorder' | ||
import { GlobalProvider } from '@/shared/global' | ||
import global from '@/store/slices/global' | ||
import theme from '@/store/slices/theme' | ||
|
||
import { renderWithProviders } from '../../test-utils' | ||
|
||
import { mockActiveCurrency, mockCurrencies } from './mock' | ||
|
||
vi.mock('react-intl', () => ({ | ||
useIntl: vi.fn(() => ({ formatMessage: vi.fn() })), | ||
})) | ||
|
||
vi.mock('react-router-dom', () => ({ | ||
useNavigate: vi.fn(), | ||
})) | ||
|
||
vi.mock('date-fns', () => ({ | ||
format: vi.fn(), | ||
subDays: vi.fn(), | ||
})) | ||
|
||
describe('Quickorder component', () => { | ||
beforeEach(() => { | ||
window.sessionStorage.setItem('sf-activeCurrency', mockActiveCurrency) | ||
window.sessionStorage.setItem('sf-currencies', mockCurrencies) | ||
}) | ||
|
||
it('renders correctly', () => { | ||
renderWithProviders( | ||
<GlobalProvider> | ||
<ThemeFrame title="test-frame"> | ||
<Quickorder /> | ||
</ThemeFrame> | ||
</GlobalProvider>, | ||
{ | ||
reducers: { global, theme }, | ||
} | ||
) | ||
}) | ||
}) |
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,57 @@ | ||
export const mockActiveCurrency = '{ "node": {"entityId": 2, "isActive": true}}' | ||
|
||
export const mockCurrencies = `{ "currencies": [{ | ||
"auto_update": false, | ||
"country_iso2": "CA", | ||
"currency_code": "CAD", | ||
"currency_exchange_rate": "1.25", | ||
"decimal_places": 2, | ||
"decimal_token": ".", | ||
"default_for_country_codes": ["CA"], | ||
"enabled": true, | ||
"id": "2", | ||
"is_default": true, | ||
"is_transactional": true, | ||
"last_updated": "2023-01-01", | ||
"name": "Canadian Dollar", | ||
"thousands_token": ",", | ||
"token": "$", | ||
"token_location": "left" | ||
}, | ||
{ | ||
"auto_update": true, | ||
"country_iso2": "GB", | ||
"currency_code": "GBP", | ||
"currency_exchange_rate": "0.75", | ||
"decimal_places": 2, | ||
"decimal_token": ".", | ||
"default_for_country_codes": ["GB"], | ||
"enabled": true, | ||
"id": "3", | ||
"is_default": false, | ||
"is_transactional": true, | ||
"last_updated": "2023-01-01", | ||
"name": "British Pound Sterling", | ||
"thousands_token": ",", | ||
"token": "£", | ||
"token_location": "left" | ||
}, | ||
{ | ||
"auto_update": true, | ||
"country_iso2": "JP", | ||
"currency_code": "JPY", | ||
"currency_exchange_rate": "110", | ||
"decimal_places": 0, | ||
"decimal_token": "", | ||
"default_for_country_codes": ["JP"], | ||
"enabled": true, | ||
"id": "4", | ||
"is_default": false, | ||
"is_transactional": true, | ||
"last_updated": "2023-01-01", | ||
"name": "Japanese Yen", | ||
"thousands_token": ",", | ||
"token": "¥", | ||
"token_location": "left" | ||
} | ||
]}` |
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
Oops, something went wrong.