diff --git a/js/reference.js b/js/reference.js index 8d70b887..81874d62 100644 --- a/js/reference.js +++ b/js/reference.js @@ -3272,6 +3272,10 @@ // as part of heuristics, treat the asset filename the same as the asset itself. // and only add one of them. if (col.isAssetFilename) { + if (col.assetURLColumnName in consideredColumns) { + return; + } + consideredColumns[col.assetURLColumnName] = true; _addAssetColumn(self.table.columns.get(col.assetURLColumnName), sourceObjectWrapper, name, heuristics); return; } diff --git a/test/specs/column/conf/columns_schema/schema.json b/test/specs/column/conf/columns_schema/schema.json index 72b1dac0..9471777b 100644 --- a/test/specs/column/conf/columns_schema/schema.json +++ b/test/specs/column/conf/columns_schema/schema.json @@ -891,7 +891,7 @@ "column_definitions": [ { "name": "id", - "comment": "id, asset should be ignored", + "comment": "id, asset should be used and key ignored", "nullok": false, "type": { "typename": "text" @@ -1090,10 +1090,8 @@ ], "annotations": { "tag:isrd.isi.edu,2016:visible-columns": { - "detailed": ["col_asset_3", "col_asset_4", "col_asset_6"], - "entry/create": ["col_filename","col_byte","col_md5","col_sha256"], "entry/edit": ["col_asset_3", "col_filename","col_byte","col_md5","col_sha256"], - "compact/brief": ["col_asset_3", "col_filename","col_byte","col_md5","col_sha256"] + "compact/brief": ["col_asset_3", "col_filename","col_byte","col_md5","col_sha256", "col_asset_6_byte_count"] } } }, diff --git a/test/specs/column/tests/01.columns_list.js b/test/specs/column/tests/01.columns_list.js index d95bff22..f68ecf7f 100644 --- a/test/specs/column/tests/01.columns_list.js +++ b/test/specs/column/tests/01.columns_list.js @@ -253,43 +253,40 @@ exports.execute = function (options) { * * 2. table_w_asset: * ref.columns for detailed (no context present): - * 0: table_w_asset_key_1 *KeyPseudoColumn* + * 0: table_w_asset_key_1 *AssetPseudoColumn* * 1: table_w_asset_fk_to_outbound *ForeignKeyPseudoColumn* * 2: col_1 * 3: col_2 - * 4: col_filename + * 4: col_asset_3 *AssetPseudoColumn* (asset with valid options) (was 10) * 5: col_byte * 6: col_md5 * 7: col_sha256 * 8: col_asset_1 *AssetPseudoColumn* disabeld (no url_pattern) * 9: col_asset_2 *AssetPseudoColumn* (asset with invalid options) has column-display (markdown and order) - * 10: col_asset_3 *AssetPseudoColumn* (asset with valid options) - * 11: col_asset_4 *AssetPseudoColumn* (asset with url_pattern and filename) has column-display (markdown) - * 12: col_asset_4_filename - * 13: col_asset_5 (asset with type not text) - * 14: col_asset_6 *AssetPseudoColumn* (asset with url_pattern, filename, and image_preview) - * 15: col_asset_6_filename - * 16: col_asset_6_byte_count + * 10: col_asset_4 *AssetPseudoColumn* (asset with url_pattern and filename) has column-display (markdown) (was 11) + * 11: col_asset_5 (asset with type not text) (was 13) + * 12: col_asset_6 *AssetPseudoColumn* (asset with url_pattern, filename, and image_preview) (wa 14) + * 13: col_asset_6_byte_count (was 16) * + system columns * - * ref.columns for entry (no context present): - * 0: id + * ref.columns for compact (no context present): + * 0: table_w_asset_key_1 *KeyPseudoColumn* * 1: table_w_asset_fk_to_outbound *ForeignKeyPseudoColumn* * 2: col_1 * 3: col_2 - * 4: col_asset_1 *AssetPseudoColumn* (disabled) - * 5: col_asset_2 *AssetPseudoColumn* - * 6: col_asset_3 *AssetPseudoColumn* - * 7: col_asset_4 - * 8: col_asset_5 - * 9: col_asset_6 *AssetPseudoColumn* (with image_preview) - * + * 4: col_asset_3 *AssetPseudoColumn* (asset with valid options) (was 10) + * 5: col_byte + * 6: col_asset_1 *AssetPseudoColumn* disabeld (no url_pattern) (was 8) + * 7: col_asset_2 *AssetPseudoColumn* (asset with invalid options) has column-display (markdown and order) (was 9) + * 8: col_asset_4 *AssetPseudoColumn* (asset with url_pattern and filename) has column-display (markdown) (was 11) + * 9: col_asset_5 (asset with type not text) (was 13) + * 10: col_asset_6 *AssetPseudoColumn* (asset with url_pattern, filename, and image_preview) (was 14) + * 11: col_asset_6_byte_count + * + system columns * * contexts that are used: * - compact: no visible-columns - * - detailed: valid assets: col_asset_3, col_asset_4, col_asset_6 - * - edit: no visible-columns - * - entry/create: does not include col_asset_3 -> so no ignore + * - detailed: no vis-columns * - entry/edit: includes col_asset_3 and all its contituent columns * - compact/brief: includes col_asset_3 and all its contituent columns * - compact/brief/inline: inlcudes inline table that should not be visible @@ -333,6 +330,8 @@ exports.execute = function (options) { assetRefCompact = ref.contextualize.compact; assetRefCompactCols = assetRefCompact.columns; assetRefEntry = ref.contextualize.entry; + assetRefDetailed = ref.contextualize.detailed; + assetRefDetailedCols = assetRefDetailed.columns; done(); }).catch(function (err) { console.dir(err); @@ -364,18 +363,16 @@ exports.execute = function (options) { ]; assetCompactExpectedValue = [ - '1', + '1', '1', - '1000', '10001', 'filename', + '1000', '10001', + 'filename', '

