@oanda/labs-instrument-live-rate-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.
Files changed (155) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/codegen.ts +15 -0
  3. package/dist/main/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js +56 -0
  4. package/dist/main/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js.map +1 -0
  5. package/dist/main/InstrumentLiveRateWidget/Main.js +77 -0
  6. package/dist/main/InstrumentLiveRateWidget/Main.js.map +1 -0
  7. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.js +83 -0
  8. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.js.map +1 -0
  9. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.js +28 -0
  10. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.js.map +1 -0
  11. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.js +25 -0
  12. package/dist/main/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.js.map +1 -0
  13. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js +44 -0
  14. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js.map +1 -0
  15. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/index.js +17 -0
  16. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/index.js.map +1 -0
  17. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/types.js +6 -0
  18. package/dist/main/InstrumentLiveRateWidget/components/LineChartWithData/types.js.map +1 -0
  19. package/dist/main/InstrumentLiveRateWidget/components/index.js +17 -0
  20. package/dist/main/InstrumentLiveRateWidget/components/index.js.map +1 -0
  21. package/dist/main/InstrumentLiveRateWidget/constant.js +8 -0
  22. package/dist/main/InstrumentLiveRateWidget/constant.js.map +1 -0
  23. package/dist/main/InstrumentLiveRateWidget/render.js +51 -0
  24. package/dist/main/InstrumentLiveRateWidget/render.js.map +1 -0
  25. package/dist/main/InstrumentLiveRateWidget/types.js +20 -0
  26. package/dist/main/InstrumentLiveRateWidget/types.js.map +1 -0
  27. package/dist/main/InstrumentLiveRateWidget/utils.js +43 -0
  28. package/dist/main/InstrumentLiveRateWidget/utils.js.map +1 -0
  29. package/dist/main/gql/getInstrumentsChart.js +16 -0
  30. package/dist/main/gql/getInstrumentsChart.js.map +1 -0
  31. package/dist/main/gql/types/fragment-masking.js +23 -0
  32. package/dist/main/gql/types/fragment-masking.js.map +1 -0
  33. package/dist/main/gql/types/gql.js +17 -0
  34. package/dist/main/gql/types/gql.js.map +1 -0
  35. package/dist/main/gql/types/graphql.js +326 -0
  36. package/dist/main/gql/types/graphql.js.map +1 -0
  37. package/dist/main/gql/types/index.js +28 -0
  38. package/dist/main/gql/types/index.js.map +1 -0
  39. package/dist/main/gql/validateInstruments.js +16 -0
  40. package/dist/main/gql/validateInstruments.js.map +1 -0
  41. package/dist/main/index.js +28 -0
  42. package/dist/main/index.js.map +1 -0
  43. package/dist/main/translations/index.js +27 -0
  44. package/dist/main/translations/index.js.map +1 -0
  45. package/dist/main/translations/sources/en.json +4 -0
  46. package/dist/main/translations/sources/es.json +4 -0
  47. package/dist/main/translations/sources/th.json +4 -0
  48. package/dist/main/translations/sources/zh_TW.json +4 -0
  49. package/dist/main/translations/translations.js +11 -0
  50. package/dist/main/translations/translations.js.map +1 -0
  51. package/dist/module/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js +49 -0
  52. package/dist/module/InstrumentLiveRateWidget/InstrumentLiveRateWidget.js.map +1 -0
  53. package/dist/module/InstrumentLiveRateWidget/Main.js +69 -0
  54. package/dist/module/InstrumentLiveRateWidget/Main.js.map +1 -0
  55. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.js +74 -0
  56. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.js.map +1 -0
  57. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.js +3 -0
  58. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.js.map +1 -0
  59. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.js +18 -0
  60. package/dist/module/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.js.map +1 -0
  61. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js +37 -0
  62. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.js.map +1 -0
  63. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/index.js +2 -0
  64. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/index.js.map +1 -0
  65. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/types.js +2 -0
  66. package/dist/module/InstrumentLiveRateWidget/components/LineChartWithData/types.js.map +1 -0
  67. package/dist/module/InstrumentLiveRateWidget/components/index.js +2 -0
  68. package/dist/module/InstrumentLiveRateWidget/components/index.js.map +1 -0
  69. package/dist/module/InstrumentLiveRateWidget/constant.js +3 -0
  70. package/dist/module/InstrumentLiveRateWidget/constant.js.map +1 -0
  71. package/dist/module/InstrumentLiveRateWidget/render.js +48 -0
  72. package/dist/module/InstrumentLiveRateWidget/render.js.map +1 -0
  73. package/dist/module/InstrumentLiveRateWidget/types.js +3 -0
  74. package/dist/module/InstrumentLiveRateWidget/types.js.map +1 -0
  75. package/dist/module/InstrumentLiveRateWidget/utils.js +36 -0
  76. package/dist/module/InstrumentLiveRateWidget/utils.js.map +1 -0
  77. package/dist/module/gql/getInstrumentsChart.js +10 -0
  78. package/dist/module/gql/getInstrumentsChart.js.map +1 -0
  79. package/dist/module/gql/types/fragment-masking.js +15 -0
  80. package/dist/module/gql/types/fragment-masking.js.map +1 -0
  81. package/dist/module/gql/types/gql.js +9 -0
  82. package/dist/module/gql/types/gql.js.map +1 -0
  83. package/dist/module/gql/types/graphql.js +320 -0
  84. package/dist/module/gql/types/graphql.js.map +1 -0
  85. package/dist/module/gql/types/index.js +3 -0
  86. package/dist/module/gql/types/index.js.map +1 -0
  87. package/dist/module/gql/validateInstruments.js +10 -0
  88. package/dist/module/gql/validateInstruments.js.map +1 -0
  89. package/dist/module/index.js +3 -0
  90. package/dist/module/index.js.map +1 -0
  91. package/dist/module/translations/index.js +20 -0
  92. package/dist/module/translations/index.js.map +1 -0
  93. package/dist/module/translations/sources/en.json +4 -0
  94. package/dist/module/translations/sources/es.json +4 -0
  95. package/dist/module/translations/sources/th.json +4 -0
  96. package/dist/module/translations/sources/zh_TW.json +4 -0
  97. package/dist/module/translations/translations.js +5 -0
  98. package/dist/module/translations/translations.js.map +1 -0
  99. package/dist/types/InstrumentLiveRateWidget/InstrumentLiveRateWidget.d.ts +4 -0
  100. package/dist/types/InstrumentLiveRateWidget/Main.d.ts +4 -0
  101. package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.d.ts +4 -0
  102. package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.d.ts +2 -0
  103. package/dist/types/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.d.ts +3 -0
  104. package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.d.ts +4 -0
  105. package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/index.d.ts +1 -0
  106. package/dist/types/InstrumentLiveRateWidget/components/LineChartWithData/types.d.ts +11 -0
  107. package/dist/types/InstrumentLiveRateWidget/components/index.d.ts +1 -0
  108. package/dist/types/InstrumentLiveRateWidget/constant.d.ts +2 -0
  109. package/dist/types/InstrumentLiveRateWidget/render.d.ts +1 -0
  110. package/dist/types/InstrumentLiveRateWidget/types.d.ts +43 -0
  111. package/dist/types/InstrumentLiveRateWidget/utils.d.ts +12 -0
  112. package/dist/types/gql/getInstrumentsChart.d.ts +1 -0
  113. package/dist/types/gql/types/fragment-masking.d.ts +15 -0
  114. package/dist/types/gql/types/gql.d.ts +45 -0
  115. package/dist/types/gql/types/graphql.d.ts +397 -0
  116. package/dist/types/gql/types/index.d.ts +2 -0
  117. package/dist/types/gql/validateInstruments.d.ts +1 -0
  118. package/dist/types/index.d.ts +2 -0
  119. package/dist/types/translations/index.d.ts +4 -0
  120. package/dist/types/translations/translations.d.ts +4 -0
  121. package/index.ts +1 -0
  122. package/lokalise.config.json +18 -0
  123. package/package.json +25 -0
  124. package/src/InstrumentLiveRateWidget/InstrumentLiveRateWidget.tsx +57 -0
  125. package/src/InstrumentLiveRateWidget/Main.tsx +82 -0
  126. package/src/InstrumentLiveRateWidget/components/InstrumentRateWithData/InstrumentRateWithData.tsx +92 -0
  127. package/src/InstrumentLiveRateWidget/components/InstrumentRateWithData/index.ts +2 -0
  128. package/src/InstrumentLiveRateWidget/components/InstrumentRateWithData/utils.ts +25 -0
  129. package/src/InstrumentLiveRateWidget/components/LineChartWithData/LineChartWithData.tsx +48 -0
  130. package/src/InstrumentLiveRateWidget/components/LineChartWithData/index.ts +1 -0
  131. package/src/InstrumentLiveRateWidget/components/LineChartWithData/types.tsx +12 -0
  132. package/src/InstrumentLiveRateWidget/components/index.ts +1 -0
  133. package/src/InstrumentLiveRateWidget/constant.ts +5 -0
  134. package/src/InstrumentLiveRateWidget/render.tsx +48 -0
  135. package/src/InstrumentLiveRateWidget/types.tsx +50 -0
  136. package/src/InstrumentLiveRateWidget/utils.ts +49 -0
  137. package/src/gql/getInstrumentsChart.ts +10 -0
  138. package/src/gql/types/fragment-masking.ts +66 -0
  139. package/src/gql/types/gql.ts +47 -0
  140. package/src/gql/types/graphql.ts +432 -0
  141. package/src/gql/types/index.ts +2 -0
  142. package/src/gql/validateInstruments.ts +10 -0
  143. package/src/index.ts +2 -0
  144. package/src/translations/index.ts +17 -0
  145. package/src/translations/sources/en.json +4 -0
  146. package/src/translations/sources/es.json +4 -0
  147. package/src/translations/sources/th.json +4 -0
  148. package/src/translations/sources/zh_TW.json +4 -0
  149. package/src/translations/translations.ts +4 -0
  150. package/test/LineChartWithData.test.tsx +164 -0
  151. package/test/Main.test.tsx +27 -0
  152. package/test/components/InstrumentRateWithData.test.tsx +62 -0
  153. package/test/components/utils.test.ts +13 -0
  154. package/test/mocks.ts +52 -0
  155. package/tsconfig.types.json +12 -0
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import React from 'react';
5
+ import { render } from '@testing-library/react';
6
+ import { MockedProvider } from '@apollo/client/testing';
7
+ import { InstrumentRateWithData } from '../../src/InstrumentLiveRateWidget/components/InstrumentRateWithData';
8
+ import { getInstrumentsChart } from '../../src/gql/getInstrumentsChart';
9
+ import { Division } from '../../src/gql/types/graphql';
10
+
11
+ const chartPointsMocks = [
12
+ {
13
+ request: {
14
+ query: getInstrumentsChart,
15
+ variables: {
16
+ instruments: ['EUR_USD'],
17
+ division: 'OC',
18
+ },
19
+ },
20
+ result: {
21
+ data: {
22
+ topicalInstrumentsCharts: [
23
+ {
24
+ name: 'EUR_USD',
25
+ displayName: 'EUR_USD',
26
+ chart: [
27
+ 1.0544, 1.05704, 1.05716, 1.05596, 1.05556, 1.05556, 1.05238,
28
+ 1.05292, 1.05443, 1.0544, 1.05704, 1.05716, 1.05596, 1.05556,
29
+ 1.05556,
30
+ ],
31
+ },
32
+ ],
33
+ },
34
+ },
35
+ },
36
+ ];
37
+
38
+ describe('InstrumentRateWithData component', () => {
39
+ const record = {
40
+ instrument: 'EUR_USD',
41
+ displayName: 'EUR_USD',
42
+ buy: 1.04508,
43
+ dailyPercentChange: '+3,23%',
44
+ dailyPipsChange: 123,
45
+ };
46
+
47
+ it('should render table row', async () => {
48
+ const { getAllByTestId, findByTestId } = render(
49
+ <MockedProvider mocks={chartPointsMocks}>
50
+ <InstrumentRateWithData
51
+ loading={false}
52
+ division={Division.Oc}
53
+ record={record}
54
+ target={null}
55
+ />
56
+ </MockedProvider>,
57
+ );
58
+
59
+ expect(await findByTestId('line-chart')).toBeInTheDocument();
60
+ expect(getAllByTestId('label-wrapper').length).toEqual(4);
61
+ });
62
+ });
@@ -0,0 +1,13 @@
1
+ import { getColorIndicator } from '../../src/InstrumentLiveRateWidget/components/InstrumentRateWithData';
2
+
3
+ describe('getColorIndicator', () => {
4
+ it('should return value greater than 0', () => {
5
+ expect(getColorIndicator('+0.06%')).toEqual(1);
6
+ });
7
+ it('should return value equal to 0', () => {
8
+ expect(getColorIndicator('0%')).toEqual(0);
9
+ });
10
+ it('should return value lower than 0', () => {
11
+ expect(getColorIndicator('-0.20%')).toEqual(-1);
12
+ });
13
+ });
package/test/mocks.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { getInstrumentsChart } from '../src/gql/getInstrumentsChart';
2
+ import { validateInstruments } from '../src/gql/validateInstruments';
3
+
4
+ const widgetMocks = [
5
+ {
6
+ request: {
7
+ query: validateInstruments,
8
+ variables: {
9
+ instruments: ['EUR_USD'],
10
+ division: 'OC',
11
+ },
12
+ },
13
+ result: {
14
+ data: {
15
+ mapInstrumentNames: [
16
+ {
17
+ name: 'EUR_USD',
18
+ displayName: 'EUR/USD',
19
+ },
20
+ ],
21
+ },
22
+ },
23
+ },
24
+ {
25
+ request: {
26
+ query: getInstrumentsChart,
27
+ variables: {
28
+ instruments: ['EUR_USD'],
29
+ division: 'OC',
30
+ },
31
+ },
32
+ result: {
33
+ data: {
34
+ topicalInstrumentsCharts: [
35
+ {
36
+ name: 'EUR_USD',
37
+ displayName: 'EUR/USD',
38
+ chart: [
39
+ 1.0544, 1.05704, 1.05716, 1.05596, 1.05556, 1.05556, 1.05238,
40
+ 1.05292, 1.05443, 1.0544, 1.05704, 1.05716, 1.05596, 1.05556,
41
+ 1.05556,
42
+ ],
43
+ },
44
+ ],
45
+ },
46
+ },
47
+ },
48
+ ];
49
+
50
+ export {
51
+ widgetMocks,
52
+ };
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.types.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist",
6
+ "declarationDir": "./dist/types"
7
+ },
8
+ "include": [
9
+ "./src/**/*",
10
+ "../../types/**/*"
11
+ ]
12
+ }