Skip to content

Commit 71dee87

Browse files
committed
Fix unit tests
Signed-off-by: Phillip Rak <rak.phillip@gmail.com>
1 parent 3e9ae35 commit 71dee87

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

shell/edit/auth/__tests__/oidc.test.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { nextTick } from 'vue';
22
/* eslint-disable jest/no-hooks */
3-
import { mount, type VueWrapper } from '@vue/test-utils';
3+
import { mount, type VueWrapper, flushPromises } from '@vue/test-utils';
44
import { _EDIT } from '@shell/config/query-params';
55

66
import oidc from '@shell/edit/auth/oidc.vue';
@@ -9,6 +9,18 @@ jest.mock('@shell/utils/clipboard', () => {
99
return { copyTextToClipboard: jest.fn(() => Promise.resolve({})) };
1010
});
1111

12+
const mockStore = {
13+
getters: {
14+
'i18n/t': (key: string) => key,
15+
'i18n/exists': () => false,
16+
},
17+
};
18+
19+
jest.mock('vuex', () => ({
20+
...jest.requireActual('vuex'),
21+
useStore: () => mockStore,
22+
}));
23+
1224
const validClientId = 'rancheroidc';
1325
const validClientSecret = 'TOkUxg0P67m1UXWNkJLHDPkUZFIKOWSq';
1426
const validUrl = 'https://localhost:8080';
@@ -79,20 +91,26 @@ describe('oidc.vue', () => {
7991
});
8092

8193
describe('have "Create" button disabled', () => {
82-
it('given missing Auth endpoint URL', () => {
94+
// validateAllFields() replicates what happens on blur in a real browser: it runs
95+
// the toTypedSchema validators for every registered field and flushes async errors.
96+
it('given missing Auth endpoint URL', async() => {
8397
wrapper.vm.model.authEndpoint = '';
8498
wrapper.vm.model.scopes = 'openid profile email'; // set scope to be sure
8599
wrapper.vm.oidcScope = ['openid', 'profile', 'email']; // TODO #13457: this is duplicated due wrong format of scopes
100+
await wrapper.vm.validateAllFields();
101+
await flushPromises();
86102

87103
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement;
88104

89105
expect(saveButton.disabled).toBe(true);
90106
});
91107

92-
it('given missing required basic scopes', () => {
93-
wrapper.vm.model.authEndpoint = 'whatever'; // set auth endpoint to be sure
108+
it('given missing required basic scopes', async() => {
109+
wrapper.vm.model.authEndpoint = validAuthEndpoint; // set auth endpoint to be sure
94110
wrapper.vm.model.scopes = 'something else'; // set wrong scope
95111
wrapper.vm.oidcScope = ['something', 'else']; // TODO #13457: this is duplicated due wrong format of scopes
112+
await wrapper.vm.validateAllFields();
113+
await flushPromises();
96114

97115
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement;
98116

@@ -101,7 +119,8 @@ describe('oidc.vue', () => {
101119

102120
it('when provider is disabled and editing config before fields are filled in', async() => {
103121
wrapper.setData({ model: {}, editConfig: true });
104-
await nextTick();
122+
await wrapper.vm.validateAllFields();
123+
await flushPromises();
105124

106125
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement;
107126

@@ -110,7 +129,8 @@ describe('oidc.vue', () => {
110129

111130
it('when provider is disabled and editing config after required fields and scope is missing openid', async() => {
112131
wrapper.setData({ oidcUrls: { url: validUrl, realm: validRealm } });
113-
await nextTick();
132+
await wrapper.vm.validateAllFields();
133+
await flushPromises();
114134

115135
const saveButton = wrapper.find('[data-testid="form-save"]').element as HTMLInputElement;
116136

0 commit comments

Comments
 (0)