Skip to content

Commit

Permalink
fix issues in the code and broken test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
RFSH committed Oct 17, 2023
1 parent a839cce commit 4fc769f
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 121 deletions.
4 changes: 4 additions & 0 deletions js/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions test/specs/column/conf/columns_schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
}
}
},
Expand Down
112 changes: 58 additions & 54 deletions test/specs/column/tests/01.columns_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -364,18 +363,16 @@ exports.execute = function (options) {
];

assetCompactExpectedValue = [
'<a href="https://example.org/chaise/record/columns_schema:table_w_asset/id=1">1</a>',
'<a href="1?uinit=1&amp;cid=test" download="" class="asset-permission">1</a>',
'<a href="https://example.org/chaise/record/columns_schema:columns_table/RID=' + utils.findEntityRID(options, schemaName, "columns_table", "id", "1") + '">1</a>',
'1000', '10001', 'filename',
'1000', '10001',
'<a href="https://example.org?uinit=1&amp;cid=test" download="" class="asset-permission">filename</a>',
'<p><span data-chaise-tooltip="1,242 bytes (1 kB = 1,000 bytes)">1.24 kB</span></p>\n',
'md5', 'sha256',
'',
'<h2>filename</h2>\n',
'<a href="https://example.org?uinit=1&amp;cid=test" download="" class="asset-permission">filename</a>',
'filename4',
'<p>filename4</p>\n',
'4',
'<a href="https://example.org/file.png?uinit=1&amp;cid=test" download="" class="asset-permission">filename6</a>',
'filename6',
'<p>9,234</p>\n'
];

Expand Down Expand Up @@ -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"
]
}]);
});
Expand Down Expand Up @@ -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"
]
}]);
});
});

Expand All @@ -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");
});
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 4fc769f

Please sign in to comment.