-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: create component to list namespaces
This commit creates a component to separate the code into another component. Signed-off-by: Leonardo R.S. Joao <leonardo.joao@ossystems.com.br>
- Loading branch information
1 parent
33c2c86
commit af491cb
Showing
6 changed files
with
234 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<template> | ||
<fragment> | ||
<v-list-item | ||
v-for="item in namespaces" | ||
:key="item.tenant_id" | ||
link | ||
@click="switchIn(item.tenant_id)" | ||
> | ||
<v-list-item-content> | ||
<v-list-item-title | ||
:data-test="item.name+'-namespace'" | ||
v-text="item.name" | ||
/> | ||
</v-list-item-content> | ||
</v-list-item> | ||
</fragment> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'NamespaceList', | ||
computed: { | ||
namespace() { | ||
return this.$store.getters['namespaces/get']; | ||
}, | ||
namespaces() { | ||
return this.$store.getters['namespaces/list'].filter((el) => el.name !== this.namespace.name); | ||
}, | ||
}, | ||
methods: { | ||
async switchIn(tenant) { | ||
try { | ||
await this.$store.dispatch('namespaces/switchNamespace', { | ||
tenant_id: tenant, | ||
}); | ||
window.location.reload(); | ||
} catch { | ||
this.$store.dispatch('snackbar/showSnackbarErrorLoading', this.$errors.snackbar.namespaceSwitch); | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> |
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
147 changes: 147 additions & 0 deletions
147
ui/tests/unit/components/namespaces/NamespaceList.spec.js
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,147 @@ | ||
import Vuex from 'vuex'; | ||
import { shallowMount, createLocalVue } from '@vue/test-utils'; | ||
import Vuetify from 'vuetify'; | ||
import NamespaceList from '@/components/namespace/NamespaceList'; | ||
|
||
describe('Namespace', () => { | ||
const localVue = createLocalVue(); | ||
const vuetify = new Vuetify(); | ||
localVue.use(Vuex); | ||
|
||
let wrapper; | ||
|
||
const namespace = { | ||
name: 'namespace3', | ||
owner: 'user1', | ||
member_names: ['user6', 'user7', 'user8'], | ||
tenant_id: 'e359bf484715', | ||
}; | ||
|
||
const namespaces = [ | ||
{ | ||
name: 'namespace1', | ||
owner: 'user1', | ||
member_names: ['user3', 'user4', 'user5'], | ||
tenant_id: 'xxxxxxxx', | ||
}, | ||
{ | ||
name: 'namespace2', | ||
owner: 'user1', | ||
member_names: ['user3', 'user4'], | ||
tenant_id: 'xxxxxxxy', | ||
}, | ||
]; | ||
|
||
const store = new Vuex.Store({ | ||
namespaced: true, | ||
state: { | ||
namespace, | ||
namespaces, | ||
}, | ||
getters: { | ||
'namespaces/list': (state) => state.namespaces, | ||
'namespaces/get': (state) => state.namespace, | ||
}, | ||
actions: { | ||
'namespaces/switchNamespace': () => {}, | ||
'snackbar/showSnackbarErrorLoading': () => {}, | ||
}, | ||
}); | ||
|
||
/////// | ||
// In this case, check owner fields rendering in enterprise version. | ||
/////// | ||
|
||
describe('Enterprise version', () => { | ||
beforeEach(() => { | ||
wrapper = shallowMount(NamespaceList, { | ||
store, | ||
localVue, | ||
stubs: ['fragment'], | ||
vuetify, | ||
}); | ||
}); | ||
|
||
/////// | ||
// Component Rendering | ||
////// | ||
|
||
it('Is a Vue Instance', () => { | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
it('Renders the component', () => { | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
/////// | ||
// Data and Props checking | ||
////// | ||
|
||
it('Process data in the computed', () => { | ||
expect(wrapper.vm.namespace).toEqual(namespace); | ||
expect(wrapper.vm.namespaces).toEqual(namespaces.filter((el) => el.name !== namespace.name)); | ||
}); | ||
|
||
////// | ||
// HTML validation | ||
////// | ||
|
||
it('Renders the template with data', async () => { | ||
const namespacesLocal = namespaces.filter((el) => el.name !== namespace.name); | ||
|
||
Object.keys(namespacesLocal).forEach((item) => { | ||
expect(wrapper.find(`[data-test="${namespacesLocal[item].name}-namespace"]`).text()).toEqual(namespacesLocal[item].name); | ||
}); | ||
}); | ||
}); | ||
|
||
/////// | ||
// In this case, check owner fields rendering in open version | ||
// of the template. | ||
/////// | ||
|
||
describe('Open version', () => { | ||
beforeEach(() => { | ||
wrapper = shallowMount(NamespaceList, { | ||
store, | ||
localVue, | ||
stubs: ['fragment', 'router-link'], | ||
vuetify, | ||
}); | ||
|
||
jest.spyOn(Storage.prototype, 'getItem').mockReturnValue(namespace.tenant_id); | ||
}); | ||
|
||
/////// | ||
// Component Rendering | ||
////// | ||
|
||
it('Is a Vue Instance', () => { | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
it('Renders the component', () => { | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
/////// | ||
// Data and Props checking | ||
////// | ||
|
||
it('Process data in the computed', () => { | ||
expect(wrapper.vm.namespace).toEqual(namespace); | ||
expect(wrapper.vm.namespaces).toEqual(namespaces.filter((el) => el.name !== namespace.name)); | ||
}); | ||
|
||
////// | ||
// HTML validation | ||
////// | ||
|
||
it('Renders the template with data', async () => { | ||
const namespacesLocal = namespaces.filter((el) => el.name !== namespace.name); | ||
|
||
Object.keys(namespacesLocal).forEach((item) => { | ||
expect(wrapper.find(`[data-test="${namespacesLocal[item].name}-namespace"]`).text()).toEqual(namespacesLocal[item].name); | ||
}); | ||
}); | ||
}); | ||
}); |
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
31 changes: 31 additions & 0 deletions
31
ui/tests/unit/components/namespaces/__snapshots__/NamespaceList.spec.js.snap
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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Namespace Enterprise version Renders the component 1`] = ` | ||
<fragment-stub> | ||
<v-list-item-stub activeclass="" link="true" tag="div"> | ||
<v-list-item-content-stub tag="div"> | ||
<v-list-item-title-stub tag="div" data-test="namespace1-namespace">namespace1</v-list-item-title-stub> | ||
</v-list-item-content-stub> | ||
</v-list-item-stub> | ||
<v-list-item-stub activeclass="" link="true" tag="div"> | ||
<v-list-item-content-stub tag="div"> | ||
<v-list-item-title-stub tag="div" data-test="namespace2-namespace">namespace2</v-list-item-title-stub> | ||
</v-list-item-content-stub> | ||
</v-list-item-stub> | ||
</fragment-stub> | ||
`; | ||
|
||
exports[`Namespace Open version Renders the component 1`] = ` | ||
<fragment-stub> | ||
<v-list-item-stub activeclass="" link="true" tag="div"> | ||
<v-list-item-content-stub tag="div"> | ||
<v-list-item-title-stub tag="div" data-test="namespace1-namespace">namespace1</v-list-item-title-stub> | ||
</v-list-item-content-stub> | ||
</v-list-item-stub> | ||
<v-list-item-stub activeclass="" link="true" tag="div"> | ||
<v-list-item-content-stub tag="div"> | ||
<v-list-item-title-stub tag="div" data-test="namespace2-namespace">namespace2</v-list-item-title-stub> | ||
</v-list-item-content-stub> | ||
</v-list-item-stub> | ||
</fragment-stub> | ||
`; |