Skip to content

Commit

Permalink
Display unit tests in generated docs (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Mar 12, 2024
1 parent 7505688 commit e56754c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Docs-20240311-140344.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Docs
body: Enable display of unit tests
time: 2024-03-11T14:03:44.490834-04:00
custom:
Author: gshank
Issue: "501"
4 changes: 2 additions & 2 deletions src/app/components/column_details/column_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<th style="background-color: white; position: sticky; top: 0; z-index: 1;">Type</th>
<th style="background-color: white; position: sticky; top: 0; z-index: 1;">Description</th>
<th style="width: 1px; background-color: white; position: sticky; top: 0; z-index: 1;">Constraints</th>
<th style="width: 1px; background-color: white; position: sticky; top: 0; z-index: 1;">Tests</th>
<th style="width: 1px; background-color: white; position: sticky; top: 0; z-index: 1;">Data Tests</th>
<th style="width: 1px; background-color: white; position: sticky; top: 0; z-index: 1;" class='text-center'>More?</th>
</tr>
</thead>
Expand Down Expand Up @@ -104,7 +104,7 @@ <h5>Constraints</h5>
</div>

<div ng-show="column.tests && column.tests.length" style="margin-bottom: 15px">
<h5>Generic Tests</h5>
<h5>Generic Data Tests</h5>
<ul class="list-unstyled" style="margin-top: 2px">
<li ng-repeat="test in column.tests" ng-switch on="test.short" class='text-light'>
<span ng-switch-when="F">
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/references/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ angular
} else if (type == 'seed') {
return 'Seeds';
} else if (type == 'test') {
return 'Tests';
return 'Data Tests';
} else if (type == 'unit_test') {
return 'Unit Tests';
} else if (type == 'snapshot') {
return 'Snapshots'
} else if (type == 'analysis') {
Expand Down
60 changes: 60 additions & 0 deletions src/app/docs/unit_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<style>
/* TODO */
.section-target {
top: -8em;
}

.noflex {
flex: 0 0 160px !important;
}

.highlight {
color: #24292e;
background-color: white;
}

</style>

<div class='app-scroll'>
<div class="app-links app-sticky">
<div class="app-title">
<div class="app-frame app-pad app-flush-bottom">
<h1>
<span class="break">{{ model.name }}</span>
<small>unit test</small>
</h1>
</div>
</div>
<div class="app-frame app-pad-h">
<ul class="nav nav-tabs">
<li ui-sref-active='active'><a ui-sref="dbt.unit_test({'#': 'description'})">Description</a></li>
<li ui-sref-active='active' ng-show = "parentsLength != 0"><a ui-sref="dbt.unit_test({'#': 'depends_on'})">Depends On</a></li>
</ul>
</div>
</div>
<div class="app-details">
<div class="app-frame app-pad">
<section class="section">
<div class="section-target" id="description"></div>
<div class="section-content">
<h6>Description</h6>
<div class="panel">
<div class="panel-body">
<div ng-if="model.description" class="model-markdown" marked="model.description"></div>
<div ng-if="!model.description">This {{ model.resource_type }} is not currently documented</div>
</div>
</div>
</div>
</section>

<section class="section" ng-show = "parentsLength != 0">
<div class="section-target" id="depends_on"></div>
<div class="section-content">
<h6>Depends On</h6>
<reference-list references="parents" node="model" />
</div>
</section>

</div>
</div>
</div>
9 changes: 9 additions & 0 deletions src/app/index.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const templates = {
source: require('./docs/source.html'),
snapshot: require('./docs/snapshot.html'),
seed: require('./docs/seed.html'),
unit_test: require('./docs/unit_test.html'),
test: require('./docs/test.html'),
analysis: require('./docs/analysis.html'),
macro: require('./docs/macro.html'),
Expand Down Expand Up @@ -78,6 +79,14 @@ angular
unique_id: {type: 'string'}
},
})
.state('dbt.unit_test', {
url: 'unit_test/:unique_id?section&' + graph_params,
controller: 'TestCtrl',
templateUrl: templates.unit_test,
params: {
unique_id: {type: 'string'}
},
})
.state('dbt.test', {
url: 'test/:unique_id?section&' + graph_params,
controller: 'TestCtrl',
Expand Down
5 changes: 3 additions & 2 deletions src/app/services/node_selection_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ angular
'snapshot',
'source',
'test',
'unit_test',
'analysis',
'exposure',
'metric',
Expand All @@ -37,7 +38,7 @@ angular
options: {
packages: [],
tags: [null],
resource_types: ['model', 'seed', 'snapshot', 'source', 'test', 'analysis', 'exposure', 'metric', 'semantic_model'],
resource_types: ['model', 'seed', 'snapshot', 'source', 'test', 'analysis', 'exposure', 'metric', 'semantic_model', 'unit_test'],
}
};

Expand All @@ -63,7 +64,7 @@ angular
include_selection = '+metric:' + node.name;
} else if (node && node.resource_type == 'semantic_model') {
include_selection = '+semantic_model:' + node.name;
} else if (node && _.includes(['analysis', 'test'], node.resource_type)) {
} else if (node && _.includes(['analysis', 'test', 'unit_test'], node.resource_type)) {
include_selection = '+' + node.name;
} else {
include_selection = "";
Expand Down
6 changes: 6 additions & 0 deletions src/app/services/project_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ angular
node.label = node.name;
});

// Add unit tests into nodes
_.each(service.files.manifest.unit_tests, function(node) {
service.files.manifest.nodes[node.unique_id] = node;
node.label = node.name;
});

var adapter = service.files.manifest.metadata.adapter_type;
var macros = clean_project_macros(service.files.manifest.macros, adapter);
service.files.manifest.macros = macros;
Expand Down

0 comments on commit e56754c

Please sign in to comment.