-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from Geoportail-Luxembourg/GSLUX-747-auth-ui
GSLUX-747: Auth form ui
- Loading branch information
Showing
16 changed files
with
447 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
describe('Authentification', () => { | ||
beforeEach(() => { | ||
cy.visit('/') | ||
}) | ||
|
||
describe('When user arrives on the page', () => { | ||
it('the authentification icon is located in the header', () => { | ||
cy.get('header [data-cy="authFormIcon"]').should('exist') | ||
}) | ||
}) | ||
|
||
describe('When user clicks on the auth icon in the header', () => { | ||
it('displays the authentification form correctly', () => { | ||
cy.get('header [data-cy="authFormIcon"]').click() | ||
cy.get('header [data-cy="authForm"]').should('exist') | ||
cy.get('header [data-cy="authForm"] form input[name="userName"]').should( | ||
'exist' | ||
) | ||
cy.get( | ||
'header [data-cy="authForm"] form input[name="userPassword"]' | ||
).should('exist') | ||
cy.get( | ||
'header [data-cy="authForm"] form a[data-cy="authFormLostPwd"]' | ||
).should('contain.text', "J'ai perdu mon mot de passe") | ||
cy.get( | ||
'header [data-cy="authForm"] form a[data-cy="authFormNewAccount"]' | ||
).should('contain.text', 'Créer un nouvel utilisateur') | ||
}) | ||
|
||
describe('When user clicks again', () => { | ||
it('hides the authentification form', () => { | ||
cy.get('header [data-cy="authFormIcon"]').click() | ||
cy.get('header [data-cy="authForm"]').should('exist') | ||
cy.get('header [data-cy="authFormIcon"]').click() | ||
cy.get('header [data-cy="authForm"]').should('not.be.visible') | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import { useTranslation } from 'i18next-vue' | ||
import { storeToRefs } from 'pinia' | ||
import { useAppStore } from '@/stores/app.store' | ||
const MYACCOUNT_URL = import.meta.env.VITE_MYACCOUNT_URL | ||
const MYACCOUNT_RECOVER_URL = import.meta.env.VITE_MYACCOUNT_RECOVER_URL | ||
const MYACCOUNT_NEW_URL = import.meta.env.VITE_MYACCOUNT_NEW_URL | ||
const { t } = useTranslation() | ||
const { lang } = storeToRefs(useAppStore()) | ||
const isAuthenticated = ref(false) | ||
const email = ref('') | ||
const userName = ref('') | ||
function logout() { | ||
alert('TODO: logout') | ||
isAuthenticated.value = false | ||
email.value = '' // TODO: remove when api ok | ||
userName.value = '' // TODO: remove when api ok | ||
} | ||
function submit() { | ||
alert('TODO: submit form') | ||
isAuthenticated.value = true | ||
email.value = 'random email (todo)' // TODO: remove when api ok | ||
userName.value = 'random user name (todo)' // TODO: remove when api ok | ||
} | ||
</script> | ||
|
||
<template> | ||
<div data-cy="authForm" class="lux-account bg-secondary"> | ||
<h4 | ||
class="lux-panel-title pt-5 mb-5 pl-5 h-16 shrink-0 flex justify-between" | ||
> | ||
{{ t('My account') }} | ||
</h4> | ||
|
||
<fieldset> | ||
<legend class="lux-account-tab"></legend> | ||
|
||
<div class="lux-account-content"> | ||
<!-- When user is not authenticated --> | ||
<template v-if="!isAuthenticated"> | ||
<form @submit.prevent="submit"> | ||
<div class="flex flex-col gap-2 mb-2"> | ||
<div> | ||
<input | ||
class="w-full lux-input h-11" | ||
type="text" | ||
name="userName" | ||
v-model="userName" | ||
:placeholder="t('Username')" | ||
/> | ||
</div> | ||
<div> | ||
<input | ||
class="w-full lux-input h-11" | ||
type="password" | ||
name="userPassword" | ||
:placeholder="t('Password')" | ||
/> | ||
</div> | ||
</div> | ||
|
||
<div class="flex mt-3 items-center"> | ||
<div class="grow leading-5"> | ||
<p> | ||
<a | ||
data-cy="authFormLostPwd" | ||
class="text-secondary hover:underline" | ||
target="_blank" | ||
:href="MYACCOUNT_RECOVER_URL" | ||
>{{ t('I lost my password') }}</a | ||
> | ||
</p> | ||
<p> | ||
<a | ||
data-cy="authFormNewAccount" | ||
class="text-secondary hover:underline" | ||
target="_blank" | ||
:href="MYACCOUNT_NEW_URL" | ||
>{{ t('Create a new user account') }}</a | ||
> | ||
</p> | ||
</div> | ||
<div> | ||
<input | ||
class="lux-btn h-11 w-24 text-white placeholder:italic bg-secondary border-none uppercase hover:text-primary hover:bg-secondary" | ||
type="submit" | ||
:value="t('Submit')" | ||
/> | ||
</div> | ||
</div> | ||
</form> | ||
</template> | ||
|
||
<!--User is authenticated --> | ||
<template v-else> | ||
<div> | ||
<div class="flex flex-col gap-1 mb-2 text-white"> | ||
<div class="bg-secondary p-1">{{ userName }}</div> | ||
<div class="bg-secondary p-1">{{ email }}</div> | ||
</div> | ||
<div class="flex items-center gap-3 justify-end"> | ||
<div> | ||
<a | ||
class="text-secondary hover:underline" | ||
target="_blank" | ||
:href="`${MYACCOUNT_URL}?lang=${lang}`" | ||
>{{ t('My account') }}</a | ||
> | ||
</div> | ||
<div> | ||
<button class="lux-btn" @click="logout"> | ||
{{ t('Logout') }} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
</div> | ||
</fieldset> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { mount } from '@vue/test-utils' | ||
import DropdownContent from './dropdown-content.vue' | ||
|
||
describe('DropdownContent', () => { | ||
it('renders the placeholder prop', () => { | ||
const wrapper = mount(DropdownContent, { | ||
props: { placeholder: 'Test Placeholder' }, | ||
}) | ||
expect(wrapper.find('span').text()).toBe('Test Placeholder') | ||
}) | ||
|
||
it('toggles dropdown on button click', async () => { | ||
const wrapper = mount(DropdownContent) | ||
const button = wrapper.find('button') | ||
|
||
expect(wrapper.find('.lux-dropdown-content').classes()).toContain('hidden') | ||
|
||
await button.trigger('click') | ||
|
||
expect(wrapper.find('.lux-dropdown-content').classes()).not.toContain( | ||
'hidden' | ||
) | ||
|
||
await button.trigger('click') | ||
|
||
expect(wrapper.find('.lux-dropdown-content').classes()).toContain('hidden') | ||
}) | ||
|
||
it('opens dropdown when forceOpen is true', async () => { | ||
const wrapper = mount(DropdownContent) | ||
wrapper.vm.toggleDropdown(true) | ||
|
||
await wrapper.vm.$nextTick() | ||
|
||
expect(wrapper.find('.lux-dropdown-content').classes()).not.toContain( | ||
'hidden' | ||
) | ||
}) | ||
|
||
it('closes dropdown when clicking outside', async () => { | ||
const wrapper = mount(DropdownContent, { | ||
props: { enableClickOutside: true }, | ||
}) | ||
|
||
wrapper.vm.toggleDropdown(true) | ||
|
||
await wrapper.vm.$nextTick() | ||
|
||
document.dispatchEvent(new MouseEvent('click')) | ||
|
||
await wrapper.vm.$nextTick() | ||
|
||
expect(wrapper.find('.lux-dropdown-content').classes()).toContain('hidden') | ||
}) | ||
|
||
it('does not close dropdown when enableClickOutside is false', async () => { | ||
const wrapper = mount(DropdownContent, { | ||
props: { enableClickOutside: false }, | ||
}) | ||
|
||
wrapper.vm.toggleDropdown(true) | ||
|
||
await wrapper.vm.$nextTick() | ||
|
||
document.dispatchEvent(new MouseEvent('click')) | ||
|
||
await wrapper.vm.$nextTick() | ||
|
||
expect(wrapper.find('.lux-dropdown-content').classes()).not.toContain( | ||
'hidden' | ||
) | ||
}) | ||
}) |
Oops, something went wrong.