1.24 kB

\n', - 'md5', 'sha256', '', '

filename

\n', - 'filename', - 'filename4', + '

filename4

\n', '4', 'filename6', - 'filename6', '

9,234

\n' ]; @@ -460,20 +457,14 @@ exports.execute = function (options) { "col_asset_3" ] }]); - - checkReferenceColumns([{ - ref: assetRef.contextualize.entryCreate, - expected: [ - "col_filename","col_byte","col_md5","col_sha256" - ] - }]); }); it('otherwise, should not be ignored.', function() { checkReferenceColumns([{ ref: assetRef.contextualize.compactBrief, expected: [ - "col_asset_3", "col_filename","col_byte","col_md5","col_sha256" + "col_asset_3", "col_filename","col_byte","col_md5","col_sha256", + "col_asset_6_byte_count" ] }]); }); @@ -715,24 +706,36 @@ exports.execute = function (options) { }]); }); - it ('filename, md5, and sha256 should be ignored in compact context.', () => { - - }); - - it ('filename should be ingored in detailed context.', () => { - + it ('only filename should be ignored in detailed context.', () => { + expect(assetRefDetailed.columns.length).toBe(19); + checkReferenceColumns([{ + ref: assetRefDetailed, + expected: [ + "id", + ["columns_schema", "table_w_asset_fk_to_outbound"].join("_"), + "col_1", "col_2", + "col_asset_3", // instead of filename + "col_byte", "col_md5", "col_sha256", + "col_asset_1", "col_asset_2", + "col_asset_4", "col_asset_5", "col_asset_6", "col_asset_6_byte_count" + ] + }]); }); - it('should not be ignored in other contexts.', function() { - expect(assetRefCompactCols.length).toBe(22); - expect(assetRefCompactCols[4].name).toBe("col_filename"); - expect(assetRefCompactCols[4].isPseudo).toBe(false); - expect(assetRefCompactCols[5].name).toBe("col_byte"); - expect(assetRefCompactCols[5].isPseudo).toBe(false); - expect(assetRefCompactCols[6].name).toBe("col_md5"); - expect(assetRefCompactCols[6].isPseudo).toBe(false); - expect(assetRefCompactCols[7].name).toBe("col_sha256"); - expect(assetRefCompactCols[7].isPseudo).toBe(false); + it ('filename, md5, and sha256 should be ignored in compact context.', () => { + expect(assetRefCompact.columns.length).toBe(17); + checkReferenceColumns([{ + ref: assetRefCompact, + expected: [ + "id", + ["columns_schema", "table_w_asset_fk_to_outbound"].join("_"), + "col_1", "col_2", + "col_asset_3", // instead of filename + "col_byte", + "col_asset_1", "col_asset_2", + "col_asset_4", "col_asset_5", "col_asset_6" + ] + }]); }); }); @@ -747,8 +750,8 @@ exports.execute = function (options) { }); it("if column type is not `text`, should ignore the asset annotation.", function() { - expect(assetRefCompactCols[13].name).toBe("col_asset_5", "invalid name for compact"); - expect(assetRefCompactCols[13].isPseudo).toBe(false, "invalid isPseudo for compact"); + expect(assetRefCompactCols[9].name).toBe("col_asset_5", "invalid name for compact"); + expect(assetRefCompactCols[9].isPseudo).toBe(false, "invalid isPseudo for compact"); expect(assetRefEntry.columns[8].name).toBe("col_asset_5", "invalid name for entry"); expect(assetRefEntry.columns[8].isPseudo).toBe(false, "invalid isPseudo for entry"); }); @@ -973,9 +976,10 @@ exports.execute = function (options) { }); it('in detailed, should return the download button and image preview if applicaple.', function(done) { - assetRefCompact.contextualize.detailed.read(limit).then(function (page) { + assetRefDetailed.read(limit).then(function (page) { var tuples = page.tuples; expect(tuples[0].values).toEqual(jasmine.arrayContaining(assetDetailedExpectedValue)); + done(); }, function (err) { console.dir(err); diff --git a/test/specs/column/tests/02.reference_column.js b/test/specs/column/tests/02.reference_column.js index af35bc85..4eec99b0 100644 --- a/test/specs/column/tests/02.reference_column.js +++ b/test/specs/column/tests/02.reference_column.js @@ -149,9 +149,9 @@ exports.execute = function (options) { expect(compactColumns[i].isPseudo).toBe(true, "problem with Outbound FKs, index=" + i); } - for (i = 9; i < 12; i++) { + [4, 6, 7, 8, 10].forEach((i) => { expect(assetRefCompactCols[i].isPseudo).toBe(true, "problem with Asset index=" + i); - } + }); expect(detailedColumns[3].isPseudo).toBe(true, "problem with Inbound FKs."); @@ -195,15 +195,15 @@ exports.execute = function (options) { describe('.isAsset, ', function () { it ('for PseudoColumns that are asset should return true.', function () { - for (var i = 8; i < 12; i++) { - expect(assetRefCompactCols[i].isAsset).toBe(true, "invalid isAsset for index="+ i); - } + expect(assetRefCompactCols[4].isAsset).toBe(true, "invalid isAsset for index=4"); - expect(assetRefCompactCols[14].isAsset).toBe(true, "invalid isAsset for index=14"); + [0, 4, 6, 7, 8, 10].forEach((i) => { + expect(assetRefCompactCols[i].isAsset).toBe(true, "invalid isAsset for index="+ i); + }); }); it ('for other columns should return undefined.', function () { - for (var i = 0; i < 8; i++) { + for (var i = 1; i <=3; i++) { expect(assetRefCompactCols[i].isAsset).toBe(undefined, "invalid isAsset for index="+ i); } }); @@ -247,10 +247,6 @@ exports.execute = function (options) { for (var i = 5; i < 12; i++) { expect(compactColumns[i].table.name).toBe(tableName); } - - for (var i = 8; i < 12; i++) { - expect(assetRefCompactCols[i].table.name).toBe(tableWithAsset); - } }); }); @@ -361,9 +357,10 @@ exports.execute = function (options) { for (var i = 16; i < 21; i++) { expect(compactColumns[i].type.name).toBe("markdown"); } - for (var i = 9; i < 12; i++) { + + [0, 4, 6, 7, 8, 10].forEach((i) => { expect(assetRefCompactCols[i].type.name).toBe('markdown'); - } + }); expect(detailedColumns[3].type.name).toBe("markdown"); }); @@ -842,21 +839,21 @@ exports.execute = function (options) { val = assetRefEntryCols[6].formatPresentation({"col_asset_3": "https://example.com"}, "entry", {"col_asset_3": "https://example.com"}).value; expect(val).toEqual("https://example.com"); - val = assetRefCompactCols[9].formatPresentation({"col_filename": "filename", "col_asset_2": "value"}, "entry", {"col_filename": "filename"}).value; + val = assetRefCompactCols[7].formatPresentation({"col_filename": "filename", "col_asset_2": "value"}, "entry", {"col_filename": "filename"}).value; expect(val).toEqual("value"); }); it('otherwise, if coulmn has column-display annotation, use it.', function () { - val = assetRefCompactCols[9].formatPresentation({"col_filename": "filename", "col_asset_2": "value"}, "compact", {"col_filename": "filename"}).value; + val = assetRefCompactCols[7].formatPresentation({"col_filename": "filename", "col_asset_2": "value"}, "compact", {"col_filename": "filename"}).value; expect(val).toEqual("

