From d64ce2e2021afaadd282b04d52adb323f1ac0235 Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Fri, 18 May 2018 15:15:43 -0700 Subject: [PATCH] fixes failing tests for purge-policy and upstream-dataset components --- .../components/datasets/upstream-dataset.ts | 2 +- wherehows-web/app/components/purge-policy.ts | 2 +- .../upstream-dataset/_upstream-dataset.scss | 26 --- .../components/datasets/upstream-dataset.hbs | 154 +++++++++--------- .../containers/upstream-dataset-test.js | 71 ++++++-- .../datasets/upstream-dataset-test.js | 38 +---- .../components/purge-policy-test.js | 15 +- 7 files changed, 148 insertions(+), 160 deletions(-) diff --git a/wherehows-web/app/components/datasets/upstream-dataset.ts b/wherehows-web/app/components/datasets/upstream-dataset.ts index 6cdbdc4bea..771f9c1b12 100644 --- a/wherehows-web/app/components/datasets/upstream-dataset.ts +++ b/wherehows-web/app/components/datasets/upstream-dataset.ts @@ -5,7 +5,7 @@ import { action } from '@ember-decorators/object'; export default class UpstreamDataset extends Component { tagName = 'section'; - classNames = ['upstream-dataset-banner']; + classNames = ['upstream-downstream-retention']; /** * Flag indicating the component is in view only mode and not editable diff --git a/wherehows-web/app/components/purge-policy.ts b/wherehows-web/app/components/purge-policy.ts index 867f82f5a0..571506eb7f 100644 --- a/wherehows-web/app/components/purge-policy.ts +++ b/wherehows-web/app/components/purge-policy.ts @@ -23,7 +23,7 @@ export default class PurgePolicyComponent extends Component { * Reference to the informational text if the dataset does not have a saved purge policy * @type {string} */ - missingPolicyText: string = ''; + missingPolicyText: string; /** * Reference to client options for each purge policy diff --git a/wherehows-web/app/styles/components/upstream-dataset/_upstream-dataset.scss b/wherehows-web/app/styles/components/upstream-dataset/_upstream-dataset.scss index 43289e94bf..e2e5c3b543 100644 --- a/wherehows-web/app/styles/components/upstream-dataset/_upstream-dataset.scss +++ b/wherehows-web/app/styles/components/upstream-dataset/_upstream-dataset.scss @@ -1,29 +1,3 @@ -.upstream-dataset-banner { - &:hover { - .upstream-dataset-banner__description { - height: item-spacing(7); - } - } - - &__description { - margin: 0; - height: 0; - overflow: hidden; - transition: height 0.2s ease-in-out; - } - - &__informational { - display: flex; - flex-direction: row; - align-items: center; - - &__text { - margin: 0; - padding: item-spacing(2); - } - } -} - .upstream-dataset { @include nacho-container; padding: item-spacing(2 5); diff --git a/wherehows-web/app/templates/components/datasets/upstream-dataset.hbs b/wherehows-web/app/templates/components/datasets/upstream-dataset.hbs index 166ca49ff4..6fe029b423 100644 --- a/wherehows-web/app/templates/components/datasets/upstream-dataset.hbs +++ b/wherehows-web/app/templates/components/datasets/upstream-dataset.hbs @@ -1,17 +1,16 @@ -
-

Compliance Info

-

- Compliance Policy on this dataset is inherited from it's parent dataset(s). To make modifications on the purge -
- policy on this page, please complete the Compliance Metadata on all of the parent datasets. -

+

Compliance Info

+

+ Compliance Policy on this dataset is inherited from it's parent dataset(s). To make modifications on the purge +
+ policy on this page, please complete the Compliance Metadata on all of the parent datasets. +

-
+
-

Parent Dataset

+

Parent Dataset

- {{#each upstreamsMetadata as |parent|}} -
+{{#each upstreamsMetadata as |parent|}} +
{{tooltip-on-element text=(if parent.hasCompliance "Compliance completed for parent dataset" "Please complete the Compliance on this parent dataset") @@ -24,78 +23,77 @@ {{/if}} - {{#link-to - "datasets.dataset" - "urn" - (query-params urn=parent.urn) - class="upstream-dataset__upstream-link" - }} - {{parent.nativeName}} - {{/link-to}} + {{#link-to + "datasets.dataset" + "urn" + (query-params urn=parent.urn) + class="upstream-dataset__upstream-link" + }} + {{parent.nativeName}} + {{/link-to}} - {{#link-to - "datasets.dataset" - "urn" - (query-params urn=parent.urn) - class="upstream-dataset__upstream-link-chevron" - }} - - {{/link-to}} + {{#link-to + "datasets.dataset" + "urn" + (query-params urn=parent.urn) + class="upstream-dataset__upstream-link-chevron" + }} + + {{/link-to}} -
- {{/each}} +
+{{/each}} -
-

Compliance Purge Policy

-
- {{#unless hasIncompleteUpstream}} - +
+

Compliance Purge Policy

+
+ {{#unless hasIncompleteUpstream}} + - {{#if isReadOnly}} - - {{else}} - + {{else}} + - {{/if}} - {{/unless}} -
- -
- -
- {{#if hasIncompleteUpstream}} -

- This dataset does not have a current compliance purge policy. To update, please complete the Compliance Metadata - on the parent dataset(s). -

- {{else}} - - {{purge-policy - isEditable=(not isReadOnly) - platform=platform - supportedPurgePolicies=supportedPurgePolicies - purgeNote=retention.purgeNote - purgePolicy=(readonly retention.purgeType) - missingPolicyText="This dataset does not have a current compliance purge policy" - onPolicyChange=onChange - }} - {{/if}} + + {{/if}} + {{/unless}}
-
+ + + +
+ {{#if hasIncompleteUpstream}} +

+ This dataset does not have a current compliance purge policy. To update, please complete the Compliance Metadata + on the parent dataset(s). +

+ {{else}} + + {{purge-policy + isEditable=(not isReadOnly) + platform=platform + supportedPurgePolicies=supportedPurgePolicies + purgeNote=retention.purgeNote + purgePolicy=(readonly retention.purgeType) + missingPolicyText="This dataset does not have a current compliance purge policy" + onPolicyChange=onChange + }} + {{/if}} +
diff --git a/wherehows-web/tests/integration/components/datasets/containers/upstream-dataset-test.js b/wherehows-web/tests/integration/components/datasets/containers/upstream-dataset-test.js index 2bfdbc8e6a..be7a6c1892 100644 --- a/wherehows-web/tests/integration/components/datasets/containers/upstream-dataset-test.js +++ b/wherehows-web/tests/integration/components/datasets/containers/upstream-dataset-test.js @@ -3,6 +3,7 @@ import hbs from 'htmlbars-inline-precompile'; import { hdfsUrn } from 'wherehows-web/mirage/fixtures/urn'; import sinon from 'sinon'; import { waitUntil, find } from 'ember-native-dom-helpers'; +import { DatasetPlatform, PurgePolicy } from 'wherehows-web/constants'; moduleForComponent( 'datasets/containers/upstream-dataset', @@ -22,28 +23,72 @@ moduleForComponent( ); test('it renders', async function(assert) { - assert.expect(2); - const titleElementQuery = '.upstream-dataset-banner__title strong'; - const descriptionElementQuery = '.upstream-dataset-banner__description strong'; + assert.expect(1); + const upstreamElement = '.upstream-dataset'; - this.set('upstreamUrn', hdfsUrn); - this.server.respondWith(/\/api\/v2\/datasets.*/, function(xhr) { + this.set('urn', hdfsUrn); + this.set('platform', DatasetPlatform.HDFS); + + this.server.respondWith(/\/api\/v2\/datasets.*\/upstreams/, function(xhr) { + xhr.respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify([ + { + nativeName: 'A nativeName', + platform: DatasetPlatform.HDFS, + uri: hdfsUrn + } + ]) + ); + }); + + this.server.respondWith(/\/api\/v2\/datasets.*\/compliance/, function(xhr) { xhr.respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify({ - dataset: { - nativeName: 'A nativeName', - description: 'A dataset description' - } + datasetUrn: hdfsUrn }) ); }); - this.render(hbs`{{datasets/containers/upstream-dataset upstreamUrn=upstreamUrn}}`); + const retentionPolicy = { + datasetUrn: hdfsUrn, + purgeType: PurgePolicy.AutoPurge, + purgeNote: null + }; - await waitUntil(() => find(descriptionElementQuery)); + this.server.respondWith('GET', /\/api\/v2\/datasets.*\/retention/, [ + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify({ retentionPolicy }) + ]); - assert.equal(find(titleElementQuery).textContent.trim(), 'A nativeName'); - assert.equal(find(descriptionElementQuery).textContent.trim(), 'A dataset description'); + this.server.respondWith('POST', /\/api\/v2\/datasets.*\/retention/, [ + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify({ retentionPolicy }) + ]); + + this.server.respondWith(/\/api\/v2\/list.*\/platforms/, function(xhr) { + xhr.respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify({ + platforms: [ + { + name: DatasetPlatform.HDFS, + supportedPurgePolicies: [PurgePolicy.AutoLimitedRetention, PurgePolicy.AutoPurge] + } + ] + }) + ); + }); + + this.render(hbs`{{datasets/containers/upstream-dataset urn=urn platform=platform}}`); + + await waitUntil(() => find(upstreamElement)); + + assert.equal(find(upstreamElement).textContent.trim(), 'A nativeName'); }); diff --git a/wherehows-web/tests/integration/components/datasets/upstream-dataset-test.js b/wherehows-web/tests/integration/components/datasets/upstream-dataset-test.js index ea6f8d35fe..cff0910a5c 100644 --- a/wherehows-web/tests/integration/components/datasets/upstream-dataset-test.js +++ b/wherehows-web/tests/integration/components/datasets/upstream-dataset-test.js @@ -9,40 +9,14 @@ moduleForComponent('datasets/upstream-dataset', 'Integration | Component | datas test('it renders', function(assert) { this.render(hbs`{{datasets/upstream-dataset}}`); - assert.ok(document.querySelector('.upstream-dataset-banner'), 'renders upstream-dataset as expected'); + assert.ok(document.querySelector('.upstream-downstream-retention'), 'renders upstream-dataset as expected'); }); test('it renders upstream dataset properties', function(assert) { - const titleElementQuery = '.upstream-dataset-banner__title strong'; - const descriptionElementQuery = '.upstream-dataset-banner__description strong'; - const nativeName = 'Upstream Dataset'; - const description = 'Upstream Dataset Description'; + const upstreamLink = '.upstream-dataset__upstream-link'; + const upstreamsMetadata = [{}, {}]; + this.set('upstreamsMetadata', upstreamsMetadata); + this.render(hbs`{{datasets/upstream-dataset upstreamsMetadata=upstreamsMetadata}}`); - this.set('nativeName', nativeName); - this.set('description', description); - - this.render(hbs`{{datasets/upstream-dataset nativeName=nativeName description=description}}`); - - assert.ok( - document - .querySelector(titleElementQuery) - .textContent.trim() - .includes(nativeName), - 'renders nativeName' - ); - assert.ok( - document - .querySelector(descriptionElementQuery) - .textContent.trim() - .includes(description), - 'renders description' - ); -}); - -test('it creates a link to the upstream dataset', function(assert) { - this.set('upstreamUrn', hdfsUrn); - - this.render(hbs`{{datasets/upstream-dataset upstreamUrn=upstreamUrn}}`); - - assert.ok(document.querySelector('.upstream-dataset-banner a'), 'anchor element is rendered'); + assert.equal(document.querySelectorAll(upstreamLink).length, 2, 'renders a link for each upstream dataset'); }); diff --git a/wherehows-web/tests/integration/components/purge-policy-test.js b/wherehows-web/tests/integration/components/purge-policy-test.js index ca4bb752ce..aab0a777a6 100644 --- a/wherehows-web/tests/integration/components/purge-policy-test.js +++ b/wherehows-web/tests/integration/components/purge-policy-test.js @@ -3,13 +3,7 @@ import hbs from 'htmlbars-inline-precompile'; import { triggerEvent } from 'ember-native-dom-helpers'; import sinon from 'sinon'; -import { - missingPolicyText, - purgePolicyProps, - exemptPolicy, - PurgePolicy, - getSupportedPurgePolicies -} from 'wherehows-web/constants'; +import { purgePolicyProps, exemptPolicy, PurgePolicy, getSupportedPurgePolicies } from 'wherehows-web/constants'; import { DatasetPlatform } from 'wherehows-web/constants/datasets/platform'; import platforms from 'wherehows-web/mirage/fixtures/list-platforms'; import { ApiStatus } from 'wherehows-web/utils/api'; @@ -28,6 +22,7 @@ moduleForComponent('purge-policy', 'Integration | Component | purge policy', { const policyList = '.purge-policy-list'; const policyTypes = Object.keys(purgePolicyProps); +const missingPolicyText = 'No policy'; test('it renders', function(assert) { assert.expect(1); @@ -70,9 +65,11 @@ test('it triggers the onPolicyChange action', function(assert) { test('it renders a user message if the purge policy is not set and is in readonly mode', function(assert) { assert.expect(1); - this.render(hbs`{{purge-policy}}`); + this.set('missingPolicyText', missingPolicyText); + this.set('isEditable', false); + this.render(hbs`{{purge-policy missingPolicyText=missingPolicyText isEditable=isEditable}}`); assert.equal( - document.querySelector(`${policyList} p`).textContent, + document.querySelector(`${policyList}`).textContent.trim(), missingPolicyText, `${missingPolicyText} is rendered` );