Skip to content

Commit

Permalink
fix(admin): fix publication buttons reactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecoin committed Dec 13, 2024
1 parent c17f912 commit d0b899a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export default class ListController extends Controller {
this.pixToast.sendSuccessNotification({ message: 'Les certifications ont été correctement dépubliées.' });
} catch (e) {
this.notifyError(e);
} finally {
await this.forceRefreshModelFromBackend();
}
this.hideConfirmationModal();
}
Expand All @@ -70,6 +72,7 @@ export default class ListController extends Controller {
await this.model.session.save({ adapterOptions: { updatePublishedCertifications: true, toPublish: true } });
} catch (e) {
this.notifyError(e);
} finally {
await this.forceRefreshModelFromBackend();
}

Expand Down
4 changes: 2 additions & 2 deletions admin/app/models/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export default class Session extends Model {
return Boolean(this.hasIncident || this.hasJoiningIssue);
}

@computed('status')
@computed('publishedAt')
get isPublished() {
return this.status === PROCESSED;
return this.publishedAt !== null;
}

@computed('juryCertificationSummaries.[]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module('Acceptance | authenticated/sessions/session/certifications', function (h
setupMirage(hooks);

module('When user has role metier', function () {
test('it should not show publish button', async function (assert) {
test('it should not show the publication button', async function (assert) {
// given
await authenticateAdminMemberWithRole({ isMetier: true })(server);
server.create('session', { id: '1' });
Expand All @@ -25,6 +25,42 @@ module('Acceptance | authenticated/sessions/session/certifications', function (h
});
});

module('When user has role certif', function () {
test('the session can be published', async function (assert) {
// given
await authenticateAdminMemberWithRole({ isCertif: true })(server);

const juryCertificationSummary = server.create('jury-certification-summary', {
status: 'ok',
isCancelled: false,
});
server.create('session', {
id: '1',
finalizedAt: '2020-01-01',
publishedAt: null,
status: 'finalized',
juryCertificationSummaries: [juryCertificationSummary],
});

const screen = await visit('/sessions/1/certifications');

this.server.get('/admin/sessions/:id', (schema, request) => {
const sessionId = request.params.id;
const session = schema.sessions.findBy({ id: sessionId });
return session.update({ publishedAt: '2020-01-01' });
});

// when
await click(screen.getByRole('button', { name: 'Publier la session' }));
await screen.findByRole('dialog');
await click(screen.getByRole('button', { name: 'Confirmer' }));

// then
assert.dom(await screen.queryByText('Publier la session')).doesNotExist();
assert.dom(await screen.getByText('Dépublier la session')).exists();
});
});

module('When requesting next page from pagination', function () {
test('it should display next page jury certificate summary', async function (assert) {
await authenticateAdminMemberWithRole({ isSuperAdmin: true })(server);
Expand Down

0 comments on commit d0b899a

Please sign in to comment.