diff --git a/mon-pix/app/components/authentication/other-authentication-providers.gjs b/mon-pix/app/components/authentication/other-authentication-providers.gjs
index 8020f7a1bda..1019ada52fb 100644
--- a/mon-pix/app/components/authentication/other-authentication-providers.gjs
+++ b/mon-pix/app/components/authentication/other-authentication-providers.gjs
@@ -13,52 +13,54 @@ export default class OtherAuthenticationProviders extends Component {
}
-
-
- {{#if @isForSignup}}
- {{t "components.authentication.other-authentication-providers.signup.heading"}}
- {{else}}
- {{t "components.authentication.other-authentication-providers.login.heading"}}
- {{/if}}
-
-
- {{#if this.oidcIdentityProviders.featuredIdentityProvider}}
-
-
+ {{#if this.oidcIdentityProviders.hasIdentityProviders}}
+
+
{{#if @isForSignup}}
- {{t
- "components.authentication.other-authentication-providers.signup.signup-with-featured-identity-provider-link"
- featuredIdentityProvider=this.oidcIdentityProviders.featuredIdentityProvider.organizationName
- }}
+ {{t "components.authentication.other-authentication-providers.signup.heading"}}
{{else}}
- {{t
- "components.authentication.other-authentication-providers.login.login-with-featured-identity-provider-link"
- featuredIdentityProvider=this.oidcIdentityProviders.featuredIdentityProvider.organizationName
- }}
+ {{t "components.authentication.other-authentication-providers.login.heading"}}
{{/if}}
-
- {{/if}}
+
- {{#if this.oidcIdentityProviders.hasOtherIdentityProviders}}
-
- {{t "components.authentication.other-authentication-providers.select-another-organization-link"}}
+ {{#if this.oidcIdentityProviders.featuredIdentityProvider}}
+
+
+ {{#if @isForSignup}}
+ {{t
+ "components.authentication.other-authentication-providers.signup.signup-with-featured-identity-provider-link"
+ featuredIdentityProvider=this.oidcIdentityProviders.featuredIdentityProvider.organizationName
+ }}
+ {{else}}
+ {{t
+ "components.authentication.other-authentication-providers.login.login-with-featured-identity-provider-link"
+ featuredIdentityProvider=this.oidcIdentityProviders.featuredIdentityProvider.organizationName
+ }}
+ {{/if}}
+
+ {{/if}}
-
-
- {{/if}}
-
+ {{#if this.oidcIdentityProviders.hasOtherIdentityProviders}}
+
+ {{t "components.authentication.other-authentication-providers.select-another-organization-link"}}
+
+
+
+ {{/if}}
+
+ {{/if}}
}
diff --git a/mon-pix/app/services/oidc-identity-providers.js b/mon-pix/app/services/oidc-identity-providers.js
index 3ac8ed4a938..66493fc7943 100644
--- a/mon-pix/app/services/oidc-identity-providers.js
+++ b/mon-pix/app/services/oidc-identity-providers.js
@@ -21,6 +21,10 @@ export default class OidcIdentityProviders extends Service {
.map((provider) => provider.organizationName);
}
+ get hasIdentityProviders() {
+ return this.list.length > 0;
+ }
+
// TODO: Manage this through the API
get featuredIdentityProvider() {
return this.list.find((identityProvider) => {
diff --git a/mon-pix/tests/integration/components/authentication/other-authentication-providers-test.gjs b/mon-pix/tests/integration/components/authentication/other-authentication-providers-test.gjs
index 3c05dc2a938..68983ef23e8 100644
--- a/mon-pix/tests/integration/components/authentication/other-authentication-providers-test.gjs
+++ b/mon-pix/tests/integration/components/authentication/other-authentication-providers-test.gjs
@@ -6,52 +6,118 @@ import { module, test } from 'qunit';
import setupIntlRenderingTest from '../../../helpers/setup-intl-rendering';
+class NoOidcIdentityProvidersServiceStub extends Service {
+ get hasIdentityProviders() {
+ return false;
+ }
+
+ get featuredIdentityProvider() {
+ return null;
+ }
+
+ get hasOtherIdentityProviders() {
+ return false;
+ }
+
+ load() {
+ return Promise.resolve();
+ }
+}
+
+class OneFeaturedNoOthersOidcIdentityProvidersServiceStub extends NoOidcIdentityProvidersServiceStub {
+ get hasIdentityProviders() {
+ return true;
+ }
+
+ get featuredIdentityProvider() {
+ return { organizationName: 'Some Identity Provider', slug: 'some-identity-provider' };
+ }
+}
+
+class OneFeaturedOthersOidcIdentityProvidersServiceStub extends OneFeaturedNoOthersOidcIdentityProvidersServiceStub {
+ get hasOtherIdentityProviders() {
+ return true;
+ }
+}
+
module('Integration | Component | Authentication | other-authentication-providers', function (hooks) {
setupIntlRenderingTest(hooks);
- module('when it’s for login', function () {
- test('it displays a login heading', async function (assert) {
- // when
- const screen = await render();
+ module('when there are identity providers', function (hooks) {
+ hooks.beforeEach(function () {
+ this.owner.register('service:oidcIdentityProviders', OneFeaturedNoOthersOidcIdentityProvidersServiceStub);
+ });
- // then
- assert
- .dom(
- screen.getByRole('heading', {
- name: t('components.authentication.other-authentication-providers.login.heading'),
- }),
- )
- .exists();
+ module('when it’s for login', function () {
+ test('it displays a login heading', async function (assert) {
+ // when
+ const screen = await render();
+
+ // then
+ assert
+ .dom(
+ screen.getByRole('heading', {
+ name: t('components.authentication.other-authentication-providers.login.heading'),
+ }),
+ )
+ .exists();
+ });
+ });
+
+ module('when it’s for signup', function () {
+ test('it displays a signup heading', async function (assert) {
+ // when
+ const screen = await render();
+
+ // then
+ assert
+ .dom(
+ screen.getByRole('heading', {
+ name: t('components.authentication.other-authentication-providers.signup.heading'),
+ }),
+ )
+ .exists();
+ });
});
});
- module('when it’s for signup', function () {
- test('it displays a signup heading', async function (assert) {
- // when
- const screen = await render();
+ module('when there are no identity providers', function (hooks) {
+ hooks.beforeEach(function () {
+ this.owner.register('service:oidcIdentityProviders', NoOidcIdentityProvidersServiceStub);
+ });
- // then
- assert
- .dom(
- screen.getByRole('heading', {
- name: t('components.authentication.other-authentication-providers.signup.heading'),
- }),
- )
- .exists();
+ module('when it’s for login', function () {
+ test('it doesn’t display a login heading', async function (assert) {
+ // when
+ const screen = await render();
+
+ // then
+ assert
+ .dom(screen.queryByText(t('components.authentication.other-authentication-providers.login.heading')))
+ .doesNotExist();
+ });
+ });
+
+ module('when it’s for signup', function () {
+ test('it doesn’t display a signup heading', async function (assert) {
+ // when
+ const screen = await render();
+
+ // then
+ assert
+ .dom(screen.queryByText(t('components.authentication.other-authentication-providers.signup.heading')))
+ .doesNotExist();
+ });
});
});
- module('when there is a featured identity provider', function () {
+ module('when there is a featured identity provider', function (hooks) {
+ hooks.beforeEach(function () {
+ this.owner.register('service:oidcIdentityProviders', OneFeaturedNoOthersOidcIdentityProvidersServiceStub);
+ });
+
module('when it’s for login');
test('it displays a login featured identity provider link', async function (assert) {
- // given
- class OidcIdentityProvidersServiceStub extends Service {
- get featuredIdentityProvider() {
- return { organizationName: 'Some Identity Provider', slug: 'some-identity-provider' };
- }
- }
- this.owner.register('service:oidcIdentityProviders', OidcIdentityProvidersServiceStub);
-
// when
const screen = await render();
@@ -69,14 +135,6 @@ module('Integration | Component | Authentication | other-authentication-provider
});
module('when it’s for signup');
test('it displays a signup featured identity provider link', async function (assert) {
- // given
- class OidcIdentityProvidersServiceStub extends Service {
- get featuredIdentityProvider() {
- return { organizationName: 'Some Identity Provider', slug: 'some-identity-provider' };
- }
- }
- this.owner.register('service:oidcIdentityProviders', OidcIdentityProvidersServiceStub);
-
// when
const screen = await render();
@@ -94,16 +152,12 @@ module('Integration | Component | Authentication | other-authentication-provider
});
});
- module('when there isn’t any featured identity provider', function () {
- test('it doesn’t display a continue featured identity provider link', async function (assert) {
- // given
- class OidcIdentityProvidersServiceStub extends Service {
- get featuredIdentityProvider() {
- return null;
- }
- }
- this.owner.register('service:oidcIdentityProviders', OidcIdentityProvidersServiceStub);
+ module('when there is no featured identity provider', function (hooks) {
+ hooks.beforeEach(function () {
+ this.owner.register('service:oidcIdentityProviders', NoOidcIdentityProvidersServiceStub);
+ });
+ test('it doesn’t display a continue featured identity provider link', async function (assert) {
// when
const screen = await render();
@@ -135,21 +189,13 @@ module('Integration | Component | Authentication | other-authentication-provider
});
});
- module('when there are other identity providers', function () {
+ module('when there are other identity providers', function (hooks) {
+ hooks.beforeEach(function () {
+ this.owner.register('service:oidcIdentityProviders', OneFeaturedOthersOidcIdentityProvidersServiceStub);
+ });
+
module('when it’s for login', function () {
test('it displays a select another organization link', async function (assert) {
- // given
- class OidcIdentityProvidersServiceStub extends Service {
- get hasOtherIdentityProviders() {
- return true;
- }
-
- load() {
- return Promise.resolve();
- }
- }
- this.owner.register('service:oidcIdentityProviders', OidcIdentityProvidersServiceStub);
-
// when
const screen = await render();
@@ -164,18 +210,6 @@ module('Integration | Component | Authentication | other-authentication-provider
module('when it’s for signup', function () {
test('it displays a select another organization link', async function (assert) {
- // given
- class OidcIdentityProvidersServiceStub extends Service {
- get hasOtherIdentityProviders() {
- return true;
- }
-
- load() {
- return Promise.resolve();
- }
- }
- this.owner.register('service:oidcIdentityProviders', OidcIdentityProvidersServiceStub);
-
// when
const screen = await render();
@@ -189,16 +223,12 @@ module('Integration | Component | Authentication | other-authentication-provider
});
});
- module('when there aren’t any other identity providers', function () {
- test('it doesn’t display a select another organization link', async function (assert) {
- // given
- class OidcIdentityProvidersServiceStub extends Service {
- get hasOtherIdentityProviders() {
- return false;
- }
- }
- this.owner.register('service:oidcIdentityProviders', OidcIdentityProvidersServiceStub);
+ module('when there are no other identity providers', function (hooks) {
+ hooks.beforeEach(function () {
+ this.owner.register('service:oidcIdentityProviders', OneFeaturedNoOthersOidcIdentityProvidersServiceStub);
+ });
+ test('it doesn’t display a select another organization link', async function (assert) {
// when
const screen = await render();
diff --git a/mon-pix/tests/unit/services/oidc-identity-providers-test.js b/mon-pix/tests/unit/services/oidc-identity-providers-test.js
index 622199cd89b..a0a3668f090 100644
--- a/mon-pix/tests/unit/services/oidc-identity-providers-test.js
+++ b/mon-pix/tests/unit/services/oidc-identity-providers-test.js
@@ -78,6 +78,51 @@ module('Unit | Service | oidc-identity-providers', function (hooks) {
});
});
+ module('hasIdentityProviders', function () {
+ module('when there is some identity providers', function () {
+ test('returns true', async function () {
+ // given
+ const oidcPartner = {
+ id: 'oidc-partner',
+ code: 'OIDC_PARTNER',
+ organizationName: 'Partenaire OIDC',
+ slug: 'partenaire-oidc',
+ shouldCloseSession: false,
+ source: 'oidc-externe',
+ };
+ const oidcPartnerObject = Object.create(oidcPartner);
+ const storeStub = Service.create({
+ peekAll: sinon.stub().returns([oidcPartnerObject]),
+ });
+ const oidcIdentityProvidersService = this.owner.lookup('service:oidcIdentityProviders');
+ oidcIdentityProvidersService.set('store', storeStub);
+
+ // when
+ const hasIdentityProviders = await oidcIdentityProvidersService.hasIdentityProviders;
+
+ // then
+ assert.strictEqual(hasIdentityProviders, true);
+ });
+ });
+
+ module('when there is no identity providers', function () {
+ test('returns false', async function () {
+ // given
+ const storeStub = Service.create({
+ peekAll: sinon.stub().returns([]),
+ });
+ const oidcIdentityProvidersService = this.owner.lookup('service:oidcIdentityProviders');
+ oidcIdentityProvidersService.set('store', storeStub);
+
+ // when
+ const hasIdentityProviders = await oidcIdentityProvidersService.hasIdentityProviders;
+
+ // then
+ assert.strictEqual(hasIdentityProviders, false);
+ });
+ });
+ });
+
module('featuredIdentityProvider', function () {
module('when there is some identity providers containing a featured one', function () {
test('returns the featured identity provider', async function () {