Skip to content

Commit

Permalink
feat(orga): improve error message after learner import
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Dec 18, 2024
1 parent d0ab904 commit 37929ae
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
6 changes: 4 additions & 2 deletions orga/app/components/import/banner.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class ImportBanner extends Component {
}

get anchorMessage() {
if (this.args.organizationImportDetail?.hasError) {
if (this.args.organizationImportDetail?.hasFixableErrors) {
return this.intl.t('pages.organization-participants-import.banner.anchor-error');
}
return null;
Expand All @@ -87,7 +87,9 @@ export default class ImportBanner extends Component {

get actionMessage() {
if (this.args.organizationImportDetail?.hasError)
return this.intl.t('pages.organization-participants-import.banner.error-text');
if (this.args.organizationImportDetail?.hasFixableErrors)
return this.intl.t('pages.organization-participants-import.banner.fix-error-text');
else return this.intl.t('pages.organization-participants-import.banner.retry-error-text');
return this.intl.t('pages.organization-participants-import.banner.in-progress-text');
}

Expand Down
1 change: 1 addition & 0 deletions orga/app/models/organization-import-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class OrganizationImportDetail extends Model {
@attr('date') createdAt;
@attr('date') updatedAt;
@attr() errors;
@attr() hasFixableErrors;
@attr() createdBy;

get hasError() {
Expand Down
26 changes: 20 additions & 6 deletions orga/tests/integration/components/import/banner_test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,15 @@ module('Integration | Component | Import::Banner', function (hooks) {
});

module('errors', function () {
test('display validation error banner when validation failed', async function (assert) {
test('display validation error banner when validation failed (fix)', async function (assert) {
const store = this.owner.lookup('service:store');
const createdAt = new Date(2023, 1, 10);
const organizationImportDetail = store.createRecord('organization-import-detail', {
status: 'VALIDATION_ERROR',
createdAt,
createdBy: { firstName: 'Dark', lastName: 'Vador' },
errors: [{ code: 'UAI_MISMATCHED', meta: {} }],
errors: [{ meta: [{ code: 'UAI_MISMATCHED' }], name: 'AggregateImportError' }],
hasFixableErrors: true,
});
// when
const isLoading = false;
Expand All @@ -226,6 +227,7 @@ module('Integration | Component | Import::Banner', function (hooks) {
exact: false,
}),
);
assert.ok(screen.getByRole('link', { name: t('pages.organization-participants-import.banner.anchor-error') }));
assert.ok(
screen.getByText(
t('pages.organization-participants-import.banner.upload-completed', {
Expand All @@ -237,17 +239,23 @@ module('Integration | Component | Import::Banner', function (hooks) {
),
);

assert.ok(screen.getByText(t('pages.organization-participants-import.banner.error-text'), { exact: false }));
assert.ok(screen.getByText(t('pages.organization-participants-import.banner.fix-error-text'), { exact: false }));
});

test('display import error banner when import failed', async function (assert) {
test('display import error banner when import failed (retry)', async function (assert) {
const store = this.owner.lookup('service:store');
const createdAt = new Date(2023, 1, 10);
const organizationImportDetail = store.createRecord('organization-import-detail', {
status: 'IMPORT_ERROR',
createdAt,
createdBy: { firstName: 'Dark', lastName: 'Vador' },
errors: [{ code: 'ERROR', meta: {} }],
errors: [
{
name: 'OrganizationLearnersCouldNotBeSavedError',
message: 'An error occurred during process',
},
],
hasFixableErrors: false,
});
// when
const isLoading = false;
Expand All @@ -262,6 +270,9 @@ module('Integration | Component | Import::Banner', function (hooks) {
exact: false,
}),
);
assert.notOk(
screen.queryByRole('link', { name: t('pages.organization-participants-import.banner.anchor-error') }),
);
assert.ok(
screen.getByText(
t('pages.organization-participants-import.banner.upload-completed', {
Expand All @@ -272,7 +283,9 @@ module('Integration | Component | Import::Banner', function (hooks) {
{ exact: false },
),
);
assert.ok(screen.getByText(t('pages.organization-participants-import.banner.error-text'), { exact: false }));
assert.ok(
screen.getByText(t('pages.organization-participants-import.banner.retry-error-text'), { exact: false }),
);
});
});

Expand All @@ -285,6 +298,7 @@ module('Integration | Component | Import::Banner', function (hooks) {
createdAt,
createdBy: { firstName: 'Dark', lastName: 'Vador' },
errors: [{ code: 'ERROR', meta: {} }],
hasFixableErrors: true,
});
// when
const isLoading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module('Unit | Model | organization-import-detail', function (hooks) {
assert.ok(model.isDone);
});
['UPLOADED', 'VALIDATED', 'UPLOAD_ERROR', 'VALIDATION_ERROR', 'IMPORT_ERROR'].forEach((status) => {
test('it should return false', function (assert) {
test(`it should return false ${status}`, function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('organization-import-detail', {
status,
Expand All @@ -61,7 +61,7 @@ module('Unit | Model | organization-import-detail', function (hooks) {
});
module('inProgress', function () {
['UPLOADED', 'VALIDATED'].forEach((status) => {
test('it should return true', function (assert) {
test(`it should return true - ${status}`, function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('organization-import-detail', {
status,
Expand All @@ -70,7 +70,7 @@ module('Unit | Model | organization-import-detail', function (hooks) {
});
});
['UPLOAD_ERROR', 'VALIDATION_ERROR', 'IMPORT_ERROR', 'IMPORTED'].forEach((status) => {
test('it should return false', function (assert) {
test(`it should return false - ${status}`, function (assert) {
const store = this.owner.lookup('service:store');
const model = store.createRecord('organization-import-detail', {
status,
Expand Down
3 changes: 2 additions & 1 deletion orga/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,11 @@
},
"banner": {
"anchor-error": "See the list of errors",
"error-text": "Please correct them and import the file again.",
"fix-error-text": "Please correct them and import the file again.",
"import-error": "The import of participants has failed.",
"import-in-progress": "The content of the file has been validated and the participants are now being imported in PixOrga.",
"in-progress-text": "Please refresh this page in a few moments to see the status of the file.",
"retry-error-text": "An error has occurred, please import later or write to Pix support",
"upload-completed": "The file was imported on {date} by {firstName} {lastName}.",
"upload-error": "The file could not be imported.",
"upload-in-progress": "It may take a few minutes to import the file. Please do not leave this page.",
Expand Down
3 changes: 2 additions & 1 deletion orga/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1190,10 +1190,11 @@
},
"banner": {
"anchor-error": "Voir la liste des erreurs",
"error-text": "Merci de corriger les erreurs et d’importer à nouveau le fichier.",
"fix-error-text": "Merci de corriger les erreurs et d’importer à nouveau le fichier.",
"import-error": "L'import des participants a échoué.",
"import-in-progress": "Le contenu du fichier est validé, l’import des participants est en cours.",
"in-progress-text": "Merci de rafraîchir cette page dans quelques instants pour connaitre l’état de traitement du fichier.",
"retry-error-text": "Une erreur est survenue, merci d'importer plus tard ou d'écrire au support Pix",
"upload-completed": "Le fichier a été importé le {date} par {firstName} {lastName}.",
"upload-error": "Le fichier n'a pas pu être importé.",
"upload-in-progress": "L’import du fichier peut prendre quelques minutes. Merci de ne pas quitter cette page.",
Expand Down
3 changes: 2 additions & 1 deletion orga/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,8 @@
},
"banner": {
"anchor-error": "De lijst met foutmeldingen bekijken",
"error-text": "Corrigeer de fouten en importeer het bestand opnieuw.",
"fix-error-text": "Corrigeer de fouten en importeer het bestand opnieuw.",
"retry-error-text": "Er is een fout opgetreden, importeer later of schrijf naar Pix support.",
"import-error": "De import van deelnemers is mislukt.",
"import-in-progress": "De inhoud van het bestand is gevalideerd en de deelnemers worden geïmporteerd.",
"in-progress-text": "Vernieuw deze pagina over enkele ogenblikken om de status van het bestand te controleren.",
Expand Down

0 comments on commit 37929ae

Please sign in to comment.