mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch '2595-visualize-the-federation' into fix-community-url
This commit is contained in:
commit
7536898a0c
183
admin/src/components/Fedaration/FederationVisualizeItem.spec.js
Normal file
183
admin/src/components/Fedaration/FederationVisualizeItem.spec.js
Normal file
@ -0,0 +1,183 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import FederationVisualizeItem from './FederationVisualizeItem.vue'
|
||||
|
||||
const localVue = global.localVue
|
||||
const today = new Date()
|
||||
const createdDate = new Date()
|
||||
createdDate.setDate(createdDate.getDate() - 3)
|
||||
|
||||
let propsData = {
|
||||
item: {
|
||||
id: 7590,
|
||||
foreign: false,
|
||||
publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7',
|
||||
url: 'http://localhost/api/api/2_0',
|
||||
lastAnnouncedAt: createdDate,
|
||||
verifiedAt: today,
|
||||
lastErrorAt: null,
|
||||
createdAt: createdDate,
|
||||
updatedAt: null,
|
||||
},
|
||||
}
|
||||
|
||||
const mocks = {
|
||||
$i18n: {
|
||||
locale: 'en',
|
||||
},
|
||||
}
|
||||
|
||||
describe('FederationVisualizeItem', () => {
|
||||
let wrapper
|
||||
|
||||
const Wrapper = () => {
|
||||
return mount(FederationVisualizeItem, { localVue, mocks, propsData })
|
||||
}
|
||||
|
||||
describe('mount', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('renders the component', () => {
|
||||
expect(wrapper.find('div.federation-visualize-item').exists()).toBe(true)
|
||||
})
|
||||
|
||||
describe('rendering item properties', () => {
|
||||
it('has the url', () => {
|
||||
expect(wrapper.find('.row > div:nth-child(2) > div').text()).toBe(
|
||||
'http://localhost/api/api/2_0',
|
||||
)
|
||||
})
|
||||
|
||||
it('has the public key', () => {
|
||||
expect(wrapper.find('.row > div:nth-child(2) > small').text()).toContain(
|
||||
'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7'.substring(0, 26),
|
||||
)
|
||||
})
|
||||
|
||||
describe('verified item', () => {
|
||||
it('has the check icon', () => {
|
||||
expect(wrapper.find('svg.bi-check').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('has the text variant "success"', () => {
|
||||
expect(wrapper.find('.text-success').exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('not verified item', () => {
|
||||
beforeEach(() => {
|
||||
propsData = {
|
||||
item: {
|
||||
id: 7590,
|
||||
foreign: false,
|
||||
publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7',
|
||||
url: 'http://localhost/api/api/2_0',
|
||||
lastAnnouncedAt: createdDate,
|
||||
verifiedAt: null,
|
||||
lastErrorAt: null,
|
||||
createdAt: createdDate,
|
||||
updatedAt: null,
|
||||
},
|
||||
}
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('has the x-circle icon', () => {
|
||||
expect(wrapper.find('svg.bi-x-circle').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('has the text variant "danger"', () => {
|
||||
expect(wrapper.find('.text-danger').exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
// describe('with different locales (de, en, fr, es, nl)', () => {
|
||||
describe('lastAnnouncedAt', () => {
|
||||
it('computes the time string for different locales (de, en, fr, es, nl)', () => {
|
||||
wrapper.vm.$i18n.locale = 'de'
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.vm.lastAnnouncedAt).toBe('vor 3 Tagen')
|
||||
|
||||
wrapper.vm.$i18n.locale = 'fr'
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.vm.lastAnnouncedAt).toBe('il y a 3 jours')
|
||||
|
||||
wrapper.vm.$i18n.locale = 'es'
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.vm.lastAnnouncedAt).toBe('hace 3 días')
|
||||
|
||||
wrapper.vm.$i18n.locale = 'nl'
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.vm.lastAnnouncedAt).toBe('3 dagen geleden')
|
||||
})
|
||||
|
||||
describe('lastAnnouncedAt == null', () => {
|
||||
beforeEach(() => {
|
||||
propsData = {
|
||||
item: {
|
||||
id: 7590,
|
||||
foreign: false,
|
||||
publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7',
|
||||
url: 'http://localhost/api/api/2_0',
|
||||
lastAnnouncedAt: null,
|
||||
verifiedAt: null,
|
||||
lastErrorAt: null,
|
||||
createdAt: createdDate,
|
||||
updatedAt: null,
|
||||
},
|
||||
}
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('computes empty string', async () => {
|
||||
expect(wrapper.vm.lastAnnouncedAt).toBe('')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('createdAt', () => {
|
||||
it('computes the time string for different locales (de, en, fr, es, nl)', () => {
|
||||
wrapper.vm.$i18n.locale = 'de'
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.vm.createdAt).toBe('vor 3 Tagen')
|
||||
|
||||
wrapper.vm.$i18n.locale = 'fr'
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.vm.createdAt).toBe('il y a 3 jours')
|
||||
|
||||
wrapper.vm.$i18n.locale = 'es'
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.vm.createdAt).toBe('hace 3 días')
|
||||
|
||||
wrapper.vm.$i18n.locale = 'nl'
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.vm.createdAt).toBe('3 dagen geleden')
|
||||
})
|
||||
|
||||
describe('createdAt == null', () => {
|
||||
beforeEach(() => {
|
||||
propsData = {
|
||||
item: {
|
||||
id: 7590,
|
||||
foreign: false,
|
||||
publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7',
|
||||
url: 'http://localhost/api/api/2_0',
|
||||
lastAnnouncedAt: createdDate,
|
||||
verifiedAt: null,
|
||||
lastErrorAt: null,
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
},
|
||||
}
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('computes empty string', async () => {
|
||||
expect(wrapper.vm.createdAt).toBe('')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -15,6 +15,8 @@
|
||||
import { formatDistanceToNow } from 'date-fns'
|
||||
import { de, en, fr, es, nl } from 'date-fns/locale'
|
||||
|
||||
const locales = { en, de, es, fr, nl }
|
||||
|
||||
export default {
|
||||
name: 'FederationVisualizeItem',
|
||||
props: {
|
||||
@ -22,7 +24,6 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
oldPublicKey: '',
|
||||
formatDistanceToNow,
|
||||
locale: this.$i18n.locale,
|
||||
}
|
||||
@ -37,26 +38,12 @@ export default {
|
||||
variant() {
|
||||
return this.verified ? 'success' : 'danger'
|
||||
},
|
||||
fnsLocale() {
|
||||
switch (this.locale) {
|
||||
case 'de':
|
||||
return de
|
||||
case 'es':
|
||||
return es
|
||||
case 'fr':
|
||||
return fr
|
||||
case 'nl':
|
||||
return nl
|
||||
default:
|
||||
return en
|
||||
}
|
||||
},
|
||||
lastAnnouncedAt() {
|
||||
if (this.item.lastAnnouncedAt) {
|
||||
return formatDistanceToNow(new Date(this.item.lastAnnouncedAt), {
|
||||
includeSecond: true,
|
||||
addSuffix: true,
|
||||
locale: this.fnsLocale,
|
||||
locale: locales[this.locale],
|
||||
})
|
||||
}
|
||||
return ''
|
||||
@ -66,7 +53,7 @@ export default {
|
||||
return formatDistanceToNow(new Date(this.item.createdAt), {
|
||||
includeSecond: true,
|
||||
addSuffix: true,
|
||||
locale: this.fnsLocale,
|
||||
locale: locales[this.locale],
|
||||
})
|
||||
}
|
||||
return ''
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import FederationVisualizeItem from './FederationVisualizeItem.vue'
|
||||
|
||||
const localVue = global.localVue
|
||||
|
||||
const mocks = {
|
||||
$t: (key) => key,
|
||||
$i18n: {
|
||||
locale: 'de',
|
||||
t: (key) => key,
|
||||
},
|
||||
}
|
||||
|
||||
describe('FederationVisualizeItem', () => {
|
||||
let wrapper
|
||||
|
||||
const propsData = {
|
||||
item: {
|
||||
id: 7590,
|
||||
foreign: false,
|
||||
publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7',
|
||||
url: 'http://localhost/api/api/2_0',
|
||||
lastAnnouncedAt: null,
|
||||
verifiedAt: null,
|
||||
lastErrorAt: null,
|
||||
createdAt: '2023-03-29T04:46:38.823Z',
|
||||
updatedAt: null,
|
||||
},
|
||||
}
|
||||
|
||||
const Wrapper = () => {
|
||||
return mount(FederationVisualizeItem, { localVue, mocks, propsData })
|
||||
}
|
||||
|
||||
describe('mount', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('renders the component', () => {
|
||||
expect(wrapper.find('div.federation-visualize-item').exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -1,30 +1,98 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import FederationVisualize from './FederationVisualize'
|
||||
import VueApollo from 'vue-apollo'
|
||||
import { createMockClient } from 'mock-apollo-client'
|
||||
import { getCommunities } from '@/graphql/getCommunities'
|
||||
|
||||
const mockClient = createMockClient()
|
||||
const apolloProvider = new VueApollo({
|
||||
defaultClient: mockClient,
|
||||
})
|
||||
|
||||
const localVue = global.localVue
|
||||
|
||||
localVue.use(VueApollo)
|
||||
|
||||
const mocks = {
|
||||
$t: (key) => key,
|
||||
// $t: jest.fn((t) => t),
|
||||
$d: jest.fn((d) => d),
|
||||
$i18n: {
|
||||
locale: 'de',
|
||||
locale: 'en',
|
||||
t: (key) => key,
|
||||
},
|
||||
}
|
||||
|
||||
describe('Overview', () => {
|
||||
const defaultData = () => {
|
||||
return {
|
||||
getCommunities: [
|
||||
{
|
||||
id: 1776,
|
||||
foreign: true,
|
||||
publicKey: 'c7ca9e742421bb167b8666cb78f90b40c665b8f35db8f001988d44dbb3ce8527',
|
||||
url: 'http://localhost/api/api/2_0',
|
||||
lastAnnouncedAt: '2023-04-07T12:27:24.037Z',
|
||||
verifiedAt: null,
|
||||
lastErrorAt: null,
|
||||
createdAt: '2023-04-07T11:45:06.254Z',
|
||||
updatedAt: null,
|
||||
__typename: 'Community',
|
||||
},
|
||||
{
|
||||
id: 1775,
|
||||
foreign: true,
|
||||
publicKey: 'c7ca9e742421bb167b8666cb78f90b40c665b8f35db8f001988d44dbb3ce8527',
|
||||
url: 'http://localhost/api/api/1_1',
|
||||
lastAnnouncedAt: '2023-04-07T12:27:24.023Z',
|
||||
verifiedAt: null,
|
||||
lastErrorAt: null,
|
||||
createdAt: '2023-04-07T11:45:06.234Z',
|
||||
updatedAt: null,
|
||||
__typename: 'Community',
|
||||
},
|
||||
{
|
||||
id: 1774,
|
||||
foreign: true,
|
||||
publicKey: 'c7ca9e742421bb167b8666cb78f90b40c665b8f35db8f001988d44dbb3ce8527',
|
||||
url: 'http://localhost/api/api/1_0',
|
||||
lastAnnouncedAt: '2023-04-07T12:27:24.009Z',
|
||||
verifiedAt: null,
|
||||
lastErrorAt: null,
|
||||
createdAt: '2023-04-07T11:45:06.218Z',
|
||||
updatedAt: null,
|
||||
__typename: 'Community',
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
describe('FederationVisualize', () => {
|
||||
let wrapper
|
||||
const getCommunitiesMock = jest.fn()
|
||||
|
||||
mockClient.setRequestHandler(
|
||||
getCommunities,
|
||||
getCommunitiesMock
|
||||
.mockRejectedValueOnce({ message: 'Ouch!' })
|
||||
.mockResolvedValue({ data: defaultData() }),
|
||||
)
|
||||
|
||||
const Wrapper = () => {
|
||||
return mount(FederationVisualize, { localVue, mocks })
|
||||
return mount(FederationVisualize, { localVue, mocks, apolloProvider })
|
||||
}
|
||||
|
||||
describe('mount', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('has a DIV element with the class.component-confirm-register-mail', () => {
|
||||
it('has a DIV element with the class "federation-visualize"', () => {
|
||||
expect(wrapper.find('div.federation-visualize').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('has a refresh button', () => {
|
||||
expect(wrapper.find('[data-test="federation-communities-refresh-btn"]').exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
font-scale="2"
|
||||
:animation="animation"
|
||||
@click="$apollo.queries.GetCommunities.refresh()"
|
||||
data-test="federation-communities-refresh-btn"
|
||||
></b-icon>
|
||||
</b-button>
|
||||
</div>
|
||||
@ -43,24 +44,24 @@ export default {
|
||||
oldPublicKey: '',
|
||||
communities: [],
|
||||
icon: '',
|
||||
animation: '',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
animation() {
|
||||
return this.$apollo.queries.GetCommunities.loading ? 'spin' : ''
|
||||
},
|
||||
},
|
||||
apollo: {
|
||||
GetCommunities: {
|
||||
fetchPolicy: 'network-only',
|
||||
query() {
|
||||
this.animation = 'spin'
|
||||
|
||||
return getCommunities
|
||||
},
|
||||
update({ getCommunities }) {
|
||||
this.communities = getCommunities
|
||||
this.animation = ''
|
||||
},
|
||||
error({ message }) {
|
||||
this.toastError(message)
|
||||
this.animation = ''
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -36,6 +36,7 @@ describe('CommunityResolver', () => {
|
||||
let foreignCom1: DbCommunity
|
||||
let foreignCom2: DbCommunity
|
||||
let foreignCom3: DbCommunity
|
||||
|
||||
describe('with empty list', () => {
|
||||
it('returns no community entry', async () => {
|
||||
// const result: Community[] = await query({ query: getCommunities })
|
||||
@ -77,7 +78,7 @@ describe('CommunityResolver', () => {
|
||||
await DbCommunity.insert(homeCom3)
|
||||
})
|
||||
|
||||
it('returns three home-community entries', async () => {
|
||||
it('returns 3 home-community entries', async () => {
|
||||
await expect(query({ query: getCommunities })).resolves.toMatchObject({
|
||||
data: {
|
||||
getCommunities: [
|
||||
@ -149,7 +150,7 @@ describe('CommunityResolver', () => {
|
||||
await DbCommunity.insert(foreignCom3)
|
||||
})
|
||||
|
||||
it('returns 3x home and 3x foreign-community entries', async () => {
|
||||
it('returns 3 home community and 3 foreign community entries', async () => {
|
||||
await expect(query({ query: getCommunities })).resolves.toMatchObject({
|
||||
data: {
|
||||
getCommunities: [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user