Skip to content

Commit

Permalink
chore(orga): remove component unit tests for Integration | Component …
Browse files Browse the repository at this point in the history
…| Campaign::Charts::ParticipantsByDay
  • Loading branch information
frinyvonnick committed Sep 24, 2024
1 parent 4759bce commit fc3399c
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 113 deletions.
15 changes: 13 additions & 2 deletions orga/app/components/campaign/charts/participants-by-day.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
];
}

Expand All @@ -165,6 +171,7 @@ export default class ParticipantsByDay extends Component {

{{#each this.datasets as |dataset|}}
<table class="screen-reader-only">
<caption>{{t dataset.caption}}</caption>
<thead>
<tr>
<TableHeader>{{t "charts.participants-by-day.labels-a11y.date"}}</TableHeader>
Expand All @@ -188,21 +195,25 @@ 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',
},
};

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',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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': [],
},
},
Expand All @@ -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': [],
},
},
Expand All @@ -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`<Campaign::Charts::ParticipantsByDay @campaignId={{this.campaignId}} @isTypeAssessment={{true}} />`,
);

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`<Campaign::Charts::ParticipantsByDay @campaignId={{this.campaignId}} @isTypeAssessment={{true}} />`,
);

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`<Campaign::Charts::ParticipantsByDay @campaignId={{this.campaignId}} @isTypeAssessment={{true}} />`,
);

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`<Campaign::Charts::ParticipantsByDay @campaignId={{this.campaignId}} @isTypeAssessment={{true}} />`,
);

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 };
}
108 changes: 0 additions & 108 deletions orga/tests/unit/components/campaign/charts/participants-by-day-test.js

This file was deleted.

5 changes: 5 additions & 0 deletions orga/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions orga/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fc3399c

Please sign in to comment.