diff --git a/orga/app/components/campaign/charts/participants-by-day.gjs b/orga/app/components/campaign/charts/participants-by-day.gjs
index 27d7ea716ac..3b579317385 100644
--- a/orga/app/components/campaign/charts/participants-by-day.gjs
+++ b/orga/app/components/campaign/charts/participants-by-day.gjs
@@ -135,18 +135,24 @@ export default class ParticipantsByDay extends Component {
get datasets() {
let startedLabel = '';
let sharedLabel = '';
+ let startedCaption = '';
+ let sharedCaption = '';
if (this.args.isTypeAssessment) {
+ startedCaption = LABELS_ASSESSMENT.started.caption;
startedLabel = LABELS_ASSESSMENT.started.a11y;
+ sharedCaption = LABELS_ASSESSMENT.shared.caption;
sharedLabel = LABELS_ASSESSMENT.shared.a11y;
} else {
+ startedCaption = LABELS_PROFILE_COLLECTIONS.started.caption;
startedLabel = LABELS_PROFILE_COLLECTIONS.started.a11y;
+ sharedCaption = LABELS_PROFILE_COLLECTIONS.shared.caption;
sharedLabel = LABELS_PROFILE_COLLECTIONS.shared.a11y;
}
return [
- { entries: this.startedDatasets, countLabel: startedLabel },
- { entries: this.sharedDatasets, countLabel: sharedLabel },
+ { caption: startedCaption, entries: this.startedDatasets, countLabel: startedLabel },
+ { caption: sharedCaption, entries: this.sharedDatasets, countLabel: sharedLabel },
];
}
@@ -165,6 +171,7 @@ export default class ParticipantsByDay extends Component {
{{#each this.datasets as |dataset|}}
+ {{t dataset.caption}}
{{t "charts.participants-by-day.labels-a11y.date"}}
@@ -188,10 +195,12 @@ export default class ParticipantsByDay extends Component {
const LABELS_ASSESSMENT = {
started: {
+ caption: 'charts.participants-by-day.captions.started',
legend: 'charts.participants-by-day.labels-legend.started',
a11y: 'charts.participants-by-day.labels-a11y.started',
},
shared: {
+ caption: 'charts.participants-by-day.captions.shared',
legend: 'charts.participants-by-day.labels-legend.shared',
a11y: 'charts.participants-by-day.labels-a11y.shared',
},
@@ -199,10 +208,12 @@ const LABELS_ASSESSMENT = {
const LABELS_PROFILE_COLLECTIONS = {
started: {
+ caption: 'charts.participants-by-day.captions.started',
legend: 'charts.participants-by-day.labels-legend.started',
a11y: 'charts.participants-by-day.labels-a11y.started',
},
shared: {
+ caption: 'charts.participants-by-day.captions.shared-profile',
legend: 'charts.participants-by-day.labels-legend.shared-profile',
a11y: 'charts.participants-by-day.labels-a11y.shared-profile',
},
diff --git a/orga/tests/integration/components/campaign/charts/participants-by-day-test.js b/orga/tests/integration/components/campaign/charts/participants-by-day-test.js
index d997956968e..2fc6634650c 100644
--- a/orga/tests/integration/components/campaign/charts/participants-by-day-test.js
+++ b/orga/tests/integration/components/campaign/charts/participants-by-day-test.js
@@ -1,5 +1,6 @@
-import { render } from '@1024pix/ember-testing-library';
+import { render, within } from '@1024pix/ember-testing-library';
import { hbs } from 'ember-cli-htmlbars';
+import { t } from 'ember-intl/test-support';
import { module, test } from 'qunit';
import sinon from 'sinon';
@@ -24,7 +25,7 @@ module('Integration | Component | Campaign::Charts::ParticipantsByDay', function
dataFetcher.withArgs(campaignId).resolves({
data: {
attributes: {
- 'started-participations': [{ day: '2021-06-01', count: '1' }],
+ 'started-participations': [],
'shared-participations': [],
},
},
@@ -45,7 +46,7 @@ module('Integration | Component | Campaign::Charts::ParticipantsByDay', function
dataFetcher.withArgs(campaignId).resolves({
data: {
attributes: {
- 'started-participations': [{ day: '2021-06-01', count: '1' }],
+ 'started-participations': [],
'shared-participations': [],
},
},
@@ -60,4 +61,117 @@ module('Integration | Component | Campaign::Charts::ParticipantsByDay', function
assert.ok(screen.getByText('Total des participants'));
assert.ok(screen.getByText('Total des participants ayant envoyé leurs profils'));
});
+
+ test('it should display participants by day', async function (assert) {
+ // given
+ dataFetcher.withArgs(campaignId).resolves({
+ data: {
+ attributes: {
+ 'started-participations': [{ day: '2021-06-01', count: '1' }],
+ 'shared-participations': [{ day: '2021-06-01', count: '2' }],
+ },
+ },
+ });
+
+ // when
+ const screen = await render(
+ hbs``,
+ );
+
+ const { startedTable, sharedTable } = getTables(screen);
+
+ assert.ok(within(startedTable).getByText('1'));
+ assert.ok(within(sharedTable).getByText('2'));
+ });
+
+ test('should start shared participations to 0 when there is at least one shared participant', async function (assert) {
+ // given
+ dataFetcher.withArgs(campaignId).resolves({
+ data: {
+ attributes: {
+ 'started-participations': [{ day: '2021-06-01', count: '1' }],
+ 'shared-participations': [{ day: '2021-06-02', count: '1' }],
+ },
+ },
+ });
+
+ // when
+ const screen = await render(
+ hbs``,
+ );
+
+ const { sharedTable } = getTables(screen);
+
+ assert.ok(within(getRowByCellValue(sharedTable, '01/06/2021')).getByRole('cell', { name: 0 }));
+ assert.ok(within(getRowByCellValue(sharedTable, '02/06/2021')).getByRole('cell', { name: 1 }));
+ });
+
+ module('When last started participation is after the last shared one', () => {
+ test('should add the last started participation to shared participations', async function (assert) {
+ // given
+ dataFetcher.withArgs(campaignId).resolves({
+ data: {
+ attributes: {
+ 'started-participations': [
+ { day: '2021-06-01', count: '1' },
+ { day: '2021-06-03', count: '2' },
+ ],
+ 'shared-participations': [{ day: '2021-06-01', count: '1' }],
+ },
+ },
+ });
+
+ // when
+ const screen = await render(
+ hbs``,
+ );
+
+ const { sharedTable } = getTables(screen);
+
+ assert.ok(within(getRowByCellValue(sharedTable, '01/06/2021')).getByRole('cell', { name: 1 }));
+ assert.ok(within(getRowByCellValue(sharedTable, '03/06/2021')).getByRole('cell', { name: 1 }));
+ });
+ });
+
+ module('When last shared participation is after the last started one', () => {
+ test('should add the last shared participation to started participations', async function (assert) {
+ // given
+ dataFetcher.withArgs(campaignId).resolves({
+ data: {
+ attributes: {
+ 'started-participations': [{ day: '2021-06-01', count: '2' }],
+ 'shared-participations': [
+ { day: '2021-06-01', count: '1' },
+ { day: '2021-06-03', count: '1' },
+ ],
+ },
+ },
+ });
+
+ // when
+ const screen = await render(
+ hbs``,
+ );
+
+ const { startedTable } = getTables(screen);
+
+ assert.ok(within(getRowByCellValue(startedTable, '01/06/2021')).getByRole('cell', { name: 2 }));
+ assert.ok(within(getRowByCellValue(startedTable, '03/06/2021')).getByRole('cell', { name: 2 }));
+ });
+ });
});
+
+function getRowByCellValue(table, cellValue) {
+ return within(table).getByRole('cell', { name: cellValue }).closest('tr');
+}
+
+function getTables(screen) {
+ const startedTable = screen
+ .getByRole('caption', { name: t('charts.participants-by-day.captions.started') })
+ .closest('table');
+ const sharedTable = screen
+ .getByRole('caption', { name: t('charts.participants-by-day.captions.shared') })
+ .closest('table');
+
+ return { startedTable, sharedTable };
+}
diff --git a/orga/tests/unit/components/campaign/charts/participants-by-day-test.js b/orga/tests/unit/components/campaign/charts/participants-by-day-test.js
deleted file mode 100644
index 5a4918e7ffe..00000000000
--- a/orga/tests/unit/components/campaign/charts/participants-by-day-test.js
+++ /dev/null
@@ -1,108 +0,0 @@
-import { setupTest } from 'ember-qunit';
-import { module, test } from 'qunit';
-import sinon from 'sinon';
-
-import createGlimmerComponent from '../../../../helpers/create-glimmer-component';
-
-module('Unit | Component | Campaign::Charts::ParticipantsByDay', (hooks) => {
- setupTest(hooks);
- let component, dataFetcher;
-
- hooks.beforeEach(function () {
- const store = this.owner.lookup('service:store');
- const adapter = store.adapterFor('campaign-stats');
- dataFetcher = sinon.stub(adapter, 'getParticipationsByDay');
- });
-
- test('should fill the default datasets', async function (assert) {
- // given
- dataFetcher.resolves({
- data: {
- attributes: {
- 'started-participations': [{ day: '2021-06-01', count: '1' }],
- 'shared-participations': [{ day: '2021-06-01', count: '1' }],
- },
- },
- });
-
- // when
- component = await createGlimmerComponent('component:campaign/charts/participants-by-day');
-
- // then
- assert.deepEqual(component.startedDatasets, [{ day: '2021-06-01', count: '1' }]);
- assert.deepEqual(component.sharedDatasets, [{ day: '2021-06-01', count: '1' }]);
- });
-
- test('should start shared participations to 0 when there is at least one shared participant', async function (assert) {
- // given
- dataFetcher.resolves({
- data: {
- attributes: {
- 'started-participations': [{ day: '2021-06-01', count: '1' }],
- 'shared-participations': [{ day: '2021-06-02', count: '1' }],
- },
- },
- });
-
- // when
- component = await createGlimmerComponent('component:campaign/charts/participants-by-day');
-
- // then
- assert.deepEqual(component.sharedDatasets, [
- { day: '2021-06-01', count: '0' },
- { day: '2021-06-02', count: '1' },
- ]);
- });
-
- module('When last started participation is after the last shared one', () => {
- test('should add the last started participation to shared participations', async function (assert) {
- // given
- dataFetcher.resolves({
- data: {
- attributes: {
- 'started-participations': [
- { day: '2021-06-01', count: '1' },
- { day: '2021-06-03', count: '2' },
- ],
- 'shared-participations': [{ day: '2021-06-01', count: '1' }],
- },
- },
- });
-
- // when
- component = await createGlimmerComponent('component:campaign/charts/participants-by-day');
-
- // then
- assert.deepEqual(component.sharedDatasets, [
- { day: '2021-06-01', count: '1' },
- { day: '2021-06-03', count: '1' },
- ]);
- });
- });
-
- module('When last shared participation is after the last started one', () => {
- test('should add the last shared participation to started participations', async function (assert) {
- // given
- dataFetcher.resolves({
- data: {
- attributes: {
- 'started-participations': [{ day: '2021-06-01', count: '2' }],
- 'shared-participations': [
- { day: '2021-06-01', count: '1' },
- { day: '2021-06-03', count: '1' },
- ],
- },
- },
- });
-
- // when
- component = await createGlimmerComponent('component:campaign/charts/participants-by-day');
-
- // then
- assert.deepEqual(component.startedDatasets, [
- { day: '2021-06-01', count: '2' },
- { day: '2021-06-03', count: '2' },
- ]);
- });
- });
-});
diff --git a/orga/translations/en.json b/orga/translations/en.json
index a4498e308c0..1bf7fd2fd26 100644
--- a/orga/translations/en.json
+++ b/orga/translations/en.json
@@ -128,6 +128,11 @@
"charts": {
"participants-by-day": {
"title": "Participant's activity",
+ "captions": {
+ "shared": "Submitted results by day",
+ "shared-profile": "Submitted profiles by day",
+ "started": "Total participants by day"
+ },
"labels-a11y": {
"date": "Date",
"shared": "Submitted results",
diff --git a/orga/translations/fr.json b/orga/translations/fr.json
index facf5b9b644..a833a2f66d5 100644
--- a/orga/translations/fr.json
+++ b/orga/translations/fr.json
@@ -131,6 +131,11 @@
"charts": {
"participants-by-day": {
"title": "Activité des participants",
+ "captions": {
+ "shared": "Total de participants par jour ayant envoyé leurs résultats par jour",
+ "shared-profile": "Total de participants ayant envoyé leurs profils par jour",
+ "started": "Total de participants par jour"
+ },
"labels-a11y": {
"date": "Date",
"shared": "Total des participants ayant envoyé leurs résultats",