@wix/bex-core 2.399.0 → 2.401.0
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/dist/cjs/assets/locale/messages_ar.json +20 -20
- package/dist/cjs/assets/locale/messages_bg.json +20 -20
- package/dist/cjs/assets/locale/messages_ca.json +20 -20
- package/dist/cjs/assets/locale/messages_cs.json +20 -20
- package/dist/cjs/assets/locale/messages_da.json +20 -20
- package/dist/cjs/assets/locale/messages_de.json +20 -20
- package/dist/cjs/assets/locale/messages_el.json +20 -20
- package/dist/cjs/assets/locale/messages_en.json +20 -20
- package/dist/cjs/assets/locale/messages_es.json +20 -20
- package/dist/cjs/assets/locale/messages_fi.json +20 -20
- package/dist/cjs/assets/locale/messages_fr.json +20 -20
- package/dist/cjs/assets/locale/messages_he.json +20 -20
- package/dist/cjs/assets/locale/messages_hi.json +20 -20
- package/dist/cjs/assets/locale/messages_hu.json +20 -20
- package/dist/cjs/assets/locale/messages_id.json +20 -20
- package/dist/cjs/assets/locale/messages_it.json +20 -20
- package/dist/cjs/assets/locale/messages_ja.json +20 -20
- package/dist/cjs/assets/locale/messages_ko.json +20 -20
- package/dist/cjs/assets/locale/messages_lt.json +20 -20
- package/dist/cjs/assets/locale/messages_ms.json +20 -20
- package/dist/cjs/assets/locale/messages_nl.json +20 -20
- package/dist/cjs/assets/locale/messages_no.json +20 -20
- package/dist/cjs/assets/locale/messages_pl.json +20 -20
- package/dist/cjs/assets/locale/messages_pt.json +20 -20
- package/dist/cjs/assets/locale/messages_ro.json +20 -20
- package/dist/cjs/assets/locale/messages_ru.json +20 -20
- package/dist/cjs/assets/locale/messages_sk.json +20 -20
- package/dist/cjs/assets/locale/messages_sl.json +20 -20
- package/dist/cjs/assets/locale/messages_sv.json +20 -20
- package/dist/cjs/assets/locale/messages_th.json +20 -20
- package/dist/cjs/assets/locale/messages_tl.json +20 -20
- package/dist/cjs/assets/locale/messages_tr.json +20 -20
- package/dist/cjs/assets/locale/messages_uk.json +20 -20
- package/dist/cjs/assets/locale/messages_vi.json +20 -20
- package/dist/cjs/assets/locale/messages_zh.json +20 -20
- package/dist/cjs/assets/locale/version_file +1 -1
- package/dist/cjs/assets/visual-e2e-locale/messages_visuale2e.json +19 -19
- package/dist/cjs/hooks/useImport.js +7 -2
- package/dist/cjs/hooks/useImport.js.map +1 -1
- package/dist/cjs/state/ImportState/ImportState.js +187 -34
- package/dist/cjs/state/ImportState/ImportState.js.map +1 -1
- package/dist/cjs/state/ImportState/ImportStateBIReporter.js +279 -0
- package/dist/cjs/state/ImportState/ImportStateBIReporter.js.map +1 -0
- package/dist/cjs/state/ImportState/__tests__/ImportState.engine.spec.js +518 -14
- package/dist/cjs/state/ImportState/__tests__/ImportState.engine.spec.js.map +1 -1
- package/dist/cjs/state/ImportState/__tests__/buildImportConfig.spec.js +30 -4
- package/dist/cjs/state/ImportState/__tests__/buildImportConfig.spec.js.map +1 -1
- package/dist/cjs/state/ImportState/__tests__/importFieldCompatibility.spec.js +91 -0
- package/dist/cjs/state/ImportState/__tests__/importFieldCompatibility.spec.js.map +1 -0
- package/dist/cjs/state/ImportState/detectFieldType.js +3 -3
- package/dist/cjs/state/ImportState/detectFieldType.js.map +1 -1
- package/dist/cjs/state/ImportState/importFieldCompatibility.js +92 -0
- package/dist/cjs/state/ImportState/importFieldCompatibility.js.map +1 -0
- package/dist/cjs/state/ImportState/importSampling.js +6 -0
- package/dist/cjs/state/ImportState/importSampling.js.map +1 -0
- package/dist/cjs/state/ImportState/index.js.map +1 -1
- package/dist/cjs/types/Field.js.map +1 -1
- package/dist/esm/assets/locale/messages_ar.json +20 -20
- package/dist/esm/assets/locale/messages_bg.json +20 -20
- package/dist/esm/assets/locale/messages_ca.json +20 -20
- package/dist/esm/assets/locale/messages_cs.json +20 -20
- package/dist/esm/assets/locale/messages_da.json +20 -20
- package/dist/esm/assets/locale/messages_de.json +20 -20
- package/dist/esm/assets/locale/messages_el.json +20 -20
- package/dist/esm/assets/locale/messages_en.json +20 -20
- package/dist/esm/assets/locale/messages_es.json +20 -20
- package/dist/esm/assets/locale/messages_fi.json +20 -20
- package/dist/esm/assets/locale/messages_fr.json +20 -20
- package/dist/esm/assets/locale/messages_he.json +20 -20
- package/dist/esm/assets/locale/messages_hi.json +20 -20
- package/dist/esm/assets/locale/messages_hu.json +20 -20
- package/dist/esm/assets/locale/messages_id.json +20 -20
- package/dist/esm/assets/locale/messages_it.json +20 -20
- package/dist/esm/assets/locale/messages_ja.json +20 -20
- package/dist/esm/assets/locale/messages_ko.json +20 -20
- package/dist/esm/assets/locale/messages_lt.json +20 -20
- package/dist/esm/assets/locale/messages_ms.json +20 -20
- package/dist/esm/assets/locale/messages_nl.json +20 -20
- package/dist/esm/assets/locale/messages_no.json +20 -20
- package/dist/esm/assets/locale/messages_pl.json +20 -20
- package/dist/esm/assets/locale/messages_pt.json +20 -20
- package/dist/esm/assets/locale/messages_ro.json +20 -20
- package/dist/esm/assets/locale/messages_ru.json +20 -20
- package/dist/esm/assets/locale/messages_sk.json +20 -20
- package/dist/esm/assets/locale/messages_sl.json +20 -20
- package/dist/esm/assets/locale/messages_sv.json +20 -20
- package/dist/esm/assets/locale/messages_th.json +20 -20
- package/dist/esm/assets/locale/messages_tl.json +20 -20
- package/dist/esm/assets/locale/messages_tr.json +20 -20
- package/dist/esm/assets/locale/messages_uk.json +20 -20
- package/dist/esm/assets/locale/messages_vi.json +20 -20
- package/dist/esm/assets/locale/messages_zh.json +20 -20
- package/dist/esm/assets/locale/version_file +1 -1
- package/dist/esm/assets/visual-e2e-locale/messages_visuale2e.json +19 -19
- package/dist/esm/hooks/useImport.js +5 -2
- package/dist/esm/hooks/useImport.js.map +1 -1
- package/dist/esm/state/ImportState/ImportState.js +181 -36
- package/dist/esm/state/ImportState/ImportState.js.map +1 -1
- package/dist/esm/state/ImportState/ImportStateBIReporter.js +232 -0
- package/dist/esm/state/ImportState/ImportStateBIReporter.js.map +1 -0
- package/dist/esm/state/ImportState/__tests__/ImportState.engine.spec.js +385 -9
- package/dist/esm/state/ImportState/__tests__/ImportState.engine.spec.js.map +1 -1
- package/dist/esm/state/ImportState/__tests__/buildImportConfig.spec.js +32 -4
- package/dist/esm/state/ImportState/__tests__/buildImportConfig.spec.js.map +1 -1
- package/dist/esm/state/ImportState/__tests__/importFieldCompatibility.spec.js +99 -0
- package/dist/esm/state/ImportState/__tests__/importFieldCompatibility.spec.js.map +1 -0
- package/dist/esm/state/ImportState/detectFieldType.js +3 -3
- package/dist/esm/state/ImportState/detectFieldType.js.map +1 -1
- package/dist/esm/state/ImportState/importFieldCompatibility.js +102 -0
- package/dist/esm/state/ImportState/importFieldCompatibility.js.map +1 -0
- package/dist/esm/state/ImportState/importSampling.js +2 -0
- package/dist/esm/state/ImportState/importSampling.js.map +1 -0
- package/dist/esm/state/ImportState/index.js.map +1 -1
- package/dist/types/hooks/useImport.d.ts +5 -1
- package/dist/types/hooks/useImport.d.ts.map +1 -1
- package/dist/types/state/ImportState/ImportState.d.ts +23 -4
- package/dist/types/state/ImportState/ImportState.d.ts.map +1 -1
- package/dist/types/state/ImportState/ImportStateBIReporter.d.ts +66 -0
- package/dist/types/state/ImportState/ImportStateBIReporter.d.ts.map +1 -0
- package/dist/types/state/ImportState/__tests__/importFieldCompatibility.spec.d.ts +2 -0
- package/dist/types/state/ImportState/__tests__/importFieldCompatibility.spec.d.ts.map +1 -0
- package/dist/types/state/ImportState/detectFieldType.d.ts.map +1 -1
- package/dist/types/state/ImportState/importFieldCompatibility.d.ts +4 -0
- package/dist/types/state/ImportState/importFieldCompatibility.d.ts.map +1 -0
- package/dist/types/state/ImportState/importSampling.d.ts +2 -0
- package/dist/types/state/ImportState/importSampling.d.ts.map +1 -0
- package/dist/types/state/ImportState/index.d.ts +1 -0
- package/dist/types/state/ImportState/index.d.ts.map +1 -1
- package/dist/types/types/Field.d.ts +4 -0
- package/dist/types/types/Field.d.ts.map +1 -1
- package/package.json +8 -5
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _util = require("util");
|
|
4
4
|
var _mobx = require("mobx");
|
|
5
|
+
var _testkit = require("@wix/fe-essentials-standalone/testkit");
|
|
5
6
|
var _ImportState = require("../ImportState");
|
|
6
7
|
var _types = require("@wix/bex-utils/@wix/ambassador-hub-v1-job/types");
|
|
7
8
|
var _hubJobClient = require("../hubJobClient");
|
|
@@ -42,13 +43,15 @@ function setup(clientOverrides = {}, extra = {}) {
|
|
|
42
43
|
};
|
|
43
44
|
_hubJobClient.createHubJobClient.mockReturnValue(client);
|
|
44
45
|
const importModalState = {
|
|
45
|
-
close: jest.fn()
|
|
46
|
+
close: jest.fn(),
|
|
47
|
+
isOpen: false
|
|
46
48
|
};
|
|
47
49
|
const showToast = jest.fn();
|
|
48
50
|
const downloadCsv = jest.fn();
|
|
49
51
|
const translate = (key, params) => params ? `${key}:${JSON.stringify(params)}` : key;
|
|
50
52
|
const {
|
|
51
53
|
detectColumnType,
|
|
54
|
+
isValueCompatible,
|
|
52
55
|
config: configOverride,
|
|
53
56
|
collectionId,
|
|
54
57
|
destination,
|
|
@@ -59,7 +62,9 @@ function setup(clientOverrides = {}, extra = {}) {
|
|
|
59
62
|
fields,
|
|
60
63
|
idFieldKey,
|
|
61
64
|
backup,
|
|
62
|
-
jobApplicationErrorMap
|
|
65
|
+
jobApplicationErrorMap,
|
|
66
|
+
reportBi,
|
|
67
|
+
noSeed
|
|
63
68
|
} = extra;
|
|
64
69
|
const collection = {
|
|
65
70
|
clearResultAndMoveToStart: jest.fn(),
|
|
@@ -114,22 +119,28 @@ function setup(clientOverrides = {}, extra = {}) {
|
|
|
114
119
|
},
|
|
115
120
|
showToast: showToast,
|
|
116
121
|
downloadCsv,
|
|
117
|
-
detectColumnType
|
|
122
|
+
detectColumnType,
|
|
123
|
+
isValueCompatible,
|
|
124
|
+
...(reportBi && {
|
|
125
|
+
reportBi
|
|
126
|
+
})
|
|
118
127
|
};
|
|
119
128
|
const state = new _ImportState.ImportState(props);
|
|
120
129
|
|
|
121
130
|
// Seed a parsed CSV mapped to an existing field.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
if (!noSeed) {
|
|
132
|
+
(0, _mobx.runInAction)(() => {
|
|
133
|
+
state.fileName = 'data.csv';
|
|
134
|
+
state.csvHeaders = ['Name'];
|
|
135
|
+
state.csvRows = [['Apple'], ['Pear']];
|
|
136
|
+
state.mappingByHeader = {
|
|
137
|
+
Name: {
|
|
138
|
+
kind: 'existing',
|
|
139
|
+
fieldId: 'name'
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
133
144
|
return {
|
|
134
145
|
state,
|
|
135
146
|
client,
|
|
@@ -145,6 +156,43 @@ describe('ImportState engine (data-hub job)', () => {
|
|
|
145
156
|
// real even if the preset defaults to fake ones.
|
|
146
157
|
jest.useRealTimers();
|
|
147
158
|
});
|
|
159
|
+
it('uploads duplicate-named columns to their own destination fields', async () => {
|
|
160
|
+
const {
|
|
161
|
+
state,
|
|
162
|
+
client
|
|
163
|
+
} = setup({}, {
|
|
164
|
+
fields: [{
|
|
165
|
+
id: 'price',
|
|
166
|
+
header: 'Number',
|
|
167
|
+
type: 'NUMBER'
|
|
168
|
+
}, {
|
|
169
|
+
id: 'otherPrice',
|
|
170
|
+
header: 'Number',
|
|
171
|
+
type: 'NUMBER'
|
|
172
|
+
}]
|
|
173
|
+
});
|
|
174
|
+
await state.onFileSelected({
|
|
175
|
+
name: 'duplicates.csv',
|
|
176
|
+
arrayBuffer: async () => new _util.TextEncoder().encode('Number,Number\n20,30\n40,50\n').buffer
|
|
177
|
+
});
|
|
178
|
+
expect(state.mappingByHeader).toEqual({
|
|
179
|
+
Number: {
|
|
180
|
+
kind: 'existing',
|
|
181
|
+
fieldId: 'price'
|
|
182
|
+
},
|
|
183
|
+
'Number (2)': {
|
|
184
|
+
kind: 'existing',
|
|
185
|
+
fieldId: 'otherPrice'
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
await state.startImport();
|
|
189
|
+
const uploaded = await new Promise(resolve => {
|
|
190
|
+
const reader = new FileReader();
|
|
191
|
+
reader.onload = () => resolve(String(reader.result));
|
|
192
|
+
reader.readAsText(client.uploadFile.mock.calls[0][0]);
|
|
193
|
+
});
|
|
194
|
+
expect(uploaded.split(/\r?\n/)).toEqual(['price,otherPrice', '20,30', '40,50']);
|
|
195
|
+
});
|
|
148
196
|
it('uploads the aligned file, submits a job, and reports success', async () => {
|
|
149
197
|
const {
|
|
150
198
|
state,
|
|
@@ -1566,4 +1614,460 @@ describe('ImportState items limit and completion hooks', () => {
|
|
|
1566
1614
|
expect(onImportCompleted).toHaveBeenCalledTimes(expectedCalls);
|
|
1567
1615
|
});
|
|
1568
1616
|
});
|
|
1617
|
+
describe('ImportState mapping dropdown fields (CAIRO-4392)', () => {
|
|
1618
|
+
_testkit.testkit.beforeAndAfter();
|
|
1619
|
+
const FIELDS = [{
|
|
1620
|
+
id: 'title',
|
|
1621
|
+
header: 'Title',
|
|
1622
|
+
type: 'SHORT_TEXT'
|
|
1623
|
+
}, {
|
|
1624
|
+
id: 'price',
|
|
1625
|
+
header: 'Price',
|
|
1626
|
+
type: 'NUMBER'
|
|
1627
|
+
}, {
|
|
1628
|
+
id: 'launch',
|
|
1629
|
+
header: 'Launch Date',
|
|
1630
|
+
type: 'DATE'
|
|
1631
|
+
}, {
|
|
1632
|
+
id: 'website',
|
|
1633
|
+
header: 'Website',
|
|
1634
|
+
type: 'URL'
|
|
1635
|
+
}, {
|
|
1636
|
+
id: 'tags',
|
|
1637
|
+
header: 'Tags',
|
|
1638
|
+
type: 'ARRAY'
|
|
1639
|
+
}, {
|
|
1640
|
+
id: 'reference',
|
|
1641
|
+
header: 'Reference',
|
|
1642
|
+
type: 'REFERENCE'
|
|
1643
|
+
}, {
|
|
1644
|
+
id: 'legacy',
|
|
1645
|
+
header: 'Legacy'
|
|
1646
|
+
}];
|
|
1647
|
+
function setupColumns(headers, rows) {
|
|
1648
|
+
const {
|
|
1649
|
+
state
|
|
1650
|
+
} = setup({}, {
|
|
1651
|
+
fields: FIELDS
|
|
1652
|
+
});
|
|
1653
|
+
(0, _mobx.runInAction)(() => {
|
|
1654
|
+
state.csvHeaders = headers;
|
|
1655
|
+
state.csvRows = rows;
|
|
1656
|
+
state.mappingByHeader = {};
|
|
1657
|
+
});
|
|
1658
|
+
return state;
|
|
1659
|
+
}
|
|
1660
|
+
const fieldIds = (state, header) => state.fieldsForHeader(header).map(field => field.id);
|
|
1661
|
+
it('detects a sparse column from its non-empty values', () => {
|
|
1662
|
+
const state = setupColumns(['Price'], [['10'], [''], ['20'], [''], ['30'], ['']]);
|
|
1663
|
+
expect(fieldIds(state, 'Price')).toContain('price');
|
|
1664
|
+
expect(fieldIds(state, 'Price')).not.toContain('launch');
|
|
1665
|
+
});
|
|
1666
|
+
it('offers only the fields that fit the column data', () => {
|
|
1667
|
+
const state = setupColumns(['Price', 'Launch Date', 'Notes'], [['10', '2026-01-01', 'first'], ['20', '2026-01-02', 'second']]);
|
|
1668
|
+
expect(fieldIds(state, 'Price')).toEqual(['title', 'price', 'legacy']);
|
|
1669
|
+
expect(fieldIds(state, 'Launch Date')).toEqual(['title', 'launch', 'legacy']);
|
|
1670
|
+
expect(fieldIds(state, 'Notes')).toEqual(['title', 'reference', 'legacy']);
|
|
1671
|
+
});
|
|
1672
|
+
it('keeps the field a column is mapped to even when it does not fit', () => {
|
|
1673
|
+
const state = setupColumns(['Score'], [['high'], ['low']]);
|
|
1674
|
+
state.setMapping('Score', 'price');
|
|
1675
|
+
expect(fieldIds(state, 'Score')).toContain('price');
|
|
1676
|
+
expect(fieldIds(state, 'Score')).not.toContain('launch');
|
|
1677
|
+
});
|
|
1678
|
+
it('offers every field for a column with no values', () => {
|
|
1679
|
+
const state = setupColumns(['Empty'], [[''], ['']]);
|
|
1680
|
+
expect(fieldIds(state, 'Empty')).toEqual(FIELDS.map(field => field.id));
|
|
1681
|
+
});
|
|
1682
|
+
it('keeps custom fields available but hides unknown fields even when selected', () => {
|
|
1683
|
+
const {
|
|
1684
|
+
state
|
|
1685
|
+
} = setup({}, {
|
|
1686
|
+
fields: [{
|
|
1687
|
+
id: 'rating',
|
|
1688
|
+
header: 'Rating',
|
|
1689
|
+
type: 'CUSTOM'
|
|
1690
|
+
}, {
|
|
1691
|
+
id: 'unknown',
|
|
1692
|
+
header: 'Unknown',
|
|
1693
|
+
type: 'UNKNOWN'
|
|
1694
|
+
}]
|
|
1695
|
+
});
|
|
1696
|
+
state.setMapping('Name', 'unknown');
|
|
1697
|
+
expect(fieldIds(state, 'Name')).toEqual(['rating']);
|
|
1698
|
+
});
|
|
1699
|
+
it('does not auto-map an unknown field with a matching name', async () => {
|
|
1700
|
+
const {
|
|
1701
|
+
state
|
|
1702
|
+
} = setup({}, {
|
|
1703
|
+
fields: [{
|
|
1704
|
+
id: 'status',
|
|
1705
|
+
header: 'Status',
|
|
1706
|
+
type: 'UNKNOWN'
|
|
1707
|
+
}]
|
|
1708
|
+
});
|
|
1709
|
+
await state.onFileSelected({
|
|
1710
|
+
name: 'status.csv',
|
|
1711
|
+
arrayBuffer: async () => new _util.TextEncoder().encode('Status\nPUBLISHED\n').buffer
|
|
1712
|
+
});
|
|
1713
|
+
expect(state.mappingByHeader.Status).toBeNull();
|
|
1714
|
+
expect(fieldIds(state, 'Status')).toEqual([]);
|
|
1715
|
+
});
|
|
1716
|
+
it('separates duplicate headers without colliding with existing suffixes', async () => {
|
|
1717
|
+
const {
|
|
1718
|
+
state
|
|
1719
|
+
} = setup({}, {
|
|
1720
|
+
fields: FIELDS
|
|
1721
|
+
});
|
|
1722
|
+
await state.onFileSelected({
|
|
1723
|
+
name: 'duplicates.csv',
|
|
1724
|
+
arrayBuffer: async () => new _util.TextEncoder().encode('Price,Price,Price (2)\n20,,hello\n').buffer
|
|
1725
|
+
});
|
|
1726
|
+
expect(state.csvHeaders).toEqual(['Price', 'Price (3)', 'Price (2)']);
|
|
1727
|
+
expect(fieldIds(state, 'Price')).not.toContain('reference');
|
|
1728
|
+
expect(fieldIds(state, 'Price (3)')).toContain('reference');
|
|
1729
|
+
state.setMapping('Price (3)', 'reference');
|
|
1730
|
+
expect(state.mappingByHeader.Price).toEqual({
|
|
1731
|
+
kind: 'existing',
|
|
1732
|
+
fieldId: 'price'
|
|
1733
|
+
});
|
|
1734
|
+
expect(state.mappingByHeader['Price (3)']).toEqual({
|
|
1735
|
+
kind: 'existing',
|
|
1736
|
+
fieldId: 'reference'
|
|
1737
|
+
});
|
|
1738
|
+
});
|
|
1739
|
+
it('reuses format checks when mappings change and refreshes them for a new upload', async () => {
|
|
1740
|
+
const isValueCompatible = jest.fn(() => undefined);
|
|
1741
|
+
const {
|
|
1742
|
+
state
|
|
1743
|
+
} = setup({}, {
|
|
1744
|
+
fields: FIELDS,
|
|
1745
|
+
isValueCompatible
|
|
1746
|
+
});
|
|
1747
|
+
expect(fieldIds(state, 'Name')).toContain('title');
|
|
1748
|
+
const initialChecks = isValueCompatible.mock.calls.length;
|
|
1749
|
+
expect(initialChecks).toBeGreaterThan(0);
|
|
1750
|
+
state.setMapping('Name', 'price');
|
|
1751
|
+
expect(fieldIds(state, 'Name')).toContain('price');
|
|
1752
|
+
state.setMapping('Name', null);
|
|
1753
|
+
expect(fieldIds(state, 'Name')).not.toContain('price');
|
|
1754
|
+
expect(isValueCompatible).toHaveBeenCalledTimes(initialChecks);
|
|
1755
|
+
await state.onFileSelected({
|
|
1756
|
+
name: 'numbers.csv',
|
|
1757
|
+
arrayBuffer: async () => new _util.TextEncoder().encode('Name\n10\n20\n').buffer
|
|
1758
|
+
});
|
|
1759
|
+
expect(fieldIds(state, 'Name')).toContain('price');
|
|
1760
|
+
expect(isValueCompatible.mock.calls.length).toBeGreaterThan(initialChecks);
|
|
1761
|
+
});
|
|
1762
|
+
it('refreshes compatibility when the source fields change', () => {
|
|
1763
|
+
const fields = _mobx.observable.box([{
|
|
1764
|
+
id: 'value',
|
|
1765
|
+
header: 'Value',
|
|
1766
|
+
type: 'NUMBER'
|
|
1767
|
+
}]);
|
|
1768
|
+
const {
|
|
1769
|
+
state
|
|
1770
|
+
} = setup({}, {
|
|
1771
|
+
config: {
|
|
1772
|
+
get fields() {
|
|
1773
|
+
return fields.get();
|
|
1774
|
+
},
|
|
1775
|
+
dataSource: {
|
|
1776
|
+
collectionId: 'Movies'
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
expect(fieldIds(state, 'Name')).toEqual([]);
|
|
1781
|
+
(0, _mobx.runInAction)(() => fields.set([{
|
|
1782
|
+
id: 'value',
|
|
1783
|
+
header: 'Value',
|
|
1784
|
+
type: 'SHORT_TEXT'
|
|
1785
|
+
}]));
|
|
1786
|
+
expect(fieldIds(state, 'Name')).toEqual(['value']);
|
|
1787
|
+
});
|
|
1788
|
+
it.each([['14:30:00.000', true], ['14:30:00x000', false]])('offers Time for %s only when the format fits', (value, fits) => {
|
|
1789
|
+
const {
|
|
1790
|
+
state
|
|
1791
|
+
} = setup({}, {
|
|
1792
|
+
fields: [{
|
|
1793
|
+
id: 'clock',
|
|
1794
|
+
header: 'Clock',
|
|
1795
|
+
type: 'TIME'
|
|
1796
|
+
}]
|
|
1797
|
+
});
|
|
1798
|
+
(0, _mobx.runInAction)(() => {
|
|
1799
|
+
state.csvRows = [[value]];
|
|
1800
|
+
});
|
|
1801
|
+
expect(fieldIds(state, 'Name')).toEqual(fits ? ['clock'] : []);
|
|
1802
|
+
});
|
|
1803
|
+
it('updates column compatibility when a new file is uploaded', async () => {
|
|
1804
|
+
const {
|
|
1805
|
+
state
|
|
1806
|
+
} = setup({}, {
|
|
1807
|
+
fields: FIELDS
|
|
1808
|
+
});
|
|
1809
|
+
const upload = csv => state.onFileSelected({
|
|
1810
|
+
name: 'data.csv',
|
|
1811
|
+
arrayBuffer: async () => new _util.TextEncoder().encode(csv).buffer
|
|
1812
|
+
});
|
|
1813
|
+
await upload('Value\n10\n20\n');
|
|
1814
|
+
expect(fieldIds(state, 'Value')).toContain('price');
|
|
1815
|
+
expect(fieldIds(state, 'Value')).not.toContain('launch');
|
|
1816
|
+
await upload('Value\n2026-01-01\n2026-01-02\n');
|
|
1817
|
+
expect(fieldIds(state, 'Value')).toContain('launch');
|
|
1818
|
+
expect(fieldIds(state, 'Value')).not.toContain('price');
|
|
1819
|
+
});
|
|
1820
|
+
it.each([[['10', '20', 'bad'], true], [['10', 'bad', 'worse'], false]])('offers Number only when two-thirds of the samples fit: %j', (values, fits) => {
|
|
1821
|
+
const state = setupColumns(['Value'], values.map(value => [value]));
|
|
1822
|
+
expect(fieldIds(state, 'Value').includes('price')).toBe(fits);
|
|
1823
|
+
});
|
|
1824
|
+
});
|
|
1825
|
+
describe('ImportState BI reporting', () => {
|
|
1826
|
+
beforeEach(() => {
|
|
1827
|
+
jest.useRealTimers();
|
|
1828
|
+
});
|
|
1829
|
+
const CAIRO_SRC = 144;
|
|
1830
|
+
|
|
1831
|
+
/** The reported events with the given evid, as `[params]`. */
|
|
1832
|
+
const eventsOf = (reportBi, evid) => reportBi.mock.calls.map(([log]) => log).filter(log => log.src === CAIRO_SRC && log.evid === evid).map(log => log.params);
|
|
1833
|
+
const setupWithBi = (clientOverrides = {}, extra = {}) => {
|
|
1834
|
+
const reportBi = jest.fn();
|
|
1835
|
+
return {
|
|
1836
|
+
...setup(clientOverrides, {
|
|
1837
|
+
...extra,
|
|
1838
|
+
reportBi
|
|
1839
|
+
}),
|
|
1840
|
+
reportBi
|
|
1841
|
+
};
|
|
1842
|
+
};
|
|
1843
|
+
const csvFile = (content, name = 'data.csv') => ({
|
|
1844
|
+
name,
|
|
1845
|
+
arrayBuffer: async () => new _util.TextEncoder().encode(content).buffer
|
|
1846
|
+
});
|
|
1847
|
+
it('reports the backup phase before the import phase when a backup is configured', async () => {
|
|
1848
|
+
const {
|
|
1849
|
+
state,
|
|
1850
|
+
reportBi
|
|
1851
|
+
} = setupWithBi({}, {
|
|
1852
|
+
backup: async () => ({
|
|
1853
|
+
restore: async () => {}
|
|
1854
|
+
})
|
|
1855
|
+
});
|
|
1856
|
+
await state.startImport();
|
|
1857
|
+
expect(eventsOf(reportBi, 36).map(e => e.phase)).toEqual(['backup', 'import']);
|
|
1858
|
+
});
|
|
1859
|
+
it('reports a partial result and the failed-rows download CTA', async () => {
|
|
1860
|
+
const {
|
|
1861
|
+
state,
|
|
1862
|
+
reportBi
|
|
1863
|
+
} = setupWithBi({
|
|
1864
|
+
getJob: jest.fn(async () => ({
|
|
1865
|
+
...COMPLETED_JOB,
|
|
1866
|
+
status: _types.JobStatus.PARTIALLY_SUCCESSFUL,
|
|
1867
|
+
progress: {
|
|
1868
|
+
itemsSuccessful: 1,
|
|
1869
|
+
itemsRejected: 1,
|
|
1870
|
+
total: 2,
|
|
1871
|
+
current: 2,
|
|
1872
|
+
itemsSuccessfulInfo: {
|
|
1873
|
+
itemsCreated: 1,
|
|
1874
|
+
itemsUpdated: 0
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
})),
|
|
1878
|
+
listMovementLogs: jest.fn(async () => ({
|
|
1879
|
+
logs: []
|
|
1880
|
+
}))
|
|
1881
|
+
});
|
|
1882
|
+
await state.startImport();
|
|
1883
|
+
await state.downloadFailedRows();
|
|
1884
|
+
expect(eventsOf(reportBi, 37)).toEqual([expect.objectContaining({
|
|
1885
|
+
result: 'partial',
|
|
1886
|
+
numItemsFailed: 1
|
|
1887
|
+
})]);
|
|
1888
|
+
expect(eventsOf(reportBi, 39)).toEqual([expect.objectContaining({
|
|
1889
|
+
result: 'partial',
|
|
1890
|
+
numItemsImported: 1
|
|
1891
|
+
})]);
|
|
1892
|
+
expect(eventsOf(reportBi, 40)).toEqual([expect.objectContaining({
|
|
1893
|
+
ctaName: 'Download failed items CSV',
|
|
1894
|
+
result: 'partial'
|
|
1895
|
+
})]);
|
|
1896
|
+
});
|
|
1897
|
+
it('reports a failed job, then the retry with an incremented try', async () => {
|
|
1898
|
+
const getJob = jest.fn().mockResolvedValueOnce({
|
|
1899
|
+
...COMPLETED_JOB,
|
|
1900
|
+
status: _types.JobStatus.FAILED,
|
|
1901
|
+
error: {
|
|
1902
|
+
code: 'boom'
|
|
1903
|
+
}
|
|
1904
|
+
}).mockResolvedValue(COMPLETED_JOB);
|
|
1905
|
+
const {
|
|
1906
|
+
state,
|
|
1907
|
+
reportBi
|
|
1908
|
+
} = setupWithBi({
|
|
1909
|
+
getJob
|
|
1910
|
+
});
|
|
1911
|
+
await state.startImport();
|
|
1912
|
+
expect(eventsOf(reportBi, 37)).toEqual([expect.objectContaining({
|
|
1913
|
+
result: 'fail',
|
|
1914
|
+
try: 1
|
|
1915
|
+
})]);
|
|
1916
|
+
await state.retryImport();
|
|
1917
|
+
expect(eventsOf(reportBi, 38)).toEqual([expect.objectContaining({
|
|
1918
|
+
ctaName: 'Try Again',
|
|
1919
|
+
try: 1
|
|
1920
|
+
})]);
|
|
1921
|
+
// The retry is not a second "Import" confirmation.
|
|
1922
|
+
expect(eventsOf(reportBi, 29)).toHaveLength(1);
|
|
1923
|
+
expect(eventsOf(reportBi, 36).map(e => e.try)).toEqual([1, 2]);
|
|
1924
|
+
expect(eventsOf(reportBi, 37).map(e => [e.result, e.try])).toEqual([['fail', 1], ['success', 2]]);
|
|
1925
|
+
});
|
|
1926
|
+
it('reports a backup failure as a failed process', async () => {
|
|
1927
|
+
const {
|
|
1928
|
+
state,
|
|
1929
|
+
reportBi
|
|
1930
|
+
} = setupWithBi({}, {
|
|
1931
|
+
backup: () => Promise.reject(new Error('backup failed'))
|
|
1932
|
+
});
|
|
1933
|
+
await state.startImport();
|
|
1934
|
+
expect(eventsOf(reportBi, 36).map(e => e.phase)).toEqual(['backup']);
|
|
1935
|
+
expect(eventsOf(reportBi, 37)).toEqual([expect.objectContaining({
|
|
1936
|
+
result: 'fail',
|
|
1937
|
+
try: 1
|
|
1938
|
+
})]);
|
|
1939
|
+
});
|
|
1940
|
+
it('reports the import phase start before a new field fails to be created', async () => {
|
|
1941
|
+
const {
|
|
1942
|
+
state,
|
|
1943
|
+
reportBi
|
|
1944
|
+
} = setupWithBi({}, {
|
|
1945
|
+
updateSchema: jest.fn(() => Promise.reject(new Error('create failed')))
|
|
1946
|
+
});
|
|
1947
|
+
(0, _mobx.runInAction)(() => {
|
|
1948
|
+
state.csvHeaders = ['Name', 'Color'];
|
|
1949
|
+
state.csvRows = [['Apple', 'Red']];
|
|
1950
|
+
state.mappingByHeader = {
|
|
1951
|
+
Name: {
|
|
1952
|
+
kind: 'existing',
|
|
1953
|
+
fieldId: 'name'
|
|
1954
|
+
},
|
|
1955
|
+
Color: {
|
|
1956
|
+
kind: 'new',
|
|
1957
|
+
fieldType: 'text'
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
});
|
|
1961
|
+
await state.startImport();
|
|
1962
|
+
expect(eventsOf(reportBi, 36).map(e => e.phase)).toEqual(['import']);
|
|
1963
|
+
expect(eventsOf(reportBi, 37)).toEqual([expect.objectContaining({
|
|
1964
|
+
result: 'fail',
|
|
1965
|
+
try: 1
|
|
1966
|
+
})]);
|
|
1967
|
+
});
|
|
1968
|
+
it('does not report a failed process end for an import the user cancelled', async () => {
|
|
1969
|
+
let failCreation;
|
|
1970
|
+
const updateSchema = jest.fn(() => new Promise((_resolve, reject) => {
|
|
1971
|
+
failCreation = reject;
|
|
1972
|
+
}));
|
|
1973
|
+
const {
|
|
1974
|
+
state,
|
|
1975
|
+
reportBi
|
|
1976
|
+
} = setupWithBi({}, {
|
|
1977
|
+
updateSchema
|
|
1978
|
+
});
|
|
1979
|
+
(0, _mobx.runInAction)(() => {
|
|
1980
|
+
state.csvHeaders = ['Name', 'Color'];
|
|
1981
|
+
state.csvRows = [['Apple', 'Red']];
|
|
1982
|
+
state.mappingByHeader = {
|
|
1983
|
+
Name: {
|
|
1984
|
+
kind: 'existing',
|
|
1985
|
+
fieldId: 'name'
|
|
1986
|
+
},
|
|
1987
|
+
Color: {
|
|
1988
|
+
kind: 'new',
|
|
1989
|
+
fieldType: 'text'
|
|
1990
|
+
}
|
|
1991
|
+
};
|
|
1992
|
+
});
|
|
1993
|
+
const run = state.startImport();
|
|
1994
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
1995
|
+
expect(updateSchema).toHaveBeenCalledTimes(1);
|
|
1996
|
+
await state.close('Cancel Button');
|
|
1997
|
+
failCreation(new Error('create failed'));
|
|
1998
|
+
await run;
|
|
1999
|
+
expect(eventsOf(reportBi, 37).map(e => e.result)).toEqual(['stopped by user']);
|
|
2000
|
+
});
|
|
2001
|
+
it('reports the selected file and file errors', async () => {
|
|
2002
|
+
const {
|
|
2003
|
+
state,
|
|
2004
|
+
reportBi
|
|
2005
|
+
} = setupWithBi({}, {
|
|
2006
|
+
noSeed: true
|
|
2007
|
+
});
|
|
2008
|
+
await state.onFileSelected(csvFile('Name,Price\nA,1\nB,2\n', 'ok.csv'));
|
|
2009
|
+
expect(eventsOf(reportBi, 28)).toEqual([expect.objectContaining({
|
|
2010
|
+
fileName: 'ok.csv',
|
|
2011
|
+
numColumns: 2,
|
|
2012
|
+
numRows: 2,
|
|
2013
|
+
step: 'upload'
|
|
2014
|
+
})]);
|
|
2015
|
+
await state.onFileSelected(csvFile('a,b\n"broken,1\n', 'broken.csv'));
|
|
2016
|
+
const unreadable = csvFile('x', 'unreadable.csv');
|
|
2017
|
+
jest.spyOn(unreadable, 'arrayBuffer').mockRejectedValue(new Error('io'));
|
|
2018
|
+
await state.onFileSelected(unreadable);
|
|
2019
|
+
expect(eventsOf(reportBi, 42)).toEqual([expect.objectContaining({
|
|
2020
|
+
errorType: 'process_failed',
|
|
2021
|
+
fileName: 'broken.csv'
|
|
2022
|
+
}), expect.objectContaining({
|
|
2023
|
+
errorType: 'file_read_failed',
|
|
2024
|
+
fileName: 'unreadable.csv'
|
|
2025
|
+
})]);
|
|
2026
|
+
});
|
|
2027
|
+
it('reports the selected file before the mapping warning it causes', async () => {
|
|
2028
|
+
const {
|
|
2029
|
+
state,
|
|
2030
|
+
reportBi
|
|
2031
|
+
} = setupWithBi({}, {
|
|
2032
|
+
noSeed: true
|
|
2033
|
+
});
|
|
2034
|
+
const dispose = state.init();
|
|
2035
|
+
await state.onFileSelected(csvFile('Name,Price\n', 'empty.csv'));
|
|
2036
|
+
dispose();
|
|
2037
|
+
const evids = reportBi.mock.calls.map(([log]) => log.evid);
|
|
2038
|
+
expect(evids.indexOf(28)).toBeGreaterThan(-1);
|
|
2039
|
+
expect(evids.indexOf(28)).toBeLessThan(evids.indexOf(41));
|
|
2040
|
+
expect(eventsOf(reportBi, 41)).toEqual([expect.objectContaining({
|
|
2041
|
+
warningType: 'no_rows'
|
|
2042
|
+
})]);
|
|
2043
|
+
});
|
|
2044
|
+
it('reports the duplicate-id policy change and whether the file repeats ids', () => {
|
|
2045
|
+
const {
|
|
2046
|
+
state,
|
|
2047
|
+
reportBi
|
|
2048
|
+
} = setupWithBi({}, {
|
|
2049
|
+
fields: [{
|
|
2050
|
+
id: '_id',
|
|
2051
|
+
header: 'ID'
|
|
2052
|
+
}]
|
|
2053
|
+
});
|
|
2054
|
+
(0, _mobx.runInAction)(() => {
|
|
2055
|
+
state.csvHeaders = ['ID'];
|
|
2056
|
+
state.csvRows = [['1'], ['1']];
|
|
2057
|
+
state.mappingByHeader = {
|
|
2058
|
+
ID: {
|
|
2059
|
+
kind: 'existing',
|
|
2060
|
+
fieldId: '_id'
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
});
|
|
2064
|
+
state.setWritePolicy(_types.WritePolicy.SKIP_EXISTING);
|
|
2065
|
+
state.setWritePolicy(_types.WritePolicy.SKIP_EXISTING);
|
|
2066
|
+
expect(eventsOf(reportBi, 44)).toEqual([expect.objectContaining({
|
|
2067
|
+
duplicateIdPolicy: 'skip_imported',
|
|
2068
|
+
prevDuplicateIdPolicy: 'update_existing',
|
|
2069
|
+
hasDuplicateIdsInFile: true
|
|
2070
|
+
})]);
|
|
2071
|
+
});
|
|
2072
|
+
});
|
|
1569
2073
|
//# sourceMappingURL=ImportState.engine.spec.js.map
|