Skip to content

Commit

Permalink
[BUGFIX] Ne pas afficher « Autres moyens de connexion » quand aucun S…
Browse files Browse the repository at this point in the history
…SO n'est disponible (PIX-15494)

 #10669
  • Loading branch information
pix-service-auto-merge authored Dec 2, 2024
2 parents 7ace134 + 3944704 commit e65a74f
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,54 @@ export default class OtherAuthenticationProviders extends Component {
}

<template>
<section class="authentication-other-authentication-providers-section">
<h2 class="authentication-other-authentication-providers-section__heading">
{{#if @isForSignup}}
{{t "components.authentication.other-authentication-providers.signup.heading"}}
{{else}}
{{t "components.authentication.other-authentication-providers.login.heading"}}
{{/if}}
</h2>

{{#if this.oidcIdentityProviders.featuredIdentityProvider}}
<PixButtonLink
@route="authentication.login-oidc"
@model="{{this.oidcIdentityProviders.featuredIdentityProvider.slug}}"
@variant="secondary"
class="authentication-other-authentication-providers-section__button-link"
>
<img
src="/images/logo/identity-providers/{{this.oidcIdentityProviders.featuredIdentityProvider.slug}}.svg"
alt=""
class="authentication-other-authentication-providers-section__featured-identity-provider-logo"
/>
{{#if this.oidcIdentityProviders.hasIdentityProviders}}
<section class="authentication-other-authentication-providers-section">
<h2 class="authentication-other-authentication-providers-section__heading">
{{#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}}
</PixButtonLink>
{{/if}}
</h2>

{{#if this.oidcIdentityProviders.hasOtherIdentityProviders}}
<PixButtonLink
@route={{this.ssoSelectionRoute}}
@variant="secondary"
class="authentication-other-authentication-providers-section__button-link"
>
{{t "components.authentication.other-authentication-providers.select-another-organization-link"}}
{{#if this.oidcIdentityProviders.featuredIdentityProvider}}
<PixButtonLink
@route="authentication.login-oidc"
@model="{{this.oidcIdentityProviders.featuredIdentityProvider.slug}}"
@variant="secondary"
class="authentication-other-authentication-providers-section__button-link"
>
<img
src="/images/logo/identity-providers/{{this.oidcIdentityProviders.featuredIdentityProvider.slug}}.svg"
alt=""
class="authentication-other-authentication-providers-section__featured-identity-provider-logo"
/>
{{#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}}
</PixButtonLink>
{{/if}}

<span class="authentication-other-authentication-providers-section__chevron-right"></span>
</PixButtonLink>
{{/if}}
</section>
{{#if this.oidcIdentityProviders.hasOtherIdentityProviders}}
<PixButtonLink
@route={{this.ssoSelectionRoute}}
@variant="secondary"
class="authentication-other-authentication-providers-section__button-link"
>
{{t "components.authentication.other-authentication-providers.select-another-organization-link"}}

<span class="authentication-other-authentication-providers-section__chevron-right"></span>
</PixButtonLink>
{{/if}}
</section>
{{/if}}
</template>
}
4 changes: 4 additions & 0 deletions mon-pix/app/services/oidc-identity-providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<template><OtherAuthenticationProviders /></template>);
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(<template><OtherAuthenticationProviders /></template>);

// 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(<template><OtherAuthenticationProviders @isForSignup="true" /></template>);

// 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(<template><OtherAuthenticationProviders @isForSignup="true" /></template>);
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(<template><OtherAuthenticationProviders /></template>);

// 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(<template><OtherAuthenticationProviders @isForSignup="true" /></template>);

// 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(<template><OtherAuthenticationProviders /></template>);

Expand All @@ -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(<template><OtherAuthenticationProviders @isForSignup="true" /></template>);

Expand All @@ -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(<template><OtherAuthenticationProviders /></template>);

Expand Down Expand Up @@ -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(<template><OtherAuthenticationProviders /></template>);

Expand All @@ -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(<template><OtherAuthenticationProviders @isForSignup={{true}} /></template>);

Expand All @@ -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(<template><OtherAuthenticationProviders /></template>);

Expand Down
Loading

0 comments on commit e65a74f

Please sign in to comment.