Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
import PasswordCard from './PasswordCard.vue'
import { useSession } from '../../store/session'
import { expectPrimitiveControls } from '../../helpers/primitiveControls'
import MdAlert from '../md/MdAlert.vue'
import type { Component } from 'vue'

const toast = vi.hoisted(() => ({ success: vi.fn() }))

Expand Down Expand Up @@ -152,6 +154,8 @@ describe('PasswordCard', () => {
await submit()

expect(wrapper.find('[role="alert"]').text()).toContain('The current password is wrong')
expect(wrapper.findComponent(MdAlert as Component).attributes('data-tone'), 'the wrong password is drawn with the error tone').toBe('error')
expect(wrapper.findComponent(MdAlert as Component).props('tone'), 'the error alert carries the error tone').toBe('error')
expect(toast.success).not.toHaveBeenCalled()
expect(wrapper.find<HTMLInputElement>('#account-new-password').element.value, 'the new password stays for another try').toBe('new-password-123')
})
Expand Down
8 changes: 4 additions & 4 deletions reposilite-frontend/src/components/account/PasswordCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<script setup lang="ts">
import { computed, nextTick, onMounted, ref } from 'vue'
import { createSuccessToast, errorMessage } from '../../helpers/toast'
import MdAlert from '../md/MdAlert.vue'
import MdButton from '../md/MdButton.vue'
import MdCard from '../md/MdCard.vue'
import MdSection from '../md/MdSection.vue'
Expand Down Expand Up @@ -154,13 +155,12 @@ const submit = async () => {
:error="confirmError"
error-text="Passwords do not match"
/>
<p
<MdAlert
v-if="failure"
role="alert"
class="md-body-medium text-error"
tone="error"
>
{{ failure }}
</p>
</MdAlert>
<div class="flex justify-end">
<MdButton
type="submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import { describe, it, expect, vi, beforeEach, afterEach, type Mock } from 'vitest'
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
import SecondFactorsCard from './SecondFactorsCard.vue'
import MdAlert from '../md/MdAlert.vue'
import type { Component } from 'vue'

const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn() }))
const passkeys = vi.hoisted(() => ({ supported: true, create: vi.fn() }))
Expand Down Expand Up @@ -128,6 +130,45 @@ describe('SecondFactorsCard', () => {
expect(bodyText(), 'the kind is shown in words, not as the wire value').toContain('Passkey')
})

it('draws a list that failed to load through MdAlert in the error state', async () => {
api.factors.list.mockReset().mockRejectedValue(new Error('The factor list is down'))
await mountCard()

const alert = wrapper.findComponent(MdAlert as Component)
expect(alert.text(), 'the load failure is explained').toContain('The factor list is down')
expect(alert.attributes('data-tone'), 'the load failure is drawn with the error tone').toBe('error')
expect(alert.props('tone'), 'the error alert carries the error tone').toBe('error')
expect(alert.attributes('role'), 'the failure is announced once, on the alert root').toBe('alert')
})

it('draws a refused rename through MdAlert in the error state', async () => {
api.factors.rename.mockRejectedValue(new Error('The name is taken'))
await mountCard()

await click('Rename')
await typeInto('second-factor-name', 'Work phone')
await click('Save name')

const alert = wrapper.findComponent(MdAlert as Component)
expect(alert.text(), 'the refusal is explained').toContain('The name is taken')
expect(alert.attributes('data-tone'), 'the refused rename is drawn with the error tone').toBe('error')
expect(alert.props('tone'), 'the error alert carries the error tone').toBe('error')
})

it('draws a refused removal through MdAlert in the error state', async () => {
api.factors.remove.mockRejectedValue(new Error('The code is wrong'))
await mountCard()

await click('Remove')
await typeInto('second-factor-remove-code', '123456')
await click('Remove factor')

const alert = wrapper.findComponent(MdAlert as Component)
expect(alert.text(), 'the refusal is explained').toContain('The code is wrong')
expect(alert.attributes('data-tone'), 'the refused removal is drawn with the error tone').toBe('error')
expect(alert.props('tone'), 'the error alert carries the error tone').toBe('error')
})

