@oanda/labs-live-rates-table-widget 1.0.49 → 1.0.50

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 (108) hide show
  1. package/CHANGELOG.md +204 -0
  2. package/dist/main/LiveRatesTableWidget/Main.js +26 -33
  3. package/dist/main/LiveRatesTableWidget/Main.js.map +1 -1
  4. package/dist/main/LiveRatesTableWidget/config.js +12 -7
  5. package/dist/main/LiveRatesTableWidget/config.js.map +1 -1
  6. package/dist/main/LiveRatesTableWidget/constant.js +2 -2
  7. package/dist/main/LiveRatesTableWidget/constant.js.map +1 -1
  8. package/dist/main/LiveRatesTableWidget/types.js +0 -10
  9. package/dist/main/LiveRatesTableWidget/types.js.map +1 -1
  10. package/dist/main/LiveRatesTableWidget/utils.js +8 -49
  11. package/dist/main/LiveRatesTableWidget/utils.js.map +1 -1
  12. package/dist/module/LiveRatesTableWidget/Main.js +28 -35
  13. package/dist/module/LiveRatesTableWidget/Main.js.map +1 -1
  14. package/dist/module/LiveRatesTableWidget/config.js +13 -9
  15. package/dist/module/LiveRatesTableWidget/config.js.map +1 -1
  16. package/dist/module/LiveRatesTableWidget/constant.js +2 -2
  17. package/dist/module/LiveRatesTableWidget/constant.js.map +1 -1
  18. package/dist/module/LiveRatesTableWidget/types.js +0 -9
  19. package/dist/module/LiveRatesTableWidget/types.js.map +1 -1
  20. package/dist/module/LiveRatesTableWidget/utils.js +8 -47
  21. package/dist/module/LiveRatesTableWidget/utils.js.map +1 -1
  22. package/dist/types/LiveRatesTableWidget/config.d.ts +9 -28
  23. package/dist/types/LiveRatesTableWidget/constant.d.ts +2 -2
  24. package/dist/types/LiveRatesTableWidget/types.d.ts +6 -47
  25. package/dist/types/LiveRatesTableWidget/utils.d.ts +4 -15
  26. package/package.json +3 -3
  27. package/src/LiveRatesTableWidget/Main.tsx +44 -51
  28. package/src/LiveRatesTableWidget/config.ts +27 -10
  29. package/src/LiveRatesTableWidget/constant.ts +6 -6
  30. package/src/LiveRatesTableWidget/types.tsx +11 -53
  31. package/src/LiveRatesTableWidget/utils.ts +21 -65
  32. package/test/mocks.ts +1 -16
  33. package/dist/main/LiveRatesTableWidget/components/CardWithData/CardWithData.js +0 -96
  34. package/dist/main/LiveRatesTableWidget/components/CardWithData/CardWithData.js.map +0 -1
  35. package/dist/main/LiveRatesTableWidget/components/CardWithData/index.js +0 -17
  36. package/dist/main/LiveRatesTableWidget/components/CardWithData/index.js.map +0 -1
  37. package/dist/main/LiveRatesTableWidget/components/Cards/Cards.js +0 -37
  38. package/dist/main/LiveRatesTableWidget/components/Cards/Cards.js.map +0 -1
  39. package/dist/main/LiveRatesTableWidget/components/Cards/index.js +0 -17
  40. package/dist/main/LiveRatesTableWidget/components/Cards/index.js.map +0 -1
  41. package/dist/main/LiveRatesTableWidget/components/Cards/types.js +0 -6
  42. package/dist/main/LiveRatesTableWidget/components/Cards/types.js.map +0 -1
  43. package/dist/main/LiveRatesTableWidget/components/LineChartWithData/LineChartWithData.js +0 -46
  44. package/dist/main/LiveRatesTableWidget/components/LineChartWithData/LineChartWithData.js.map +0 -1
  45. package/dist/main/LiveRatesTableWidget/components/LineChartWithData/index.js +0 -17
  46. package/dist/main/LiveRatesTableWidget/components/LineChartWithData/index.js.map +0 -1
  47. package/dist/main/LiveRatesTableWidget/components/LineChartWithData/types.js +0 -6
  48. package/dist/main/LiveRatesTableWidget/components/LineChartWithData/types.js.map +0 -1
  49. package/dist/main/LiveRatesTableWidget/components/LineChartWithData/utils.js +0 -20
  50. package/dist/main/LiveRatesTableWidget/components/LineChartWithData/utils.js.map +0 -1
  51. package/dist/main/LiveRatesTableWidget/components/RowWithData/RowWithData.js +0 -104
  52. package/dist/main/LiveRatesTableWidget/components/RowWithData/RowWithData.js.map +0 -1
  53. package/dist/main/LiveRatesTableWidget/components/RowWithData/index.js +0 -17
  54. package/dist/main/LiveRatesTableWidget/components/RowWithData/index.js.map +0 -1
  55. package/dist/main/LiveRatesTableWidget/components/index.js +0 -50
  56. package/dist/main/LiveRatesTableWidget/components/index.js.map +0 -1
  57. package/dist/module/LiveRatesTableWidget/components/CardWithData/CardWithData.js +0 -89
  58. package/dist/module/LiveRatesTableWidget/components/CardWithData/CardWithData.js.map +0 -1
  59. package/dist/module/LiveRatesTableWidget/components/CardWithData/index.js +0 -2
  60. package/dist/module/LiveRatesTableWidget/components/CardWithData/index.js.map +0 -1
  61. package/dist/module/LiveRatesTableWidget/components/Cards/Cards.js +0 -30
  62. package/dist/module/LiveRatesTableWidget/components/Cards/Cards.js.map +0 -1
  63. package/dist/module/LiveRatesTableWidget/components/Cards/index.js +0 -2
  64. package/dist/module/LiveRatesTableWidget/components/Cards/index.js.map +0 -1
  65. package/dist/module/LiveRatesTableWidget/components/Cards/types.js +0 -2
  66. package/dist/module/LiveRatesTableWidget/components/Cards/types.js.map +0 -1
  67. package/dist/module/LiveRatesTableWidget/components/LineChartWithData/LineChartWithData.js +0 -39
  68. package/dist/module/LiveRatesTableWidget/components/LineChartWithData/LineChartWithData.js.map +0 -1
  69. package/dist/module/LiveRatesTableWidget/components/LineChartWithData/index.js +0 -2
  70. package/dist/module/LiveRatesTableWidget/components/LineChartWithData/index.js.map +0 -1
  71. package/dist/module/LiveRatesTableWidget/components/LineChartWithData/types.js +0 -2
  72. package/dist/module/LiveRatesTableWidget/components/LineChartWithData/types.js.map +0 -1
  73. package/dist/module/LiveRatesTableWidget/components/LineChartWithData/utils.js +0 -13
  74. package/dist/module/LiveRatesTableWidget/components/LineChartWithData/utils.js.map +0 -1
  75. package/dist/module/LiveRatesTableWidget/components/RowWithData/RowWithData.js +0 -97
  76. package/dist/module/LiveRatesTableWidget/components/RowWithData/RowWithData.js.map +0 -1
  77. package/dist/module/LiveRatesTableWidget/components/RowWithData/index.js +0 -2
  78. package/dist/module/LiveRatesTableWidget/components/RowWithData/index.js.map +0 -1
  79. package/dist/module/LiveRatesTableWidget/components/index.js +0 -5
  80. package/dist/module/LiveRatesTableWidget/components/index.js.map +0 -1
  81. package/dist/types/LiveRatesTableWidget/components/CardWithData/CardWithData.d.ts +0 -4
  82. package/dist/types/LiveRatesTableWidget/components/CardWithData/index.d.ts +0 -1
  83. package/dist/types/LiveRatesTableWidget/components/Cards/Cards.d.ts +0 -4
  84. package/dist/types/LiveRatesTableWidget/components/Cards/index.d.ts +0 -1
  85. package/dist/types/LiveRatesTableWidget/components/Cards/types.d.ts +0 -12
  86. package/dist/types/LiveRatesTableWidget/components/LineChartWithData/LineChartWithData.d.ts +0 -4
  87. package/dist/types/LiveRatesTableWidget/components/LineChartWithData/index.d.ts +0 -1
  88. package/dist/types/LiveRatesTableWidget/components/LineChartWithData/types.d.ts +0 -11
  89. package/dist/types/LiveRatesTableWidget/components/LineChartWithData/utils.d.ts +0 -1
  90. package/dist/types/LiveRatesTableWidget/components/RowWithData/RowWithData.d.ts +0 -4
  91. package/dist/types/LiveRatesTableWidget/components/RowWithData/index.d.ts +0 -1
  92. package/dist/types/LiveRatesTableWidget/components/index.d.ts +0 -4
  93. package/src/LiveRatesTableWidget/components/CardWithData/CardWithData.tsx +0 -133
  94. package/src/LiveRatesTableWidget/components/CardWithData/index.ts +0 -1
  95. package/src/LiveRatesTableWidget/components/Cards/Cards.tsx +0 -44
  96. package/src/LiveRatesTableWidget/components/Cards/index.ts +0 -1
  97. package/src/LiveRatesTableWidget/components/Cards/types.tsx +0 -13
  98. package/src/LiveRatesTableWidget/components/LineChartWithData/LineChartWithData.tsx +0 -53
  99. package/src/LiveRatesTableWidget/components/LineChartWithData/index.ts +0 -1
  100. package/src/LiveRatesTableWidget/components/LineChartWithData/types.tsx +0 -13
  101. package/src/LiveRatesTableWidget/components/LineChartWithData/utils.ts +0 -14
  102. package/src/LiveRatesTableWidget/components/RowWithData/RowWithData.tsx +0 -150
  103. package/src/LiveRatesTableWidget/components/RowWithData/index.ts +0 -1
  104. package/src/LiveRatesTableWidget/components/index.ts +0 -4
  105. package/test/CardWithData.test.tsx +0 -74
  106. package/test/Cards.test.tsx +0 -130
  107. package/test/LineChartWithData.test.tsx +0 -263
  108. package/test/RowWithData.test.tsx +0 -81