filename

\n"); }); describe('otherwise should create a download link,', () => { it ('filename should be used as caption if it\'s defined and has non-empty value', () => { - val = assetRefCompactCols[10].formatPresentation({"col_asset_3": "https://example.com", "col_filename": "filename"}).value; + val = assetRefCompactCols[4].formatPresentation({"col_asset_3": "https://example.com", "col_filename": "filename"}).value; expect(val).toEqual('filename', "value missmatch."); - val = assetRefCompactCols[10].formatPresentation({"col_asset_3": "https://example.com?query=1&v=1", "col_filename": "filename"}).value; + val = assetRefCompactCols[4].formatPresentation({"col_asset_3": "https://example.com?query=1&v=1", "col_filename": "filename"}).value; //NOTE this is the output but it will be displayed correctly. expect(val).toEqual('filename', "couldn't handle having query params in the url."); }); @@ -864,34 +861,34 @@ exports.execute = function (options) { it ("if url matches the expected hatrac format, extract the filename and use it as caption.", function () { var hatracSampleURL = "/hatrac/Zf/ZfDsy20170915D/file-test.csv:2J7IIX63WQRUDIALUGYDKDO36A"; var expectedValue = 'file-test.csv'; - val = assetRefCompactCols[8].formatPresentation({"col_asset_1": hatracSampleURL}).value; + val = assetRefCompactCols[6].formatPresentation({"col_asset_1": hatracSampleURL}).value; expect(val).toEqual(expectedValue, "value missmatch."); // has filenameColumn but its value is null - val = assetRefCompactCols[10].formatPresentation({"col_asset_3": hatracSampleURL, "col_filename": null}).value; + val = assetRefCompactCols[4].formatPresentation({"col_asset_3": hatracSampleURL, "col_filename": null}).value; expect(val).toEqual(expectedValue, "value missmatch."); }); it ("if context is detailed and url is absolute, use last part of url as caption and add origin beside the button.", function () { var url = "http://example.com/folder/next/folder/image.png"; - val = assetRefCompactCols[8].formatPresentation({"col_asset_1": url}, "detailed").value; + val = assetRefCompactCols[6].formatPresentation({"col_asset_1": url}, "detailed").value; expect(val).toEqual('image.png(source: example.com)', "value missmatch for detailed"); }); it ("otherwise, use the last part of url for caption without any origin information.", function () { // has filenameColumn but its value is null - val = assetRefCompactCols[10].formatPresentation({"col_asset_3": "https://example.com/asset.png", "col_filename": null}).value; + val = assetRefCompactCols[4].formatPresentation({"col_asset_3": "https://example.com/asset.png", "col_filename": null}).value; expect(val).toEqual('asset.png', "value missmatch."); var url = "http://example.com/folder/next/folder/image.png"; - val = assetRefCompactCols[8].formatPresentation({"col_asset_1": url}, "compact").value; + val = assetRefCompactCols[6].formatPresentation({"col_asset_1": url}, "compact").value; expect(val).toEqual('image.png', "value missmatch for compact"); - val = assetRefCompactCols[8].formatPresentation({"col_asset_1": url}, "compact/brief").value; + val = assetRefCompactCols[6].formatPresentation({"col_asset_1": url}, "compact/brief").value; expect(val).toEqual('image.png', "value missmatch for compact/brief"); // detailed but relative url - val = assetRefCompactCols[8].formatPresentation({"col_asset_1": "go/to/file.png"}, "detailed").value; + val = assetRefCompactCols[6].formatPresentation({"col_asset_1": "go/to/file.png"}, "detailed").value; expect(val).toEqual('file.png', "value missmatch for detailed context"); }) }); @@ -904,7 +901,7 @@ exports.execute = function (options) { }); it ('otherwise return the default presentation.', () => { - const v = assetRefCompactCols[16].formatPresentation({"col_asset_6_byte_count": 123456789, }, "compact").value; + const v = assetRefCompactCols[11].formatPresentation({"col_asset_6_byte_count": 123456789, }, "compact").value; expect(v).toEqual("

