diff --git a/frontend/src/components/Menu/Sidebar.spec.js b/frontend/src/components/Menu/Sidebar.spec.js index 23c855557..77a525f3b 100644 --- a/frontend/src/components/Menu/Sidebar.spec.js +++ b/frontend/src/components/Menu/Sidebar.spec.js @@ -34,7 +34,7 @@ describe('Sidebar', () => { describe('the genaral section', () => { it('has six nav-items', () => { - expect(wrapper.findAll('ul').at(0).findAll('.nav-item')).toHaveLength(6) + expect(wrapper.findAll('ul').at(0).findAll('.nav-item')).toHaveLength(7) }) it('has nav-item "navigation.overview" in navbar', () => { @@ -60,6 +60,10 @@ describe('Sidebar', () => { it('has nav-item "navigation.info" in navbar', () => { expect(wrapper.findAll('.nav-item').at(5).text()).toContain('navigation.info') }) + + it('has nav-item "usersearch" in navbar', () => { + expect(wrapper.findAll('.nav-item').at(6).text()).toContain('navigation.usersearch') + }) }) describe('the specific section', () => { diff --git a/frontend/src/pages/UserSearch.spec.js b/frontend/src/pages/UserSearch.spec.js new file mode 100644 index 000000000..20116b523 --- /dev/null +++ b/frontend/src/pages/UserSearch.spec.js @@ -0,0 +1,80 @@ +import { mount, RouterLinkStub } from '@vue/test-utils' +import UserSearch from './UserSearch' +import { toastErrorSpy } from '../../test/testSetup' +import { authenticateGmsUserSearch } from '@/graphql/queries' + +const localVue = global.localVue + +window.scrollTo = jest.fn() + +const stubs = { + RouterLink: RouterLinkStub, +} + +const apolloQueryMock = jest + .fn() + .mockResolvedValueOnce({ + data: { + authenticateGmsUserSearch: { + gmsUri: 'http://localhost:8080/playground?not initialized', + }, + }, + }) + .mockResolvedValue('default') + + +describe('UserSearch', () => { + let wrapper + + const mocks = { + $t: jest.fn((t) => t), + $n: jest.fn(), + $i18n: { + locale: 'en', + }, + $apollo: { + query: apolloQueryMock, + }, + } + + const Wrapper = () => { + return mount(UserSearch, { + localVue, + mocks, + }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('renders the usersearch page', () => { + expect(wrapper.find('div.usersearch').exists()).toBeTruthy() + }) + + it('calls authenticateGmsUserSearch', () => { + expect(apolloQueryMock).toBeCalledWith( + expect.objectContaining({ + query: authenticateGmsUserSearch, + }), + ) + }) + + describe('error apolloQueryMock', () => { + beforeEach(async () => { + jest.clearAllMocks() + apolloQueryMock.mockRejectedValue({ + message: 'uups', + }) + wrapper = Wrapper() + }) + + it('toasts an error message', () => { + expect(toastErrorSpy).toBeCalledWith( + 'authenticateGmsUserSearch failed!', + ) + }) + }) + }) +}) diff --git a/frontend/src/routes/router.test.js b/frontend/src/routes/router.test.js index 6d7e7b2a0..af6b1c431 100644 --- a/frontend/src/routes/router.test.js +++ b/frontend/src/routes/router.test.js @@ -49,8 +49,8 @@ describe('router', () => { expect(routes.find((r) => r.path === '/').redirect()).toEqual({ path: '/login' }) }) - it('has 19 routes defined', () => { - expect(routes).toHaveLength(19) + it('has 20 routes defined', () => { + expect(routes).toHaveLength(20) }) describe('overview', () => { @@ -142,6 +142,17 @@ describe('router', () => { }) }) + describe('usersearch', () => { + it('requires authorization', () => { + expect(routes.find((r) => r.path === '/usersearch').meta.requiresAuth).toBeTruthy() + }) + + it('loads the "UserSearch" page', async () => { + const component = await routes.find((r) => r.path === '/usersearch').component() + expect(component.default.name).toBe('UserSearch') + }) + }) + describe('gdt', () => { it('requires authorization', () => { expect(routes.find((r) => r.path === '/gdt').meta.requiresAuth).toBeTruthy()