@@ -1,133 +0,0 @@
1
- import {
2
- ArrowPosition,
3
- Card,
4
- CardHeader,
5
- CardRow,
6
- LineChartSize,
7
- Price,
8
- Truncate,
9
- } from '@oanda/labs-widget-common';
10
- import { useLocale } from '@oanda/mono-i18n';
11
- import React from 'react';
12
-
13
- import { INSTRUMENT_TOOLTIP_ID } from '../../constant';
14
- import type { CardWithDataProps } from '../../types';
15
- import { ColumnsNames } from '../../types';
16
- import { useRecords } from '../../utils';
17
- import { LineChartWithData } from '../LineChartWithData';
18
-
19
- const CardWithData = ({
20
- isLoading,
21
- record,
22
- target,
23
- activeColumns,
24
- index,
25
- division,
26
- isLast,
27
- }: CardWithDataProps) => {
28
- const { updatedRecord, error, ref } = useRecords(
29
- record,
30
- record.instrument ? target : null
31
- );
32
- const { lang } = useLocale();
33
-
34
- const checkLoading = (id: string) =>
35
- isLoading || (!error && updatedRecord?.[id] === undefined);
36
-
37
- return (
38
- <Card ref={ref} data-testid="card" withoutBottomBorder={!isLast}>
39
- <CardHeader
40
- isLoading={isLoading}
41
- number={index}
42
- title={
43
- <Truncate
44
- text={record.displayName}
45
- tooltipId={INSTRUMENT_TOOLTIP_ID}
46
- />
47
- }
48
- >
49
- {activeColumns.includes(ColumnsNames.CHART) && (
50
- <LineChartWithData
51
- division={division}
52
- isLoading={checkLoading('instrument')}
53
- padding={4}
54
- record={updatedRecord}
55
- size={LineChartSize.xs}
56
- />
57
- )}
58
- </CardHeader>
59
- {activeColumns.map((item) => {
60
- if (item === ColumnsNames.SELL) {
61
- return (
62
- <CardRow
63
- key={ColumnsNames.SELL}
64
- isError={!!error}
65
- isLoading={checkLoading(ColumnsNames.SELL)}
66
- label={lang('sell_price')}
67
- >
68
- <Price
69
- arrowPosition={ArrowPosition.left}
70
- movementIndicator="arrow"
71
- priceMovement={updatedRecord.sellPriceMovement}
72
- >
73
- <span>
74
- {updatedRecord.sell?.toFixed(updatedRecord.displayPrecision)}
75
- </span>
76
- </Price>
77
- </CardRow>
78
- );
79
- }
80
-
81
- if (item === ColumnsNames.BUY) {
82
- return (
83
- <CardRow
84
- key={ColumnsNames.BUY}
85
- isError={!!error}
86
- isLoading={checkLoading(ColumnsNames.BUY)}
87
- label={lang('buy_price')}
88
- >
89
- <Price
90
- arrowPosition={ArrowPosition.left}
91
- movementIndicator="arrow"
92
- priceMovement={updatedRecord.buyPriceMovement}
93
- >
94
- <span>
95
- {updatedRecord.buy?.toFixed(updatedRecord.displayPrecision)}
96
- </span>
97
- </Price>
98
- </CardRow>
99
- );
100
- }
101
-
102
- if (item === ColumnsNames.DAILY_CHANGE) {
103
- return (
104
- <CardRow
105
- key={ColumnsNames.DAILY_CHANGE}
106
- isError={!!error}
107
- isLoading={checkLoading('dailyPercentChange')}
108
- label={lang('daily_percent_change')}
109
- >
110
- <span>{updatedRecord.dailyPercentChange}</span>
111
- </CardRow>
112
- );
113
- }
114
-
115
- if (item === ColumnsNames.SPREAD) {
116
- return (
117
- <CardRow
118
- key={ColumnsNames.SPREAD}
119
- isError={!!error}
120
- isLoading={checkLoading(ColumnsNames.SPREAD)}
121
- label={lang('spread')}
122
- >
123
- <span>{updatedRecord.spread}</span>
124
- </CardRow>
125
- );
126
- }
127
- return null;
128
- })}
129
- </Card>
130
- );
131
- };
132
-
133
- export { CardWithData };
@@ -1 +0,0 @@
1
- export * from './CardWithData';
@@ -1,44 +0,0 @@
1
- import { Card, ChartError } from '@oanda/labs-widget-common';
2
- import React from 'react';
3
-
4
- import { CardWithData } from '../CardWithData/CardWithData';
5
- import type { CardsProps } from './types';
6
-
7
- const Cards = ({
8
- records,
9
- target,
10
- columns,
11
- isError,
12
- isLoading,
13
- division,
14
- startIndex = 0,
15
- }: CardsProps) => (
16
- <>
17
- {isError ? (
18
- <Card>
19
- <div className="lw-flex lw-h-[150px] lw-w-full lw-items-center lw-justify-center">
20
- <ChartError />
21
- </div>
22
- </Card>
23
- ) : (
24
- <>
25
- {records.map((record, index) => (
26
- <div key={`card_${startIndex + index}`}>
27
- <CardWithData
28
- activeColumns={columns}
29
- division={division}
30
- index={startIndex + index + 1}
31
- isError={isError}
32
- isLast={index + 1 === records.length}
33
- isLoading={isLoading}
34
- record={record}
35
- target={target}
36
- />
37
- </div>
38
- ))}
39
- </>
40
- )}
41
- </>
42
- );
43
-
44
- export { Cards };
@@ -1 +0,0 @@
1
- export * from './Cards';
@@ -1,13 +0,0 @@
1
- import type { Division } from '../../../gql/types/graphql';
2
- import type { ColumnsNames, DataRecord } from '../../types';
3
-
4
- export interface CardsProps {
5
- startIndex?: number;
6
- emptyCardsCount?: number;
7
- isLoading?: boolean;
8
- isError?: boolean;
9
- records: DataRecord[];
10
- target: EventTarget | null;
11
- columns: ColumnsNames[];
12
- division: Division;
13
- }
@@ -1,53 +0,0 @@
1
- import { useQuery } from '@apollo/client';
2
- import { LineChart, Loader, LoaderSize } from '@oanda/labs-widget-common';
3
- import React from 'react';
4
-
5
- import { getInstrumentsChart } from '../../../gql/getInstrumentsChart';
6
- import type {
7
- GetInstrumentsChartQuery,
8
- GetInstrumentsChartQueryVariables,
9
- } from '../../../gql/types/graphql';
10
- import type { LineChartWithDataProps } from './types';
11
- import { getChartColor } from './utils';
12
-
13
- const LineChartWithData = ({
14
- padding,
15
- record,
16
- size,
17
- isLoading,
18
- division,
19
- isDarkMode = false,
20
- }: LineChartWithDataProps) => {
21
- const { loading, data } = useQuery<
22
- GetInstrumentsChartQuery,
23
- GetInstrumentsChartQueryVariables
24
- >(getInstrumentsChart, {
25
- variables: {
26
- instruments: [record.instrument],
27
- division,
28
- },
29
- fetchPolicy: 'network-only',
30
- skip: !record.instrument,
31
- });
32
-
33
- const showLoader = isLoading || loading;
34
- const chart = data?.topicalInstrumentsCharts?.[0].chart || [];
35
-
36
- const chartColor = getChartColor(record.dailyPercentChange, isDarkMode);
37
-
38
- return (
39
- <>
40
- {showLoader && <Loader size={LoaderSize.md} />}
41
- {!showLoader && (
42
- <LineChart
43
- color={chartColor}
44
- data={chart}
45
- padding={padding}
46
- size={size}
47
- />
48
- )}
49
- </>
50
- );
51
- };
52
-
53
- export { LineChartWithData };
@@ -1 +0,0 @@
1
- export * from './LineChartWithData';
@@ -1,13 +0,0 @@
1
- import type { LineChartSize } from '@oanda/labs-widget-common';
2
-
3
- import type { Division } from '../../../gql/types/graphql';
4
- import type { DataRecord } from '../../types';
5
-
6
- export interface LineChartWithDataProps {
7
- padding?: number;
8
- record: DataRecord;
9
- size?: LineChartSize;
10
- isLoading: boolean;
11
- division: Division;
12
- isDarkMode?: boolean;
13
- }
@@ -1,14 +0,0 @@
1
- import { Theme, themeColors } from '@oanda/labs-widget-common';
2
-
3
- export const getChartColor = (dailyChange?: string, isDarkMode?: boolean) => {
4
- const theme = isDarkMode ? Theme.Dark : Theme.Light;
5
-
6
- switch (dailyChange?.charAt(0)) {
7
- case '+':
8
- return themeColors.ok[theme];
9
- case '-':
10
- return themeColors.danger[theme];
11
- default:
12
- return themeColors.borderDisabled[theme];
13
- }
14
- };
@@ -1,150 +0,0 @@
1
- import {
2
- LoaderSize,
3
- Price,
4
- TableCell,
5
- TableRow,
6
- Truncate,
7
- useLayoutProvider,
8
- } from '@oanda/labs-widget-common';
9
- import classnames from 'classnames';
10
- import React from 'react';
11
-
12
- import { INSTRUMENT_TOOLTIP_ID } from '../../constant';
13
- import type { RowWithDataProps } from '../../types';
14
- import { ColumnsNames } from '../../types';
15
- import { useRecords } from '../../utils';
16
- import { LineChartWithData } from '../LineChartWithData';
17
-
18
- const RowWithData = ({
19
- loading,
20
- record,
21
- hasBackgroundColor,
22
- target,
23
- activeColumns,
24
- division,
25
- isScrolled,
26
- }: RowWithDataProps) => {
27
- const { isDark } = useLayoutProvider();
28
- const { updatedRecord, error, ref } = useRecords(
29
- record,
30
- record.instrument ? target : null
31
- );
32
-
33
- const checkLoading = (id: string) =>
34
- loading || (!error && updatedRecord?.[id] === undefined);
35
-
36
- return (
37
- <TableRow
38
- ref={ref}
39
- hasBackgroundColor={hasBackgroundColor}
40
- isScrolled={isScrolled}
41
- >
42
- <>
43
- <TableCell
44
- key={ColumnsNames.INSTRUMENT}
45
- classNames={classnames('lw-font-bold', {
46
- '[&>*:first-child]:lw-border-r [&>*:first-child]:lw-border-border-primary':
47
- isDark && isScrolled,
48
- })}
49
- isLoading={checkLoading(ColumnsNames.INSTRUMENT)}
50
- type="text"
51
- >
52
- <Truncate
53
- maxWidth={130}
54
- text={record.displayName}
55
- tooltipId={INSTRUMENT_TOOLTIP_ID}
56
- />
57
- </TableCell>
58
- {activeColumns.map((item) => {
59
- if (item === ColumnsNames.SELL) {
60
- return (
61
- <TableCell
62
- key={ColumnsNames.SELL}
63
- additionalPaddingRight
64
- isError={!!error}
65
- isLoading={checkLoading(ColumnsNames.SELL)}
66
- >
67
- <Price
68
- movementIndicator="arrow"
69
- priceMovement={updatedRecord.sellPriceMovement}
70
- >
71
- <span>
72
- {updatedRecord.sell?.toFixed(
73
- updatedRecord.displayPrecision
74
- )}
75
- </span>
76
- </Price>
77
- </TableCell>
78
- );
79
- }
80
-
81
- if (item === ColumnsNames.BUY) {
82
- return (
83
- <TableCell
84
- key={ColumnsNames.BUY}
85
- additionalPaddingRight
86
- isError={!!error}
87
- isLoading={checkLoading(ColumnsNames.BUY)}
88
- >
89
- <Price
90
- movementIndicator="arrow"
91
- priceMovement={updatedRecord.buyPriceMovement}
92
- >
93
- <span>
94
- {updatedRecord.buy?.toFixed(updatedRecord.displayPrecision)}
95
- </span>
96
- </Price>
97
- </TableCell>
98
- );
99
- }
100
-
101
- if (item === ColumnsNames.DAILY_CHANGE) {
102
- return (
103
- <TableCell
104
- key={ColumnsNames.DAILY_CHANGE}
105
- isError={!!error}
106
- isLoading={checkLoading('dailyPercentChange')}
107
- >
108
- <span>{updatedRecord.dailyPercentChange}</span>
109
- </TableCell>
110
- );
111
- }
112
-
113
- if (item === ColumnsNames.CHART) {
114
- return (
115
- <td
116
- key={ColumnsNames.CHART}
117
- className="lw-relative lw-px-3 lw-py-0 lw-text-right"
118
- data-testid="chart-table-cell"
119
- >
120
- <div className="lw-flex lw-justify-center">
121
- <LineChartWithData
122
- division={division}
123
- isLoading={checkLoading('instrument')}
124
- record={updatedRecord}
125
- />
126
- </div>
127
- </td>
128
- );
129
- }
130
-
131
- if (item === ColumnsNames.SPREAD) {
132
- return (
133
- <TableCell
134
- key={ColumnsNames.SPREAD}
135
- isError={!!error}
136
- isLoading={checkLoading(ColumnsNames.SPREAD)}
137
- loaderSize={LoaderSize.sm}
138
- >
139
- <span>{updatedRecord.spread}</span>
140
- </TableCell>
141
- );
142
- }
143
- return null;
144
- })}
145
- </>
146
- </TableRow>
147
- );
148
- };
149
-
150
- export { RowWithData };
@@ -1 +0,0 @@
1
- export * from './RowWithData';
@@ -1,4 +0,0 @@
1
- export * from './Cards';
2
- export * from './CardWithData';
3
- export * from './LineChartWithData';
4
- export * from './RowWithData';
@@ -1,74 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import { MockedProvider } from '@apollo/client/testing';
5
- import { MockLayoutProvider } from '@oanda/labs-widget-common';
6
- import { render } from '@testing-library/react';
7
- import React from 'react';
8
-
9
- import { getInstrumentsChart } from '../src/gql/getInstrumentsChart';
10
- import { Division } from '../src/gql/types/graphql';
11
- import { CardWithData } from '../src/LiveRatesTableWidget/components/CardWithData';
12
- import { ColumnsNames } from '../src/LiveRatesTableWidget/types';
13
-
14
- const chartPointsMocks = [
15
- {
16
- request: {
17
- query: getInstrumentsChart,
18
- variables: {
19
- instruments: ['EUR_USD'],
20
- division: 'OC',
21
- },
22
- },
23
- result: {
24
- data: {
25
- topicalInstrumentsCharts: [
26
- {
27
- name: 'EUR_USD',
28
- displayName: 'EUR_USD',
29
- chart: [
30
- 1.0544, 1.05704, 1.05716, 1.05596, 1.05556, 1.05556, 1.05238,
31
- 1.05292, 1.05443, 1.0544, 1.05704, 1.05716, 1.05596, 1.05556,
32
- 1.05556,
33
- ],
34
- },
35
- ],
36
- },
37
- },
38
- },
39
- ];
40
- describe('CardWithData component', () => {
41
- const record = {
42
- instrument: 'EUR_USD',
43
- displayName: 'EUR_USD',
44
- buy: 1.04508,
45
- sell: 1.04523,
46
- spread: 1.2,
47
- dailyPercentChange: '+3,23%',
48
- };
49
- const columns = [
50
- ColumnsNames.SELL,
51
- ColumnsNames.BUY,
52
- ColumnsNames.DAILY_CHANGE,
53
- ColumnsNames.CHART,
54
- ColumnsNames.SPREAD,
55
- ];
56
- it('should render card', () => {
57
- const { getByTestId, getAllByTestId } = render(
58
- <MockedProvider mocks={chartPointsMocks}>
59
- <MockLayoutProvider>
60
- <CardWithData
61
- activeColumns={columns}
62
- division={Division.Oc}
63
- index={0}
64
- record={record}
65
- target={null}
66
- />
67
- </MockLayoutProvider>
68
- </MockedProvider>
69
- );
70
- expect(getByTestId('card')).toBeInTheDocument();
71
- expect(getByTestId('card-header')).toBeInTheDocument();
72
- expect(getAllByTestId('card-row').length).toEqual(4);
73
- });
74
- });
@@ -1,130 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import { MockedProvider } from '@apollo/client/testing';
5
- import { MockLayoutProvider } from '@oanda/labs-widget-common';
6
- import { render } from '@testing-library/react';
7
- import React from 'react';
8
-
9
- import { getInstrumentsChart } from '../src/gql/getInstrumentsChart';
10
- import { Division } from '../src/gql/types/graphql';
11
- import { Cards } from '../src/LiveRatesTableWidget/components';
12
- import { ColumnsNames } from '../src/LiveRatesTableWidget/types';
13
-
14
- const chartPointsMocks = [
15
- {
16
- request: {
17
- query: getInstrumentsChart,
18
- variables: {
19
- instruments: ['EUR_USD'],
20
- division: 'OC',
21
- },
22
- },
23
- result: {
24
- data: {
25
- topicalInstrumentsCharts: [
26
- {
27
- name: 'EUR_USD',
28
- displayName: 'EUR_USD',
29
- chart: [
30
- 1.0544, 1.05704, 1.05716, 1.05596, 1.05556, 1.05556, 1.05238,
31
- 1.05292, 1.05443, 1.0544, 1.05704, 1.05716, 1.05596, 1.05556,
32
- 1.05556,
33
- ],
34
- },
35
- ],
36
- },
37
- },
38
- },
39
- {
40
- request: {
41
- query: getInstrumentsChart,
42
- variables: {
43
- instruments: ['EUR_JPY'],
44
- division: 'OC',
45
- },
46
- },
47
- result: {
48
- data: {
49
- topicalInstrumentsCharts: [
50
- {
51
- name: 'EUR_JPY',
52
- displayName: 'EUR_JPY',
53
- chart: [
54
- 1.0544, 1.05704, 1.05716, 1.05596, 1.05556, 1.05556, 1.05238,
55
- 1.05292, 1.05443, 1.0544, 1.05704, 1.05716, 1.05596, 1.05556,
56
- 1.05556,
57
- ],
58
- },
59
- ],
60
- },
61
- },
62
- },
63
- ];
64
-
65
- describe('Cards component', () => {
66
- const records = [
67
- {
68
- instrument: 'EUR_USD',
69
- displayName: 'EUR_USD',
70
- buy: 1.04508,
71
- sell: 1.04523,
72
- spread: 1.2,
73
- dailyPercentChange: '+3,23%',
74
- },
75
- {
76
- instrument: 'EUR_JPY',
77
- displayName: 'EUR_JPY',
78
- buy: 1.04553,
79
- sell: 1.045353,
80
- spread: 1.3,
81
- dailyPercentChange: '+4,23%',
82
- },
83
- ];
84
- const columns = [
85
- ColumnsNames.SELL,
86
- ColumnsNames.BUY,
87
- ColumnsNames.DAILY_CHANGE,
88
- ColumnsNames.CHART,
89
- ColumnsNames.SPREAD,
90
- ];
91
- it('should render card', () => {
92
- const { getAllByTestId } = render(
93
- <MockedProvider mocks={chartPointsMocks}>
94
- <MockLayoutProvider>
95
- <Cards
96
- columns={columns}
97
- division={Division.Oc}
98
- emptyCardsCount={2}
99
- isError={false}
100
- isLoading={false}
101
- records={records}
102
- target={null}
103
- />
104
- </MockLayoutProvider>
105
- </MockedProvider>
106
- );
107
- expect(getAllByTestId('card').length).toEqual(2);
108
- expect(getAllByTestId('card-header').length).toEqual(2);
109
- expect(getAllByTestId('card-row').length).toEqual(8);
110
- });
111
- it('should render error', () => {
112
- const { getAllByTestId } = render(
113
- <MockedProvider mocks={chartPointsMocks}>
114
- <MockLayoutProvider>
115
- <Cards
116
- isError
117
- columns={columns}
118
- division={Division.Oc}
119
- emptyCardsCount={2}
120
- isLoading={false}
121
- records={records}
122
- target={null}
123
- />
124
- </MockLayoutProvider>
125
- </MockedProvider>
126
- );
127
- expect(getAllByTestId('card').length).toEqual(1);
128
- expect(getAllByTestId('chart-error').length).toEqual(1);
129
- });
130
- });