123,456,789

\n"); }); }); @@ -998,31 +995,31 @@ exports.execute = function (options) { describe("for assets, ", function () { it ("should return the defined column_order on the column.", function () { - expect(assetRefCompactCols[9].sortable).toBe(true, "sortable missmatch, index=9."); - expect(assetRefCompactCols[9]._sortColumns.length).toBe(2, "sort column length missmatch, index=9."); - expect(assetRefCompactCols[9]._sortColumns.map(function (col) { + expect(assetRefCompactCols[7].sortable).toBe(true, "sortable missmatch, index=9."); + expect(assetRefCompactCols[7]._sortColumns.length).toBe(2, "sort column length missmatch, index=9."); + expect(assetRefCompactCols[7]._sortColumns.map(function (col) { return col.column.name })).toEqual(['col_asset_2', 'col_filename'], "sort columns missmatch, index=9."); }); it ("otherwise if filename column is defined should return it", function () { - expect(assetRefCompactCols[10].sortable).toBe(true, "sortable missmatch, index=10."); - expect(assetRefCompactCols[10]._sortColumns.length).toBe(1, "sort column length missmatch, index=10."); - expect(assetRefCompactCols[10]._sortColumns.map(function (col) { + expect(assetRefCompactCols[4].sortable).toBe(true, "sortable missmatch, index=10."); + expect(assetRefCompactCols[4]._sortColumns.length).toBe(1, "sort column length missmatch, index=10."); + expect(assetRefCompactCols[4]._sortColumns.map(function (col) { return col.column.name })).toEqual(['col_filename'], "sort columns missmatch, index=10."); - expect(assetRefCompactCols[11].sortable).toBe(true, "sortable missmatch, index=11."); - expect(assetRefCompactCols[11]._sortColumns.length).toBe(1, "sort column length missmatch, index=11."); - expect(assetRefCompactCols[11]._sortColumns.map(function (col) { + expect(assetRefCompactCols[8].sortable).toBe(true, "sortable missmatch, index=11."); + expect(assetRefCompactCols[8]._sortColumns.length).toBe(1, "sort column length missmatch, index=11."); + expect(assetRefCompactCols[8]._sortColumns.map(function (col) { return col.column.name })).toEqual(['col_asset_4_filename'], "sort columns missmatch, index=11."); }); it ("otherwise should return the url column.", function () { - expect(assetRefCompactCols[8].sortable).toBe(true, "sortable missmatch, index=8."); - expect(assetRefCompactCols[8]._sortColumns.length).toBe(1, "sort column length missmatch, index=8."); - expect(assetRefCompactCols[8]._sortColumns.map(function (col) { + expect(assetRefCompactCols[6].sortable).toBe(true, "sortable missmatch, index=8."); + expect(assetRefCompactCols[6]._sortColumns.length).toBe(1, "sort column length missmatch, index=8."); + expect(assetRefCompactCols[6]._sortColumns.map(function (col) { return col.column.name })).toEqual(['col_asset_1'], "sort columns missmatch, index=8."); }); @@ -1072,70 +1069,70 @@ exports.execute = function (options) { describe('.urlPattern', function() { it('otherwise should return the defined url_pattern in annotation.', function () { - expect(assetRefCompactCols[9].urlPattern).toBe("/hatrac/{{col_asset_2}}"); - expect(assetRefCompactCols[10].urlPattern).toBe("/hatrac/{{col_asset_3}}"); + expect(assetRefCompactCols[7].urlPattern).toBe("/hatrac/{{col_asset_2}}"); + expect(assetRefCompactCols[4].urlPattern).toBe("/hatrac/{{col_asset_3}}"); }); }); describe(".templateEngine", function () { it ("should return the defined template_engine", function () { - expect(assetRefCompactCols[9].templateEngine).toBe("", "missmatch for index=9"); - expect(assetRefCompactCols[10].templateEngine).toBe("handlebars", "missmatch for index=10"); + expect(assetRefCompactCols[7].templateEngine).toBe("", "missmatch for index=9"); + expect(assetRefCompactCols[4].templateEngine).toBe("handlebars", "missmatch for index=10"); }); }); describe('.filenameColumn', function() { it('should return null if column is not valid or not present.', function () { - expect(assetRefCompactCols[9].filenameColumn).toBe(null); + expect(assetRefCompactCols[7].filenameColumn).toBe(null); }); it('otherwise should return the column.', function () { - expect(assetRefCompactCols[10].filenameColumn.name).toBe("col_filename"); + expect(assetRefCompactCols[4].filenameColumn.name).toBe("col_filename"); }); }); describe('.byteCountColumn', function() { it('should return null if column is not valid or not present.', function () { - expect(assetRefCompactCols[9].byteCountColumn).toBe(null); + expect(assetRefCompactCols[7].byteCountColumn).toBe(null); }); it('otherwise should return the column.', function () { - expect(assetRefCompactCols[10].byteCountColumn.name).toBe("col_byte"); + expect(assetRefCompactCols[4].byteCountColumn.name).toBe("col_byte"); }); }); describe('.md5', function() { it('should return the md5 defined.', function () { - expect(assetRefCompactCols[9].md5).toBe(true); - expect(assetRefCompactCols[10].md5.name).toBe("col_md5"); + expect(assetRefCompactCols[7].md5).toBe(true); + expect(assetRefCompactCols[4].md5.name).toBe("col_md5"); }); }); describe('.sha256', function() { it('should return the sha256 defined.', function () { - expect(assetRefCompactCols[9].sha256).toBe(true); - expect(assetRefCompactCols[10].sha256.name).toBe("col_sha256"); + expect(assetRefCompactCols[7].sha256).toBe(true); + expect(assetRefCompactCols[4].sha256.name).toBe("col_sha256"); }); }); describe('.filenameExtFilter', function() { it('should return empty array if file_name_ext is not present.', function () { - expect(assetRefCompactCols[9].filenameExtFilter.length).toBe(0, "Returned value is not an empty array"); + expect(assetRefCompactCols[7].filenameExtFilter.length).toBe(0, "Returned value is not an empty array"); }); it('otherwise should return the defined array of file name extensions.', function () { - expect(assetRefCompactCols[10].filenameExtFilter).toEqual(["*.jpg"]); + expect(assetRefCompactCols[4].filenameExtFilter).toEqual(["*.jpg"]); }); }); describe('.filenameExtRegexp', function() { it('should return empty array if file_name_ext is not present.', function () { - expect(assetRefCompactCols[9].filenameExtFilter.length).toBe(0, "Returned value is not an empty array"); + expect(assetRefCompactCols[7].filenameExtFilter.length).toBe(0, "Returned value is not an empty array"); }); it('otherwise should return the defined array of file name extensions.', function () { - expect(assetRefCompactCols[10].filenameExtRegexp).toEqual([".special.jpg", ".jpg"]); + expect(assetRefCompactCols[4].filenameExtRegexp).toEqual([".special.jpg", ".jpg"]); }); }); @@ -1180,32 +1177,32 @@ exports.execute = function (options) { }; it ("should return empty values if the asset is null.", function () { - testMetadata(assetRefCompactCols[9], {}, null, "empty asset index=9.", "", "", false, "", "", "", ""); + testMetadata(assetRefCompactCols[7], {}, null, "empty asset index=9.", "", "", false, "", "", "", ""); - testMetadata(assetRefCompactCols[10], {}, null, "empty asset index=10.", "", "", false, "", "", "", ""); + testMetadata(assetRefCompactCols[4], {}, null, "empty asset index=10.", "", "", false, "", "", "", ""); }); describe("regarding byteCount, md5, sha256.", function () { it ("if annotation has metadata columns, should return their values.", function () { - testMetadata(assetRefCompactCols[10], assetMetadataTestData, null, "empty asset index=10.", null, null, null, "filenamevalue.png",12400000, "md5value", "sha256value"); + testMetadata(assetRefCompactCols[4], assetMetadataTestData, null, "empty asset index=10.", null, null, null, "filenamevalue.png",12400000, "md5value", "sha256value"); }); it ("otherwise should return empty string.", function () { - testMetadata(assetRefCompactCols[9], {"col_asset_2": "/hatrac/testurl"}, null, "empty asset index=10.", null, null, null, "", "", "", ""); + testMetadata(assetRefCompactCols[7], {"col_asset_2": "/hatrac/testurl"}, null, "empty asset index=10.", null, null, null, "", "", "", ""); }); }); describe("regarding caption, hostInformation, and sameHost ", function () { it ("if asset column has filename column and its value is not empty, should return it as caption. hostInformation should be empty. sameHost should be false.", function () { - testMetadata(assetRefCompactCols[10], assetMetadataTestData, null, "asset with filename value", "filenamevalue.png", "", true); + testMetadata(assetRefCompactCols[4], assetMetadataTestData, null, "asset with filename value", "filenamevalue.png", "", true); }); it ("otherwise, if the url value matches the format, should extract the filename. hostInformation should be empty. sameHost should be true.", function () { - testMetadata(assetRefCompactCols[8], {col_asset_1: "/hatrac/Zf/ZfDsy20170915D/file-test.csv:2J7IIX63WQRUDIALUGYDKDO36A"}, null, "hatrac file", "file-test.csv", "", true); + testMetadata(assetRefCompactCols[6], {col_asset_1: "/hatrac/Zf/ZfDsy20170915D/file-test.csv:2J7IIX63WQRUDIALUGYDKDO36A"}, null, "hatrac file", "file-test.csv", "", true); }); it ("otherwise, should return the last part of url. hostInformation in detailed if url is absolute should be valid.", function () { - testMetadata(assetRefCompactCols[8], {col_asset_1: "http://example.com/folder/next/folder/image.png"}, "compact", "non-hatrac compact file", "image.png", "", false); + testMetadata(assetRefCompactCols[6], {col_asset_1: "http://example.com/folder/next/folder/image.png"}, "compact", "non-hatrac compact file", "image.png", "", false); testMetadata(assetRefEntryCols[4], {col_asset_1: "http://example.com/folder/next/folder/image.png"}, "detailed", "non-hatrac entry file", "image.png", "example.com", false); @@ -1228,11 +1225,11 @@ exports.execute = function (options) { }); it ('otherwise should return false.', function () { - for (var i = 8; i < 12; i++) { + [0, 4, 6, 7, 8].forEach((i) => { expect(assetRefCompactCols[i].displayImagePreview).toBe(false, "invalid isAsset for index="+ i); - } + }); - expect(assetRefCompactCols[14].displayImagePreview).toBe(false, "invalid isAsset for index=14"); + expect(assetRefCompactCols[10].displayImagePreview).toBe(false, "invalid isAsset for index=14"); }); });