mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
error image rendered
This commit is contained in:
parent
31790a9ebc
commit
d4e496b9e6
47
webapp/layouts/error.spec.js
Normal file
47
webapp/layouts/error.spec.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { config, shallowMount } from '@vue/test-utils'
|
||||||
|
import Error from './error.vue'
|
||||||
|
|
||||||
|
const localVue = global.localVue
|
||||||
|
|
||||||
|
config.stubs['nuxt-link'] = '<span><slot /></span>'
|
||||||
|
|
||||||
|
describe('error.vue', () => {
|
||||||
|
let mocks, wrapper
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mocks = {
|
||||||
|
$t: jest.fn(key => key),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const Wrapper = (propsData = {}) => {
|
||||||
|
return shallowMount(Error, { mocks, propsData, localVue })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('shallowMount', () => {
|
||||||
|
it('renders default error message', () => {
|
||||||
|
wrapper = Wrapper({ error: {} })
|
||||||
|
expect(wrapper.find('.error-message').text()).toBe('error-pages.default')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders error message to given statusCode', () => {
|
||||||
|
wrapper = Wrapper({ error: { statusCode: 404 } })
|
||||||
|
expect(wrapper.find('.error-message').text()).toBe('error-pages.404-default')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders error message to given custom key', () => {
|
||||||
|
wrapper = Wrapper({ error: { statusCode: 404, key: 'my-custom-key' } })
|
||||||
|
expect(wrapper.find('.error-message').text()).toBe('my-custom-key')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('has a link to index page', () => {
|
||||||
|
wrapper = Wrapper({ error: {} })
|
||||||
|
expect(wrapper.find('span[to="/"]').text()).toBe('error-pages.back-to-index')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('has an image related to the status code', () => {
|
||||||
|
wrapper = Wrapper({ error: { statusCode: 404 } })
|
||||||
|
expect(wrapper.find('.error-image').attributes('src')).toBe('/img/svg/errors/error404.svg')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="error-container">
|
<div class="error-container">
|
||||||
<base-icon class="error-icon" name="exclamation-circle" />
|
<img class="error-image" :src="image" />
|
||||||
<br />
|
<br />
|
||||||
<span v-if="error.message === 'This page could not be found'" class="error-message">
|
<span v-if="error.message === 'This page could not be found'" class="error-message">
|
||||||
{{ $t('error-pages.default') }}
|
{{ $t('error-pages.default') }}
|
||||||
@ -14,6 +14,20 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: ['error'],
|
props: ['error'],
|
||||||
|
computed: {
|
||||||
|
message() {
|
||||||
|
const mapping = {
|
||||||
|
403: 'error-pages.403-default',
|
||||||
|
404: 'error-pages.404-default',
|
||||||
|
500: 'error-pages.500-default',
|
||||||
|
503: 'error-pages.503-default',
|
||||||
|
}
|
||||||
|
return this.error.key || mapping[this.error.statusCode] || 'error-pages.default'
|
||||||
|
},
|
||||||
|
image() {
|
||||||
|
return `/img/svg/errors/error${this.error.statusCode ? this.error.statusCode : '500'}.svg`
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@ -27,8 +41,10 @@ export default {
|
|||||||
color: $text-color-softer;
|
color: $text-color-softer;
|
||||||
margin: $space-base;
|
margin: $space-base;
|
||||||
}
|
}
|
||||||
.error-icon {
|
.error-image {
|
||||||
font-size: $font-size-xxx-large;
|
width: 70%;
|
||||||
color: $text-color-softer;
|
display: block;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -804,7 +804,10 @@
|
|||||||
"back-to-index": "Zurück zur Startseite",
|
"back-to-index": "Zurück zur Startseite",
|
||||||
"post-not-found": "Dieser Beitrag konnte nicht gefunden werden",
|
"post-not-found": "Dieser Beitrag konnte nicht gefunden werden",
|
||||||
"cannot-edit-post": "Dieser Beitrag kann nicht editiert werden",
|
"cannot-edit-post": "Dieser Beitrag kann nicht editiert werden",
|
||||||
"default": "Diese Seite konnte nicht gefunden werden",
|
"403-default": "Kein Zugang zu dieser Seite",
|
||||||
"not-authorized": "Kein Zugang zu dieser Seite"
|
"404-default": "Diese Seite konnte nicht gefunden werden",
|
||||||
|
"500-default": "Internal Server Error",
|
||||||
|
"503-default": "Dienst steht nicht zur Verfügung",
|
||||||
|
"default": "Ein Fehler ist aufgetreten"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -804,8 +804,11 @@
|
|||||||
"back-to-index": "Back to index page",
|
"back-to-index": "Back to index page",
|
||||||
"post-not-found": "This post could not be found",
|
"post-not-found": "This post could not be found",
|
||||||
"cannot-edit-post": "This post cannot be edited",
|
"cannot-edit-post": "This post cannot be edited",
|
||||||
"default": "This page could not be found",
|
"404-default": "This page could not be found",
|
||||||
"not-authorized": "Not authorized to this page"
|
"403-default": "Not authorized to this page",
|
||||||
|
"500-default": "Internal Server Error",
|
||||||
|
"503-default": "Service Unavailable",
|
||||||
|
"default": "An error occurred"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user