@oanda/labs-spread-cost-calculator-widget 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/codegen.ts +15 -0
- package/dist/main/SpreadCostCalculatorWidget/Main.js +115 -0
- package/dist/main/SpreadCostCalculatorWidget/Main.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.js +54 -0
- package/dist/main/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/ValidationWrapper.js +46 -0
- package/dist/main/SpreadCostCalculatorWidget/ValidationWrapper.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/constant.js +8 -0
- package/dist/main/SpreadCostCalculatorWidget/constant.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/index.js +28 -0
- package/dist/main/SpreadCostCalculatorWidget/index.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/render.js +51 -0
- package/dist/main/SpreadCostCalculatorWidget/render.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/types.js +6 -0
- package/dist/main/SpreadCostCalculatorWidget/types.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/useCalculateSpread.js +24 -0
- package/dist/main/SpreadCostCalculatorWidget/useCalculateSpread.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/useInstrumentChange.js +51 -0
- package/dist/main/SpreadCostCalculatorWidget/useInstrumentChange.js.map +1 -0
- package/dist/main/SpreadCostCalculatorWidget/utils.js +17 -0
- package/dist/main/SpreadCostCalculatorWidget/utils.js.map +1 -0
- package/dist/main/gql/types/fragment-masking.js +23 -0
- package/dist/main/gql/types/fragment-masking.js.map +1 -0
- package/dist/main/gql/types/gql.js +16 -0
- package/dist/main/gql/types/gql.js.map +1 -0
- package/dist/main/gql/types/graphql.js +223 -0
- package/dist/main/gql/types/graphql.js.map +1 -0
- package/dist/main/gql/types/index.js +28 -0
- package/dist/main/gql/types/index.js.map +1 -0
- package/dist/main/gql/validateInstruments.js +16 -0
- package/dist/main/gql/validateInstruments.js.map +1 -0
- package/dist/main/index.js +28 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/translations/index.js +27 -0
- package/dist/main/translations/index.js.map +1 -0
- package/dist/main/translations/sources/en.json +11 -0
- package/dist/main/translations/sources/es.json +11 -0
- package/dist/main/translations/sources/th.json +11 -0
- package/dist/main/translations/sources/zh_TW.json +11 -0
- package/dist/main/translations/translations.js +8 -0
- package/dist/main/translations/translations.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/Main.js +107 -0
- package/dist/module/SpreadCostCalculatorWidget/Main.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.js +46 -0
- package/dist/module/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/ValidationWrapper.js +38 -0
- package/dist/module/SpreadCostCalculatorWidget/ValidationWrapper.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/constant.js +2 -0
- package/dist/module/SpreadCostCalculatorWidget/constant.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/index.js +3 -0
- package/dist/module/SpreadCostCalculatorWidget/index.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/render.js +48 -0
- package/dist/module/SpreadCostCalculatorWidget/render.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/types.js +2 -0
- package/dist/module/SpreadCostCalculatorWidget/types.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/useCalculateSpread.js +17 -0
- package/dist/module/SpreadCostCalculatorWidget/useCalculateSpread.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/useInstrumentChange.js +44 -0
- package/dist/module/SpreadCostCalculatorWidget/useInstrumentChange.js.map +1 -0
- package/dist/module/SpreadCostCalculatorWidget/utils.js +10 -0
- package/dist/module/SpreadCostCalculatorWidget/utils.js.map +1 -0
- package/dist/module/gql/types/fragment-masking.js +15 -0
- package/dist/module/gql/types/fragment-masking.js.map +1 -0
- package/dist/module/gql/types/gql.js +8 -0
- package/dist/module/gql/types/gql.js.map +1 -0
- package/dist/module/gql/types/graphql.js +217 -0
- package/dist/module/gql/types/graphql.js.map +1 -0
- package/dist/module/gql/types/index.js +3 -0
- package/dist/module/gql/types/index.js.map +1 -0
- package/dist/module/gql/validateInstruments.js +10 -0
- package/dist/module/gql/validateInstruments.js.map +1 -0
- package/dist/module/index.js +3 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/translations/index.js +20 -0
- package/dist/module/translations/index.js.map +1 -0
- package/dist/module/translations/sources/en.json +11 -0
- package/dist/module/translations/sources/es.json +11 -0
- package/dist/module/translations/sources/th.json +11 -0
- package/dist/module/translations/sources/zh_TW.json +11 -0
- package/dist/module/translations/translations.js +2 -0
- package/dist/module/translations/translations.js.map +1 -0
- package/dist/types/SpreadCostCalculatorWidget/Main.d.ts +4 -0
- package/dist/types/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.d.ts +4 -0
- package/dist/types/SpreadCostCalculatorWidget/ValidationWrapper.d.ts +4 -0
- package/dist/types/SpreadCostCalculatorWidget/constant.d.ts +1 -0
- package/dist/types/SpreadCostCalculatorWidget/index.d.ts +2 -0
- package/dist/types/SpreadCostCalculatorWidget/render.d.ts +1 -0
- package/dist/types/SpreadCostCalculatorWidget/types.d.ts +20 -0
- package/dist/types/SpreadCostCalculatorWidget/useCalculateSpread.d.ts +8 -0
- package/dist/types/SpreadCostCalculatorWidget/useInstrumentChange.d.ts +12 -0
- package/dist/types/SpreadCostCalculatorWidget/utils.d.ts +2 -0
- package/dist/types/gql/types/fragment-masking.d.ts +15 -0
- package/dist/types/gql/types/gql.d.ts +37 -0
- package/dist/types/gql/types/graphql.d.ts +389 -0
- package/dist/types/gql/types/index.d.ts +2 -0
- package/dist/types/gql/validateInstruments.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/translations/index.d.ts +4 -0
- package/dist/types/translations/translations.d.ts +1 -0
- package/index.ts +1 -0
- package/lokalise.config.json +18 -0
- package/package.json +26 -0
- package/src/SpreadCostCalculatorWidget/Main.tsx +138 -0
- package/src/SpreadCostCalculatorWidget/SpreadCostCalculatorWidget.tsx +52 -0
- package/src/SpreadCostCalculatorWidget/ValidationWrapper.tsx +51 -0
- package/src/SpreadCostCalculatorWidget/constant.ts +1 -0
- package/src/SpreadCostCalculatorWidget/index.ts +2 -0
- package/src/SpreadCostCalculatorWidget/render.tsx +60 -0
- package/src/SpreadCostCalculatorWidget/types.ts +27 -0
- package/src/SpreadCostCalculatorWidget/useCalculateSpread.ts +38 -0
- package/src/SpreadCostCalculatorWidget/useInstrumentChange.ts +47 -0
- package/src/SpreadCostCalculatorWidget/utils.ts +12 -0
- package/src/gql/types/fragment-masking.ts +66 -0
- package/src/gql/types/gql.ts +42 -0
- package/src/gql/types/graphql.ts +430 -0
- package/src/gql/types/index.ts +2 -0
- package/src/gql/validateInstruments.ts +10 -0
- package/src/index.ts +2 -0
- package/src/translations/index.ts +17 -0
- package/src/translations/sources/en.json +11 -0
- package/src/translations/sources/es.json +11 -0
- package/src/translations/sources/th.json +11 -0
- package/src/translations/sources/zh_TW.json +11 -0
- package/src/translations/translations.ts +1 -0
- package/test/SpreadCostCalculator.test.tsx +31 -0
- package/test/useCalculateSpread.test.tsx +131 -0
- package/test/useInstrumentChange.test.tsx +54 -0
- package/tsconfig.types.json +12 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { renderHook } from '@testing-library/react';
|
|
6
|
+
import { useLiveRatesMessage, useLiveRatesQuery } from '@oanda/labs-widget-common';
|
|
7
|
+
import { useInstrumentChange } from '../src/SpreadCostCalculatorWidget/useInstrumentChange';
|
|
8
|
+
|
|
9
|
+
jest.mock('@oanda/labs-widget-common', () => ({
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
...jest.requireActual('@oanda/labs-widget-common'),
|
|
12
|
+
useLiveRatesQuery: jest.fn(),
|
|
13
|
+
useLiveRatesMessage: jest.fn(),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
describe('useInstrumentChange', () => {
|
|
17
|
+
const initialInstrument = { id: 'ABC_XYZ', label: 'ABC/XYZ' };
|
|
18
|
+
|
|
19
|
+
it('should initialize with the initial instrument and fetch live rates', () => {
|
|
20
|
+
(useLiveRatesQuery as jest.Mock).mockReturnValue({
|
|
21
|
+
target: 'target',
|
|
22
|
+
setQuery: jest.fn(),
|
|
23
|
+
closeQuery: jest.fn(),
|
|
24
|
+
});
|
|
25
|
+
(useLiveRatesMessage as jest.Mock).mockReturnValue({
|
|
26
|
+
update: undefined,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const { result } = renderHook(() => useInstrumentChange({ initialInstrument }));
|
|
30
|
+
|
|
31
|
+
expect(result.current.selectedInstrument).toEqual(initialInstrument);
|
|
32
|
+
expect(result.current.pipLocation).toBe(undefined);
|
|
33
|
+
expect(result.current.initialSpread).toBe(undefined);
|
|
34
|
+
expect(useLiveRatesQuery).toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should update pipLocation and spread when live rates update', () => {
|
|
38
|
+
const setQueryMock = jest.fn();
|
|
39
|
+
(useLiveRatesQuery as jest.Mock).mockReturnValue({
|
|
40
|
+
target: 'target',
|
|
41
|
+
setQuery: setQueryMock,
|
|
42
|
+
closeQuery: jest.fn(),
|
|
43
|
+
});
|
|
44
|
+
const updateMock = { symbol: 'ABC_XYZ', pipLocation: -4, spread: 1.2 };
|
|
45
|
+
(useLiveRatesMessage as jest.Mock).mockReturnValue({
|
|
46
|
+
update: updateMock,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const { result } = renderHook(() => useInstrumentChange({ initialInstrument }));
|
|
50
|
+
|
|
51
|
+
expect(result.current.pipLocation).toBe(-4);
|
|
52
|
+
expect(result.current.initialSpread).toBe(1.2);
|
|
53
|
+
});
|
|
54
|
+
});
|