it('says so when the account has no second factor yet', async () => {
api.factors.list.mockReset().mockResolvedValue({ data: [] })
await mountCard()
Expand Down Expand Up @@ -203,6 +244,21 @@ describe('SecondFactorsCard', () => {
expect(bodyText(), 'no recovery code is issued for a wrong code').not.toContain('ABCD-EFGH')
})

it('draws a refused enrolment through MdAlert in the error state', async () => {
api.factors.confirmAuthenticator.mockRejectedValue(new Error('Invalid code'))
await mountCard()

await click('Add an authenticator app')
await click('Start')
await typeInto('second-factor-enrol-code', '000000')
await click('Confirm')

const alert = wrapper.findComponent(MdAlert as Component)
expect(alert.text(), 'the wrong code is explained').toContain('Invalid code')
expect(alert.attributes('data-tone'), 'the refused enrolment is drawn with the error tone').toBe('error')
expect(alert.props('tone'), 'the error alert carries the error tone').toBe('error')
})

it('keeps the recovery codes dialog open until the stored check box is ticked', async () => {
await mountCard()

Expand Down
28 changes: 12 additions & 16 deletions reposilite-frontend/src/components/account/SecondFactorsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,12 @@ const emptyList = computed(() => loaded.value && loadFailure.value === null && f
Second factors
</h3>

<p
<MdAlert
v-if="loadFailure"
role="alert"
class="md-body-medium text-error"
tone="error"
>
{{ loadFailure }}
</p>
</MdAlert>
<p
v-else-if="emptyList"
class="md-body-medium text-on-surface-variant"
Expand Down Expand Up @@ -334,13 +333,12 @@ const emptyList = computed(() => loaded.value && loadFailure.value === null && f
>
Cancel
</MdButton>
<p
<MdAlert
v-if="editFailure"
role="alert"
class="w-full md-body-medium text-error"
tone="error"
>
{{ editFailure }}
</p>
</MdAlert>
</form>

<form
Expand Down Expand Up @@ -368,13 +366,12 @@ const emptyList = computed(() => loaded.value && loadFailure.value === null && f
>
Cancel
</MdButton>
<p
<MdAlert
v-if="editFailure"
role="alert"
class="w-full md-body-medium text-error"
tone="error"
>
{{ editFailure }}
</p>
</MdAlert>
</form>
</li>
</ul>
Expand Down Expand Up @@ -445,13 +442,12 @@ const emptyList = computed(() => loaded.value && loadFailure.value === null && f
/>
</div>

<p
<MdAlert
v-if="enrolFailure"
role="alert"
class="mt-3 md-body-medium text-error"
tone="error"
>
{{ enrolFailure }}
</p>
</MdAlert>

<template #actions>
<MdDialogActions>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2026 OneLiteFeather
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, it, expect, vi, afterEach } from 'vitest'
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
import { createMemoryHistory, createRouter } from 'vue-router'
import { ref } from 'vue'
import SettingsBackupPanel from './SettingsBackupPanel.vue'
import { configurationStoreKey, createConfigurationStore } from '../../store/configuration'
import MdAlert from '../md/MdAlert.vue'
import type { Component } from 'vue'

vi.mock('../../store/session', () => ({
useSession: () => ({ client: { value: null }, can: () => true })
}))

let wrapper: VueWrapper | undefined

afterEach(() => {
wrapper?.unmount()
wrapper = undefined
document.body.innerHTML = ''
})

describe('SettingsBackupPanel', () => {
it('draws a failed configuration load through MdAlert in the error state', async () => {
// A client without settings endpoints makes the load fail, which leaves the store with its load error.
const store = createConfigurationStore(ref({ settings: {} }) as never)
const router = createRouter({
history: createMemoryHistory(),
routes: [
{ path: '/', component: { render: () => null } },
{ path: '/settings/system-info', name: 'system-info', component: { render: () => null } }
]
})
await router.push('/')
await router.isReady()

wrapper = mount(SettingsBackupPanel, {
attachTo: document.body,
global: { plugins: [router], provide: { [configurationStoreKey as symbol]: store } }
}) as VueWrapper
await flushPromises()

const alert = wrapper.findComponent(MdAlert as Component)
expect(alert.text(), 'the load failure is explained').toContain('Cannot load configuration')
expect(alert.attributes('data-tone'), 'the load failure is drawn with the error tone').toBe('error')
expect(alert.props('tone'), 'the error alert carries the error tone').toBe('error')
expect(alert.attributes('role'), 'the failure is announced once, on the alert root').toBe('alert')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { computed, inject, onMounted, ref, watch } from 'vue'
import { RouterLink } from 'vue-router'
import download from 'downloadjs'
import { configurationStoreKey, useConfiguration } from '../../store/configuration'
import MdAlert from '../md/MdAlert.vue'
import MdButton from '../md/MdButton.vue'
import PasswordDialog from '../settings/PasswordDialog.vue'
import SettingsDownloadMenu from '../settings/SettingsDownloadMenu.vue'
Expand Down Expand Up @@ -272,13 +273,12 @@ const discard = () => store.discardChanges()
</RouterLink>
</p>

<p
<MdAlert
v-if="loadError"
role="alert"
class="md-body-medium text-error"
tone="error"
>
{{ loadError }}
</p>
</MdAlert>

<SettingsImportErrors
v-if="importErrors.length > 0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2026 OneLiteFeather
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, it, expect, vi, afterEach } from 'vitest'
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
import { ref } from 'vue'
import DomainSettingsPanel from './DomainSettingsPanel.vue'
import { configurationStoreKey, createConfigurationStore } from '../../store/configuration'
import MdAlert from '../md/MdAlert.vue'
import type { Component } from 'vue'

vi.mock('../../store/session', () => ({
useSession: () => ({ client: { value: null }, can: () => true })
}))

let wrapper: VueWrapper | undefined

afterEach(() => {
wrapper?.unmount()
wrapper = undefined
document.body.innerHTML = ''
})

describe('DomainSettingsPanel', () => {
it('draws a failed configuration load through MdAlert in the error state', async () => {
// A client without settings endpoints makes the load fail, which leaves the store with its load error.
const store = createConfigurationStore(ref({ settings: {} }) as never)
await store.fetchConfiguration()

wrapper = mount(DomainSettingsPanel, {
props: { domain: 'cleanup', heading: 'Cleanup' },
attachTo: document.body,
global: { provide: { [configurationStoreKey as symbol]: store } }
}) as VueWrapper
await flushPromises()

const alert = wrapper.findComponent(MdAlert as Component)
expect(alert.text(), 'the load failure is explained').toContain('Cannot load configuration')
expect(alert.attributes('data-tone'), 'the load failure is drawn with the error tone').toBe('error')
expect(alert.props('tone'), 'the error alert carries the error tone').toBe('error')
expect(alert.attributes('role'), 'the failure is announced once, on the alert root').toBe('alert')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { JsonForms } from '@jsonforms/vue'
import { configurationStoreKey, useConfiguration } from '../../store/configuration'
import { useSession } from '../../store/session'
import { ADMIN_NODES } from '../../store/nodeAccess'
import MdAlert from '../md/MdAlert.vue'
import { collectionsOf } from './collections'
import { nestedUischemas } from './nestedLayouts'
import { domainFormOf } from './domainForm'
Expand Down Expand Up @@ -118,13 +119,12 @@ const discardAll = () => {
>
Changing these settings needs the settings permission.
</p>
<p
<MdAlert
v-else-if="store.loadError.value"
role="alert"
class="md-body-medium text-error"
tone="error"
>
{{ store.loadError.value }}
</p>
</MdAlert>
<JsonForms
v-else-if="form && store.configurations.value[domain]"
:config="formsConfiguration"
Expand Down
Loading