Skip to content

Commit fd29e4b

Browse files
MKirovaMKirova
authored andcommitted
Add partial test with 5 dimension.
1 parent aca4d5c commit fd29e4b

File tree

1 file changed

+220
-2
lines changed

1 file changed

+220
-2
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.spec.ts

Lines changed: 220 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ describe('Pivot pipes #pivotGrid', () => {
11001100
]);
11011101
});
11021102

1103-
it('should generate correct data with 4 dimensions with varying depth.', () => {
1103+
it('should generate correct row data with 4 dimensions with varying depth.', () => {
11041104

11051105
// 4 dimensions - depths 3, 2, 1, 1
11061106
const dims = [
@@ -1224,7 +1224,6 @@ describe('Pivot pipes #pivotGrid', () => {
12241224

12251225
const prod_country_date_seller = PivotGridFunctions.getDimensionData(rowStatePipeResult, pivotConfig.rows);
12261226
const allProdsRecords = prod_country_date_seller.filter(x => x['AllProduct'] === 'All Products');
1227-
debugger;
12281227
expect(allProdsRecords).toEqual([
12291228
{ AllProduct: 'All Products', Country: 'Bulgaria', AllPeriods: 'All Periods', SellerName: 'Stanley' },
12301229
{ AllProduct: 'All Products', Country: 'Bulgaria', AllPeriods: 'All Periods', SellerName: 'Walter' },
@@ -1264,4 +1263,223 @@ describe('Pivot pipes #pivotGrid', () => {
12641263
{ ProductCategory: 'Clothing', Country: 'Uruguay', Date: '05/12/2020', SellerName: 'Larry' }
12651264
]);
12661265
});
1266+
1267+
it('should generate correct row data with 5 dimensions with varying depth.', () => {
1268+
data = [
1269+
{
1270+
ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley',
1271+
Country: 'Bulgaria', Date: '01/01/2021', UnitsSold: 282, Discontinued: false
1272+
},
1273+
{ ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa', Country: 'USA', Date: '01/05/2019', UnitsSold: 296, Discontinued: true },
1274+
{ ProductCategory: 'Bikes', UnitPrice: 3.56, SellerName: 'Lydia', Country: 'Uruguay', Date: '01/06/2020', UnitsSold: 68, Discontinued: true },
1275+
{ ProductCategory: 'Accessories', UnitPrice: 85.58, SellerName: 'David', Country: 'USA', Date: '04/07/2021', UnitsSold: 293, Discontinued: false },
1276+
{ ProductCategory: 'Components', UnitPrice: 18.13, SellerName: 'John', Country: 'USA', Date: '12/08/2021', UnitsSold: 240, Discontinued: false },
1277+
{ ProductCategory: 'Clothing', UnitPrice: 68.33, SellerName: 'Larry', Country: 'Uruguay', Date: '05/12/2020', UnitsSold: 456, Discontinued: true },
1278+
{
1279+
ProductCategory: 'Clothing', UnitPrice: 16.05, SellerName: 'Walter',
1280+
Country: 'Bulgaria', Date: '02/19/2020', UnitsSold: 492, Discontinued: false
1281+
}];
1282+
// 5 dimensions - depths 3, 2, 2, 1, 1
1283+
const dims = [
1284+
new IgxPivotDateDimension(
1285+
{
1286+
memberName: 'Date',
1287+
enabled: true
1288+
},
1289+
{
1290+
months: false,
1291+
total: true
1292+
}
1293+
),
1294+
{
1295+
memberName: 'AllProduct',
1296+
memberFunction: () => 'All Products',
1297+
enabled: true,
1298+
childLevel: {
1299+
memberName: 'ProductCategory',
1300+
enabled: true
1301+
}
1302+
},
1303+
{
1304+
memberName: 'AllCountries',
1305+
memberFunction: () => 'All Countries',
1306+
enabled: true,
1307+
childLevel: {
1308+
memberName: 'Country',
1309+
enabled: true
1310+
}
1311+
},
1312+
{
1313+
memberName: 'SellerName',
1314+
enabled: true
1315+
}, {
1316+
memberName: 'Discontinued',
1317+
enabled: true,
1318+
memberFunction: (data) => {
1319+
return data.Discontinued.toString();
1320+
}
1321+
}];
1322+
// Date, Product, Country, Seller, Discontinued
1323+
pivotConfig.rows = [
1324+
dims[0], // Date
1325+
dims[1], // Product
1326+
dims[2], // Country
1327+
dims[3], // Seller
1328+
dims[4] // Discontinued
1329+
];
1330+
1331+
let rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
1332+
let columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
1333+
let rowStatePipeResult = rowStatePipe.transform(columnPipeResult, pivotConfig, expansionStates, true);
1334+
expect(rowStatePipeResult.length).toBe(77);
1335+
const prod_country_date_seller_discontinued = PivotGridFunctions.getDimensionData(rowStatePipeResult, pivotConfig.rows);
1336+
const allPeriods_allProducts_records = prod_country_date_seller_discontinued.filter(x => x['AllPeriods'] === 'All Periods' &&
1337+
x['AllProduct'] === 'All Products');
1338+
expect(allPeriods_allProducts_records).toEqual(
1339+
[
1340+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'Stanley', Discontinued: 'false' },
1341+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'Walter', Discontinued: 'false' },
1342+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'Elisa', Discontinued: 'true' },
1343+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'David', Discontinued: 'false' },
1344+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'John', Discontinued: 'false' },
1345+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'Larry', Discontinued: 'true' },
1346+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'Lydia', Discontinued: 'true' },
1347+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'Bulgaria', SellerName: 'Stanley', Discontinued: 'false' },
1348+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'Bulgaria', SellerName: 'Walter', Discontinued: 'false' },
1349+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'USA', SellerName: 'Elisa', Discontinued: 'true' },
1350+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'USA', SellerName: 'David', Discontinued: 'false' },
1351+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'USA', SellerName: 'John', Discontinued: 'false' },
1352+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'Uruguay', SellerName: 'Larry', Discontinued: 'true' },
1353+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'Uruguay', SellerName: 'Lydia', Discontinued: 'true' }
1354+
]
1355+
);
1356+
1357+
// TODO - check the rest of the 'All Periods' fields here once issue: https://github.com/IgniteUI/igniteui-angular/issues/10680 is resolved.
1358+
1359+
// Discontinued, Date, Product, Country, Seller
1360+
pivotConfig.rows = [
1361+
dims[4],
1362+
dims[0],
1363+
dims[1],
1364+
dims[2],
1365+
dims[3]
1366+
];
1367+
1368+
rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
1369+
columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
1370+
rowStatePipeResult = rowStatePipe.transform(columnPipeResult, pivotConfig, expansionStates, true);
1371+
expect(rowStatePipeResult.length).toBe(77);
1372+
const discontinued_prod_country_date_seller = PivotGridFunctions.getDimensionData(rowStatePipeResult, pivotConfig.rows);
1373+
const ongoing_records = discontinued_prod_country_date_seller.filter(x => x['Discontinued'] === 'false');
1374+
const discontinued_records = discontinued_prod_country_date_seller.filter(x => x['Discontinued'] === 'true');
1375+
expect(discontinued_records.length).toBe(33);
1376+
expect(ongoing_records.length).toBe(44);
1377+
const ongoing_allPeriods = ongoing_records.filter(x => x['AllPeriods'] === 'All Periods');
1378+
expect(ongoing_allPeriods).toEqual([
1379+
{ Discontinued: 'false', AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'Stanley' },
1380+
{ Discontinued: 'false', AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'Walter' },
1381+
{ Discontinued: 'false', AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'David' },
1382+
{ Discontinued: 'false', AllPeriods: 'All Periods', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'John' },
1383+
{ Discontinued: 'false', AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'Bulgaria', SellerName: 'Stanley' },
1384+
{ Discontinued: 'false', AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'Bulgaria', SellerName: 'Walter' },
1385+
{ Discontinued: 'false', AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'USA', SellerName: 'David' },
1386+
{ Discontinued: 'false', AllPeriods: 'All Periods', AllProduct: 'All Products', Country: 'USA', SellerName: 'John' },
1387+
{ Discontinued: 'false', AllPeriods: 'All Periods', ProductCategory: 'Clothing', AllCountries: 'All Countries', SellerName: 'Stanley' },
1388+
{ Discontinued: 'false', AllPeriods: 'All Periods', ProductCategory: 'Clothing', AllCountries: 'All Countries', SellerName: 'Walter' },
1389+
{ Discontinued: 'false', AllPeriods: 'All Periods', ProductCategory: 'Clothing', Country: 'Bulgaria', SellerName: 'Stanley' },
1390+
{ Discontinued: 'false', AllPeriods: 'All Periods', ProductCategory: 'Clothing', Country: 'Bulgaria', SellerName: 'Walter' },
1391+
{ Discontinued: 'false', AllPeriods: 'All Periods', ProductCategory: 'Accessories', AllCountries: 'All Countries', SellerName: 'David' },
1392+
{ Discontinued: 'false', AllPeriods: 'All Periods', ProductCategory: 'Accessories', Country: 'USA', SellerName: 'David' },
1393+
{ Discontinued: 'false', AllPeriods: 'All Periods', ProductCategory: 'Components', AllCountries: 'All Countries', SellerName: 'John' },
1394+
{ Discontinued: 'false', AllPeriods: 'All Periods', ProductCategory: 'Components', Country: 'USA', SellerName: 'John' }
1395+
]);
1396+
const ongoing_2021 = ongoing_records.filter(x => x['Years'] === '2021');
1397+
expect(ongoing_2021).toEqual([
1398+
{ Discontinued: 'false', Years: '2021', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'Stanley' },
1399+
{ Discontinued: 'false', Years: '2021', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'David' },
1400+
{ Discontinued: 'false', Years: '2021', AllProduct: 'All Products', AllCountries: 'All Countries', SellerName: 'John' },
1401+
{ Discontinued: 'false', Years: '2021', AllProduct: 'All Products', Country: 'Bulgaria', SellerName: 'Stanley' },
1402+
{ Discontinued: 'false', Years: '2021', AllProduct: 'All Products', Country: 'USA', SellerName: 'David' },
1403+
{ Discontinued: 'false', Years: '2021', AllProduct: 'All Products', Country: 'USA', SellerName: 'John' },
1404+
{ Discontinued: 'false', Years: '2021', ProductCategory: 'Clothing', AllCountries: 'All Countries', SellerName: 'Stanley' },
1405+
{ Discontinued: 'false', Years: '2021', ProductCategory: 'Clothing', Country: 'Bulgaria', SellerName: 'Stanley' },
1406+
{ Discontinued: 'false', Years: '2021', ProductCategory: 'Accessories', AllCountries: 'All Countries', SellerName: 'David' },
1407+
{ Discontinued: 'false', Years: '2021', ProductCategory: 'Accessories', Country: 'USA', SellerName: 'David' },
1408+
{ Discontinued: 'false', Years: '2021', ProductCategory: 'Components', AllCountries: 'All Countries', SellerName: 'John' },
1409+
{ Discontinued: 'false', Years: '2021', ProductCategory: 'Components', Country: 'USA', SellerName: 'John' },
1410+
]);
1411+
1412+
1413+
// Seller, Country, Date, Product, Discontinued
1414+
pivotConfig.rows = [
1415+
dims[3], // Seller
1416+
dims[2], // Country
1417+
dims[0], // Date
1418+
dims[1], // Product
1419+
dims[4] // Discontinued
1420+
];
1421+
1422+
rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
1423+
columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
1424+
rowStatePipeResult = rowStatePipe.transform(columnPipeResult, pivotConfig, expansionStates, true);
1425+
expect(rowStatePipeResult.length).toBe(84);
1426+
const seller_country_date_prod_disc = PivotGridFunctions.getDimensionData(rowStatePipeResult, pivotConfig.rows);
1427+
const stanley_allCountries_allPeriods = seller_country_date_prod_disc.filter(x => x['SellerName'] === 'Stanley' &&
1428+
x['AllCountries'] === 'All Countries' && x['AllPeriods'] === 'All Periods');
1429+
expect(stanley_allCountries_allPeriods).toEqual([
1430+
{ SellerName: 'Stanley', AllCountries: 'All Countries', AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false' },
1431+
{ SellerName: 'Stanley', AllCountries: 'All Countries', AllPeriods: 'All Periods', ProductCategory: 'Clothing', Discontinued: 'false' }
1432+
]);
1433+
1434+
// TODO - check the rest of the 'AllCountries' fields here once issue: https://github.com/IgniteUI/igniteui-angular/issues/10662 is resolved.
1435+
1436+
const stanley_allCountries_2021 = seller_country_date_prod_disc.filter(x => x['SellerName'] === 'Stanley' &&
1437+
x['AllCountries'] === 'All Countries' && x['Years'] === '2021');
1438+
expect(stanley_allCountries_2021).toEqual([
1439+
{ SellerName: 'Stanley', AllCountries: 'All Countries', Years: '2021', AllProduct: 'All Products', Discontinued: 'false' },
1440+
{ SellerName: 'Stanley', AllCountries: 'All Countries', Years: '2021', ProductCategory: 'Clothing', Discontinued: 'false' }
1441+
]);
1442+
1443+
// Date, Product, Discontinued, Countries, Seller
1444+
pivotConfig.rows = [
1445+
dims[0], // Date
1446+
dims[1], // Product
1447+
dims[4], // Discontinued
1448+
dims[2], // Country
1449+
dims[3], // Seller
1450+
];
1451+
1452+
rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
1453+
columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
1454+
rowStatePipeResult = rowStatePipe.transform(columnPipeResult, pivotConfig, expansionStates, true);
1455+
expect(rowStatePipeResult.length).toBe(73);
1456+
const date_prod_disc_seller = PivotGridFunctions.getDimensionData(rowStatePipeResult, pivotConfig.rows);
1457+
1458+
const date_allPeriods_allProducts_records = date_prod_disc_seller.filter(x => x['AllPeriods'] === 'All Periods' && x['AllProduct'] === 'All Products');
1459+
expect(date_allPeriods_allProducts_records).toEqual([
1460+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false', AllCountries: 'All Countries', SellerName: 'Stanley' },
1461+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false', AllCountries: 'All Countries', SellerName: 'Walter' },
1462+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false', AllCountries: 'All Countries', SellerName: 'David' },
1463+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false', AllCountries: 'All Countries', SellerName: 'John' },
1464+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false', Country: 'Bulgaria', SellerName: 'Stanley' },
1465+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false', Country: 'Bulgaria', SellerName: 'Walter' },
1466+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false', Country: 'USA', SellerName: 'David' },
1467+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'false', Country: 'USA', SellerName: 'John' },
1468+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'true', AllCountries: 'All Countries', SellerName: 'Elisa' },
1469+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'true', AllCountries: 'All Countries', SellerName: 'Larry' },
1470+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'true', AllCountries: 'All Countries', SellerName: 'Lydia' },
1471+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'true', Country: 'USA', SellerName: 'Elisa' },
1472+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'true', Country: 'Uruguay', SellerName: 'Larry' },
1473+
{ AllPeriods: 'All Periods', AllProduct: 'All Products', Discontinued: 'true', Country: 'Uruguay', SellerName: 'Lydia' }
1474+
]);
1475+
const date_2021_allProducts_records = date_prod_disc_seller.filter(x => x['Years'] === '2021' && x['AllProduct'] === 'All Products');
1476+
expect(date_2021_allProducts_records).toEqual([
1477+
{ Years: '2021', AllProduct: 'All Products', Discontinued: 'false', AllCountries: 'All Countries', SellerName: 'Stanley' },
1478+
{ Years: '2021', AllProduct: 'All Products', Discontinued: 'false', AllCountries: 'All Countries', SellerName: 'David' },
1479+
{ Years: '2021', AllProduct: 'All Products', Discontinued: 'false', AllCountries: 'All Countries', SellerName: 'John' },
1480+
{ Years: '2021', AllProduct: 'All Products', Discontinued: 'false', Country: 'Bulgaria', SellerName: 'Stanley' },
1481+
{ Years: '2021', AllProduct: 'All Products', Discontinued: 'false', Country: 'USA', SellerName: 'David' },
1482+
{ Years: '2021', AllProduct: 'All Products', Discontinued: 'false', Country: 'USA', SellerName: 'John' }
1483+
]);
1484+
});
12671485
});

0 commit comments

Comments
 (0)