From e7a349624502d00be5b487d35e6078fbe9c89dac Mon Sep 17 00:00:00 2001 From: Brian Pilati Date: Tue, 17 Sep 2024 13:17:21 -0500 Subject: [PATCH 1/2] Updates to add the project total --- .../total-count-kpi-wrapper/component.ts | 15 +++++++++++++-- translations/en-us.yml | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/institutions/dashboard/-components/total-count-kpi-wrapper/component.ts b/app/institutions/dashboard/-components/total-count-kpi-wrapper/component.ts index e3d118b7c1..a6e3aabe0c 100644 --- a/app/institutions/dashboard/-components/total-count-kpi-wrapper/component.ts +++ b/app/institutions/dashboard/-components/total-count-kpi-wrapper/component.ts @@ -5,6 +5,7 @@ import { task } from 'ember-concurrency'; import { taskFor } from 'ember-concurrency-ts'; import Intl from 'ember-intl/services/intl'; import { inject as service } from '@ember/service'; +import InstitutionSummaryMetricModel from 'ember-osf-web/models/institution-summary-metric'; interface TotalCountKpiWrapperArgs { model: any; @@ -28,6 +29,17 @@ export default class TotalCountKpiWrapperComponent extends Component Date: Wed, 18 Sep 2024 09:29:06 -0500 Subject: [PATCH 2/2] Added a test with test-data elements --- .../total-count-kpi-wrapper/component-test.ts | 78 +++++++++++++++++++ .../total-count-kpi-wrapper/template.hbs | 2 +- .../total-count-kpi/template.hbs | 2 +- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 app/institutions/dashboard/-components/total-count-kpi-wrapper/component-test.ts diff --git a/app/institutions/dashboard/-components/total-count-kpi-wrapper/component-test.ts b/app/institutions/dashboard/-components/total-count-kpi-wrapper/component-test.ts new file mode 100644 index 0000000000..bf62bc24e9 --- /dev/null +++ b/app/institutions/dashboard/-components/total-count-kpi-wrapper/component-test.ts @@ -0,0 +1,78 @@ +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; +import { setupMirage } from 'ember-cli-mirage/test-support'; +import { setupIntl } from 'ember-intl/test-support'; +import { setupRenderingTest } from 'ember-qunit'; +import { TestContext } from 'ember-test-helpers'; +import { module, test } from 'qunit'; + +module('Integration | institutions | dashboard | -components | total-count-kpi-wrapper', hooks => { + setupRenderingTest(hooks); + setupMirage(hooks); + setupIntl(hooks); + + hooks.beforeEach(function(this: TestContext) { + const model = Object({ + summaryMetrics: { + userCount: 10, + privateProjectCount: 10, + publicProjectCount: 10, + }, + }); + + this.set('model', model); + }); + + test('it renders the dashboard total kpis correctly', async assert => { + // Given the component is rendered + await render(hbs` + +`); + + // Then the first total kpi is tested + assert.dom('[data-test-total-count-kpi="0"]') + .exists('The User Widget exists'); + + assert.dom('[data-test-total-count-kpi="0"]') + .hasText('10 Total Users'); + + assert.dom('[data-test-total-count-kpi="0"] [data-test-kpi-icon]') + .hasAttribute('data-icon', 'building'); + + // And the second total kpi is tested + assert.dom('[data-test-total-count-kpi="1"]') + .exists('The Project Widget exists'); + + assert.dom('[data-test-total-count-kpi="1"]') + .hasText('20 OSF Public and Private Projects'); + + assert.dom('[data-test-total-count-kpi="1"] [data-test-kpi-icon]') + .hasAttribute('data-icon', 'atom'); + + // And the third total kpi is tested + assert.dom('[data-test-total-count-kpi="2"]') + .exists('The Registration Widget exists'); + + assert.dom('[data-test-total-count-kpi="2"]') + .hasText('1000 OSF Registrations'); + + assert.dom('[data-test-total-count-kpi="2"] [data-test-kpi-icon]') + .hasAttribute('data-icon', 'flag'); + + // And the fourth total kpi is tested + assert.dom('[data-test-total-count-kpi="3"]') + .exists('The Preprint Widget exists'); + + assert.dom('[data-test-total-count-kpi="3"]') + .hasText('10000 OSF Preprints'); + + assert.dom('[data-test-total-count-kpi="3"] [data-test-kpi-icon]') + .hasAttribute('data-icon', 'file-alt'); + + // Finally there are only 4 widgets + assert.dom('[data-test-total-count-kpi="4"]') + .doesNotExist('There are only 4 widgets'); + }); +}); diff --git a/app/institutions/dashboard/-components/total-count-kpi-wrapper/template.hbs b/app/institutions/dashboard/-components/total-count-kpi-wrapper/template.hbs index 8f57d9d5f6..943bca4037 100644 --- a/app/institutions/dashboard/-components/total-count-kpi-wrapper/template.hbs +++ b/app/institutions/dashboard/-components/total-count-kpi-wrapper/template.hbs @@ -1,6 +1,6 @@
{{#if this.isLoading}} -
+
{{else}} diff --git a/app/institutions/dashboard/-components/total-count-kpi-wrapper/total-count-kpi/template.hbs b/app/institutions/dashboard/-components/total-count-kpi-wrapper/total-count-kpi/template.hbs index cfbd4d321b..fb277c08c8 100644 --- a/app/institutions/dashboard/-components/total-count-kpi-wrapper/total-count-kpi/template.hbs +++ b/app/institutions/dashboard/-components/total-count-kpi-wrapper/total-count-kpi/template.hbs @@ -1,4 +1,4 @@ -
+
{{#if @data.total}}