diff --git a/mon-pix/app/components/tabs/index.gjs b/mon-pix/app/components/tabs/index.gjs
index 58209cdb397..0e6208b909a 100644
--- a/mon-pix/app/components/tabs/index.gjs
+++ b/mon-pix/app/components/tabs/index.gjs
@@ -1,7 +1,7 @@
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import { guidFor } from '@ember/object/internals';
-import { inject as service } from '@ember/service';
+import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { modifier } from 'ember-modifier';
@@ -11,11 +11,11 @@ import TabPanel from './tab-panel';
export default class TabsContainer extends Component {
@service elementHelper;
+ @service tabManager;
TabPanel = TabPanel;
TabItem = TabItem;
- @tracked currentTabIndex = this.args.initialTabIndex || 0;
@tracked hasScrollableTablist = false;
@tracked isLeftArrowVisible = false;
@tracked isRightArrowVisible = false;
@@ -26,6 +26,7 @@ export default class TabsContainer extends Component {
};
onMount = modifier((element) => {
+ this.args.initialTabIndex && this.tabManager.setActiveTab(this.args.initialTabIndex);
this.elements.tabs = element.querySelectorAll("[role='tab']");
this.elements.tablist = element.querySelector("[role='tablist'] > div");
@@ -66,7 +67,7 @@ export default class TabsContainer extends Component {
}
break;
}
-
+ this.tabManager.setActiveTab(nextTabIndex);
const tabToFocus = document.getElementById(this.id + '-' + nextTabIndex);
tabToFocus.focus();
@@ -76,8 +77,9 @@ export default class TabsContainer extends Component {
@action
handleTabChange(tabIndex) {
- if (tabIndex !== this.currentTabIndex) {
- this.currentTabIndex = tabIndex;
+ if (tabIndex !== this.tabManager.activeTab) {
+ this.tabManager.setActiveTab(tabIndex);
+
this.args.onTabChange && this.args.onTabChange(tabIndex);
}
}
@@ -89,7 +91,7 @@ export default class TabsContainer extends Component {
if (this.hasScrollableTablist) {
this.handleTablistArrowsVisibility();
- const currentTab = this.elements.tabs[this.currentTabIndex];
+ const currentTab = this.elements.tabs[this.tabManager.activeTab];
this.scrollToTab(currentTab, 'instant');
} else {
this.isLeftArrowVisible = false;
@@ -175,7 +177,7 @@ export default class TabsContainer extends Component {
{{/if}}
{{yield
- (component this.TabItem currentTab=this.currentTabIndex id=this.id onTabClick=this.handleTabChange)
+ (component this.TabItem currentTab=this.tabManager.activeTab id=this.id onTabClick=this.handleTabChange)
to="tabs"
}}
@@ -188,7 +190,7 @@ export default class TabsContainer extends Component {
{{/if}}
- {{yield (component this.TabPanel currentTab=this.currentTabIndex id=this.id) to="panels"}}
+ {{yield (component this.TabPanel currentTab=this.tabManager.activeTab id=this.id) to="panels"}}
}
diff --git a/mon-pix/app/services/tab-manager.js b/mon-pix/app/services/tab-manager.js
new file mode 100644
index 00000000000..3122fb7c750
--- /dev/null
+++ b/mon-pix/app/services/tab-manager.js
@@ -0,0 +1,10 @@
+import Service from '@ember/service';
+import { tracked } from '@glimmer/tracking';
+
+export default class TabManagerService extends Service {
+ @tracked activeTab = 0;
+
+ setActiveTab(tab) {
+ this.activeTab = tab;
+ }
+}
diff --git a/mon-pix/tests/integration/components/routes/campaigns/assessment/evaluation-results-test.js b/mon-pix/tests/integration/components/routes/campaigns/assessment/evaluation-results-test.js
index db6203a52d1..3d8514acefd 100644
--- a/mon-pix/tests/integration/components/routes/campaigns/assessment/evaluation-results-test.js
+++ b/mon-pix/tests/integration/components/routes/campaigns/assessment/evaluation-results-test.js
@@ -1,4 +1,5 @@
import { render } from '@1024pix/ember-testing-library';
+import { click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { t } from 'ember-intl/test-support';
import { module, test } from 'qunit';
@@ -53,4 +54,32 @@ module('Integration | Components | Routes | Campaigns | Assessment | Evaluation
assert.dom(screen.getByRole('tablist', { name: t('pages.skill-review.tabs.aria-label') })).exists();
});
});
+
+ module('when the campaign is shared and has trainings', function (hooks) {
+ hooks.beforeEach(async function () {
+ // given
+ this.model.trainings = [{ duration: { days: 1, hours: 1, minutes: 1 } }];
+ this.model.campaignParticipationResult.isShared = true;
+ this.model.campaignParticipationResult.competenceResults = [Symbol('competences')];
+ });
+
+ test('it should display the training button', async function (assert) {
+ // when
+ screen = await render(hbs`