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 @@ -17,6 +17,8 @@
import { describe, it, expect, afterEach } from 'vitest'
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
import SsoProviderDialog from './SsoProviderDialog.vue'
import MdAlert from '../md/MdAlert.vue'
import type { Component } from 'vue'
import { SECRET_PLACEHOLDER, type OidcProvider } from './loginSettings'

const KEYCLOAK: OidcProvider = {
Expand Down Expand Up @@ -53,6 +55,27 @@ const openDialog = async (): Promise<void> => {
const registerSection = (): HTMLElement | null =>
document.querySelector<HTMLElement>('[aria-labelledby="sso-register-title"]')

describe('SsoProviderDialog refused save', () => {
afterEach(() => {
wrapper?.unmount()
wrapper = undefined
})

it('draws the refused save through MdAlert in the error state', async () => {
wrapper = mount(SsoProviderDialog, {
attachTo: document.body,
props: { modelValue: true, provider: KEYCLOAK, takenIds: [], productionUrl: 'http://localhost:3000/', failure: 'Issuer is unreachable' }
})
await flushPromises()

const alert = document.querySelector('[role="alert"]')
expect(alert?.textContent?.trim(), 'the refusal is shown').toContain('Issuer is unreachable')
expect(alert?.getAttribute('data-tone'), 'the refused save 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(alert?.getAttribute('role'), 'the refusal is announced once, on the alert root').toBe('alert')
})
})

describe('SsoProviderDialog register card', () => {
afterEach(() => {
wrapper?.unmount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<script setup lang="ts">
import { computed, nextTick, ref, watch, type PropType } from 'vue'
import MdAlert from '../md/MdAlert.vue'
import MdDialog from '../md/MdDialog.vue'
import MdButton from '../md/MdButton.vue'
import MdCard from '../md/MdCard.vue'
Expand Down Expand Up @@ -497,13 +498,12 @@ const validateDomain = (text: string, existing: string[]) => {
</div>
</section>

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

<div class="flex flex-wrap items-center justify-between gap-2">
<MdButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
// @vitest-environment jsdom

import { describe, it, expect, vi, beforeEach, afterEach, type Mock } from 'vitest'
import { ref, type Ref } from 'vue'
import { ref, type Component, type Ref } from 'vue'
import { flushPromises, mount, type DOMWrapper, type VueWrapper } from '@vue/test-utils'
import { createErrorToast } from '../../helpers/toast'
import TeamParentsCard from './TeamParentsCard.vue'
import MdAlert from '../md/MdAlert.vue'
import { answer, failure } from './teamTestKit'

/*
Expand Down Expand Up @@ -59,6 +60,7 @@ describe('TeamParentsCard', () => {
const options = () => wrapper.findAll('[role="option"]').map(option => option.text())
const save = () => wrapper.find('[data-test="save-parents"]')
const error = () => wrapper.find('[data-test="parents-error"]')
const errorAlert = () => wrapper.find('[data-test="parents-error"][role="alert"]')

const type = async (text: string) => {
await input().trigger('focus')
Expand Down Expand Up @@ -456,6 +458,21 @@ describe('TeamParentsCard', () => {
expect(error().exists()).toBe(false)
})

it('draws the refused save through MdAlert in the error state', async () => {
teams.setParents.mockRejectedValue(failure(409, 'Adding staff as a parent of ops would create a cycle'))
await mountCard()
await type('staff')
await press('Enter')

await save().trigger('click')
await flushPromises()

expect(errorAlert().exists(), 'the refusal is an MdAlert').toBe(true)
expect(errorAlert().attributes('data-tone'), 'the refused save 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(errorAlert().attributes('role'), 'the refusal is announced once, on the alert root').toBe('alert')
})

it('offers a reload when the parents were changed by somebody else', async () => {
teams.setParents.mockRejectedValue(failure(412, 'Team ops was changed by somebody else, reload and try again'))
await mountCard()
Expand Down
26 changes: 15 additions & 11 deletions reposilite-frontend/src/components/access/TeamParentsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { AxiosError } from 'axios'
import { useCombobox } from '../../helpers/useCombobox'
import { createSuccessToast, errorMessage } from '../../helpers/toast'
import { useSession } from '../../store/session'
import MdAlert from '../md/MdAlert.vue'
import MdButton from '../md/MdButton.vue'
import MdCard from '../md/MdCard.vue'
import MdListbox from '../md/MdListbox.vue'
Expand Down Expand Up @@ -332,22 +333,25 @@ const save = async () => {
</MdButton>
</div>

<div
<MdAlert
v-if="serverError"
role="alert"
class="flex flex-wrap items-center gap-3"
tone="error"
data-test="parents-error"
>
<span class="md-body-medium text-error">{{ serverError }}</span>
<MdButton
{{ serverError }}
<template
v-if="stale"
variant="text"
data-test="parents-reload"
@click="load()"
#action
>
Reload
</MdButton>
</div>
<MdButton
variant="text"
data-test="parents-reload"
@click="load()"
>
Reload
</MdButton>
</template>
</MdAlert>

<div class="flex justify-end">
<MdButton
Expand Down
22 changes: 18 additions & 4 deletions reposilite-frontend/src/components/access/nodes/NodeEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
// @vitest-environment jsdom

import MdBadge from '../../md/MdBadge.vue'
import MdAlert from '../../md/MdAlert.vue'
import MdList from '../../md/MdList.vue'
import MdListItem from '../../md/MdListItem.vue'
import MdListbox from '../../md/MdListbox.vue'
import type { Component } from 'vue'
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
import NodeEditor from './NodeEditor.vue'
Expand Down Expand Up @@ -279,7 +284,7 @@ describe('NodeEditor', () => {
await type('releases')

const listbox = wrapper.find('[role="listbox"]')
expect(listbox.attributes('data-ingot-component'), 'the list is the shared MdListbox').toBe('md-listbox')
expect(wrapper.findComponent(MdListbox as Component).find('[role="listbox"]').element, 'the list is the shared MdListbox').toBe(listbox.element)
expect(listbox.classes(), 'the list sits in the menu layer').toContain('z-md-menu')
expect(listbox.classes(), 'no z-index literal is left').not.toContain('z-20')
})
Expand Down Expand Up @@ -751,10 +756,10 @@ describe('NodeEditor', () => {
mountEditor({ inherited: INHERITED() })

const rows = wrapper.findAll('[data-test="inherited-row"]')
expect(rows.map(row => row.attributes('data-ingot-component')), 'each inherited node is an md-list-item')
.toEqual(INHERITED().map(() => 'md-list-item'))
const items = wrapper.findAllComponents(MdListItem as Component).map(item => item.element as Element)
expect(rows.every(row => items.includes(row.element)), 'each inherited node is an md-list-item').toBe(true)
const list = rows[0].element.parentElement
expect(list?.dataset.ingotComponent, 'the rows sit in an md-list').toBe('md-list')
expect(wrapper.findAllComponents(MdList as Component).map(component => component.element as Element), 'the rows sit in an md-list').toContain(list)
expect(list?.dataset.divided, 'the list draws the rule between the rows').toBe('true')
})

Expand Down Expand Up @@ -815,6 +820,15 @@ describe('NodeEditor', () => {
expect(wrapper.findAll('[data-test="inherited-row"]')).toHaveLength(INHERITED().length)
})

it('draws an unreadable team as a warning notice through MdAlert, not as an alert', () => {
mountEditor({ inherited: INHERITED(), inheritedWarnings: ['Could not read the nodes of team staff: Boom'] })

const notice = wrapper.find('[data-test="inherited-warning"]')
expect(notice.element, 'the warning is an MdAlert').toBe(wrapper.findComponent(MdAlert as Component).element)
expect(notice.attributes('data-tone'), 'an unreadable team is a warning, not an error').toBe('warning')
expect(notice.attributes('role'), 'a notice that stays on the page is not announced as an alert').toBe('status')
})

it('shows the section for a warning alone, when no inherited node could be read', () => {
mountEditor({ inherited: [], inheritedWarnings: ['Could not read the nodes of team staff: Boom'] })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<script setup lang="ts">
import { ref, type PropType } from 'vue'
import MdAlert from '../../md/MdAlert.vue'
import MdBadge from '../../md/MdBadge.vue'
import MdDisclosure from '../../md/MdDisclosure.vue'
import MdList from '../../md/MdList.vue'
Expand Down Expand Up @@ -63,15 +64,14 @@ const open = ref(true)
<p class="md-body-medium text-on-surface-variant">
These nodes come from teams and cannot be changed here. A direct node that matches the same permission decides first.
</p>
<p
<MdAlert
v-for="warning in warnings"
:key="warning"
role="alert"
class="md-body-medium text-warning"
tone="warning"
data-test="inherited-warning"
>
{{ warning }}
</p>
</MdAlert>
<div
v-if="inherited.length > 0"
class="rounded-corner-medium border border-outline-variant"
Expand Down
39 changes: 39 additions & 0 deletions reposilite-frontend/src/components/header/LoginModal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { createMemoryHistory, createRouter, type Router } from 'vue-router'
import { VueFinalModal } from 'vue-final-modal'
import { siGithub } from 'simple-icons'
import LoginModal from './LoginModal.vue'
import MdAlert from '../md/MdAlert.vue'
import type { Component } from 'vue'
import { openLogin } from '../../store/login'
import { useSession } from '../../store/session'
import { resetClock, setClock } from '../../helpers/clock'
Expand Down Expand Up @@ -452,6 +454,17 @@ describe('LoginModal', () => {
expect(button.hasAttribute('disabled') || button.getAttribute('aria-disabled') === 'true').toBe(true)
})

it('draws a provider list that failed to load through MdAlert in the error state', async () => {
actions.loadProviders.mockRejectedValue(new Error('providers unavailable'))

await openDialog()

const alert = dialog().querySelector('[role="alert"]')
expect(alert?.textContent?.trim(), 'the failed load is explained').toContain('Sign in options could not be loaded')
expect(alert?.getAttribute('data-tone'), 'the failed load 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')
})

it('shows no password form when there is no local provider', async () => {
store.providers.value = [{ id: 'oidc', type: 'OIDC', label: 'Continue with Example', loginUrl: '/x' }]

Expand Down Expand Up @@ -852,6 +865,19 @@ describe('LoginModal', () => {

expect(dialog().querySelector('[role="alert"]')!.textContent.trim()).toBe('Setup code is incorrect')
})

it('draws the refused setup through MdAlert in the error state', async () => {
actions.completeSetup.mockRejectedValue(answer(500, 'Setup failed'))
await openDialog()
fillSetup()

await submit()

const alert = dialog().querySelector('[role="alert"]')
expect(alert?.getAttribute('data-tone'), 'the refused setup 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(alert?.getAttribute('role'), 'the refusal is announced once, on the alert root').toBe('alert')
})
})

describe('second step of the sign in', () => {
Expand Down Expand Up @@ -955,6 +981,19 @@ describe('LoginModal', () => {
expect(dialog()?.querySelector('h2'), 'a signed in user does not need the dialog').toBeFalsy()
})

it('draws a refused code through MdAlert in the error state', async () => {
actions.completeSecondFactor.mockRejectedValue(answer(401, 'Invalid code'))
await reachSecondStep(CODE_AND_RECOVERY)
type('login-code', '000000')

await submit()

const alert = dialog().querySelector('[role="alert"]')
expect(alert?.getAttribute('data-tone'), 'the refused code 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(alert?.getAttribute('role'), 'the error is announced once, on the alert root').toBe('alert')
})

it('keeps the step open with the server message when the code is wrong', async () => {
actions.completeSecondFactor.mockRejectedValue(answer(401, 'Invalid code'))
await reachSecondStep(CODE_AND_RECOVERY)
Expand Down
22 changes: 10 additions & 12 deletions reposilite-frontend/src/components/header/LoginModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { isWebAuthnSupported } from '../../store/webauthn'
import { loginRequests } from '../../store/login'
import { now } from '../../helpers/clock'
import { rateLimitMessage, rateLimitedUntil } from '../../helpers/rate-limit'
import MdAlert from '../md/MdAlert.vue'
import MdButton from '../md/MdButton.vue'
import MdDialog from '../md/MdDialog.vue'
import MdTextField from '../md/MdTextField.vue'
Expand Down Expand Up @@ -490,13 +491,12 @@ const submitLabel = computed(() => {
error-text="Passwords do not match"
required
/>
<p
<MdAlert
v-if="failure"
role="alert"
class="md-body-medium text-error"
tone="error"
>
{{ failure }}
</p>
</MdAlert>
</form>

<form
Expand Down Expand Up @@ -560,13 +560,12 @@ const submitLabel = computed(() => {
/>
</form>

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

<div class="mt-6 flex flex-col gap-2">
<MdButton
Expand Down Expand Up @@ -676,13 +675,12 @@ const submitLabel = computed(() => {
</li>
</ul>

<p
<MdAlert
v-if="providersFailed"
role="alert"
class="mt-4 md-body-medium text-error"
tone="error"
>
Sign in options could not be loaded
</p>
</MdAlert>
</div>
</MdTransition>

Expand Down
12 changes: 12 additions & 0 deletions reposilite-frontend/src/components/identity/StepUpDialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
import StepUpDialog from './StepUpDialog.vue'
import MdAlert from '../md/MdAlert.vue'
import type { Component } from 'vue'

// The dialog is a view of the session's step-up state. The session is replaced by a double whose
// refs the test sets, so the dialog is tested without a server.
Expand Down Expand Up @@ -96,6 +98,16 @@ describe('StepUpDialog', () => {
expect(dialog()?.querySelector('[role="alert"]')?.textContent, 'the reason of the refusal is shown').toContain('Invalid code')
})

it('draws the refusal through MdAlert in the error state', async () => {
session.stepUp.value = { methods: ['AUTHENTICATOR'], message: 'Invalid code', busy: false }
await mountDialog()

const alert = dialog()?.querySelector('[role="alert"]')
expect(alert?.getAttribute('data-tone'), 'the refusal 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(alert?.getAttribute('role'), 'the refusal is announced once, on the alert root').toBe('alert')
})

it('sends the typed code to the session when confirmed', async () => {
session.stepUp.value = { methods: ['AUTHENTICATOR'], message: '', busy: false }
await mountDialog()
Expand Down
Loading
Loading