Skip to content

Commit 77da8c7

Browse files
committed
Fixed tests
1 parent 2d0b0f2 commit 77da8c7

File tree

1 file changed

+8
-33
lines changed

1 file changed

+8
-33
lines changed

frontend/__tests__/components/GLogin.spec.js

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ describe('components', () => {
3434
let loginStore // eslint-disable-line no-unused-vars
3535
let localStorageStore
3636
let mockRoute
37-
let mockRouter
38-
let mockNext
3937

4038
function mountLogin () {
4139
return mount(GLogin, {
@@ -49,7 +47,6 @@ describe('components', () => {
4947
],
5048
mocks: {
5149
$route: mockRoute,
52-
$router: mockRouter,
5350
},
5451
},
5552
})
@@ -73,10 +70,6 @@ describe('components', () => {
7370
redirectPath: '/namespace/garden/shoots',
7471
},
7572
}
76-
mockRouter = {
77-
push: vi.fn(),
78-
replace: vi.fn(),
79-
}
8073
pinia = createTestingPinia({
8174
stubActions: false,
8275
initialState: {
@@ -120,25 +113,17 @@ describe('components', () => {
120113
title: error.title,
121114
}),
122115
}
123-
mockNext = vi.fn().mockImplementation(fn => {
124-
if (typeof fn === 'function') {
125-
fn(wrapper.vm)
126-
}
127-
})
128-
await GLogin.beforeRouteEnter.call(wrapper.vm, to, undefined, mockNext)
129-
expect(wrapper.vm.error.message).toBe(error.message)
130-
await GLogin.beforeRouteUpdate.call(wrapper.vm, undefined, undefined, () => {})
131-
expect(mockNext).toBeCalledTimes(1)
132-
expect(mockNext.mock.calls[0]).toEqual([expect.any(Function)])
116+
117+
await GLogin.beforeRouteEnter.call(wrapper.vm, to, undefined)
118+
expect(wrapper.vm.loginError.message).toBe(error.message)
119+
await GLogin.mounted.call(wrapper.vm)
133120
expect(appStore.setError).toBeCalledTimes(1)
134121
expect(appStore.setError.mock.calls[0]).toEqual([
135122
expect.objectContaining({
136123
message: 'error',
137124
title: 'title',
138125
}),
139126
])
140-
expect(mockRouter.replace).toBeCalledTimes(1)
141-
expect(mockRouter.replace.mock.calls[0]).toEqual(['/login'])
142127
})
143128

144129
it('should not show a login error', async () => {
@@ -150,17 +135,10 @@ describe('components', () => {
150135
title: error.title,
151136
}),
152137
}
153-
mockNext = vi.fn().mockImplementation(fn => {
154-
if (typeof fn === 'function') {
155-
fn(wrapper.vm)
156-
}
157-
})
158-
await GLogin.beforeRouteEnter.call(wrapper.vm, to, undefined, mockNext)
159-
expect(mockNext).toBeCalledTimes(1)
160-
expect(mockNext.mock.calls[0]).toEqual([expect.any(Function)])
138+
139+
await GLogin.beforeRouteEnter.call(wrapper.vm, to, undefined)
140+
await GLogin.mounted.call(wrapper.vm)
161141
expect(appStore.setError).not.toBeCalled()
162-
expect(mockRouter.replace).toBeCalledTimes(1)
163-
expect(mockRouter.replace.mock.calls[0]).toEqual(['/login'])
164142
})
165143

166144
it('should automatically login', async () => {
@@ -171,10 +149,7 @@ describe('components', () => {
171149
redirectPath: '/namespace/garden-foo/shoots',
172150
},
173151
}
174-
mockNext = vi.fn()
175-
await GLogin.beforeRouteEnter.call(wrapper.vm, to, undefined, mockNext)
176-
expect(mockNext).toBeCalledTimes(1)
177-
expect(mockNext.mock.calls[0]).toEqual([false])
152+
await GLogin.beforeRouteEnter.call(wrapper.vm, to, undefined)
178153
expect(authnStore.signinWithOidc).toBeCalledTimes(1)
179154
expect(authnStore.signinWithOidc.mock.calls[0]).toEqual([to.query.redirectPath])
180155
})

0 commit comments

Comments
 (0)