Skip to content

Commit 6640533

Browse files
committed
test: added unit tests for AlertUpdateToLatest
1 parent 5232f91 commit 6640533

File tree

2 files changed

+61
-24
lines changed

2 files changed

+61
-24
lines changed

src/components/alert/AlertModuleDependencies.spec.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe('AlertModuleDependencies component tests', () => {
1919
props: {
2020
psAccountsEnableLink: '/enable',
2121
psAccountsInstallLink: '/install',
22-
psAccountsUpdateLink: '/update',
2322
psIs17: true,
2423
...props
2524
},
@@ -85,29 +84,6 @@ describe('AlertModuleDependencies component tests', () => {
8584
});
8685
});
8786

88-
it('should display the Ps Accounts is not uptodate alert', async () => {
89-
vi.mocked<any>(global.fetch).mockImplementationOnce(async () => ({
90-
status: 200,
91-
ok: true,
92-
json: async () => ({
93-
[Module.PsAccounts]: {
94-
status: true
95-
}
96-
})
97-
}));
98-
factory({
99-
psAccountsIsEnabled: true,
100-
psAccountsIsInstalled: true
101-
});
102-
expect(findAlertTitle().text()).toBe(`psaccounts.alert.${Module.PsAccounts}.${Action.Update}.title`);
103-
expect(findAlertDescription().text()).toBe(`psaccounts.alert.${Module.PsAccounts}.${Action.Update}.message`);
104-
expect(findAlertButton().text()).toBe(`psaccounts.alert.${Module.PsAccounts}.${Action.Update}.action`);
105-
await findAlertButton().trigger('click');
106-
expect(fetch).toHaveBeenCalledWith('/update', {
107-
method: 'POST'
108-
});
109-
});
110-
11187
it('should display an error message if alert action fails', async () => {
11288
vi.mocked<any>(global.fetch).mockImplementationOnce(() => ({
11389
status: 404
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { describe, it, vi, expect, afterEach } from 'vitest';
2+
import { MountingOptions, VueWrapper, mount } from '@vue/test-utils';
3+
import AlertUpdateToLatest from './AlertUpdateToLatest.vue';
4+
type ComponentProps = InstanceType<typeof AlertUpdateToLatest>['$props'];
5+
6+
describe('AlertUpdateToLatest component tests', () => {
7+
// @ts-expect-error SILENCE JSDOM ERRORS ABOUT LOCATION RELOAD
8+
window.location = vi.fn();
9+
global.fetch = vi.fn();
10+
let wrapper: VueWrapper<any>;
11+
const findAlertButton = () => wrapper.find('.puik-button');
12+
13+
const factory = (props: ComponentProps, options: MountingOptions<any> = {}) => {
14+
wrapper = mount(AlertUpdateToLatest, {
15+
props,
16+
...options
17+
});
18+
};
19+
20+
afterEach(() => {
21+
vi.clearAllMocks();
22+
});
23+
24+
it('should call the update route on click', async () => {
25+
vi.mocked<any>(global.fetch).mockImplementationOnce(async () => ({
26+
status: 200,
27+
ok: true,
28+
json: async () => ({
29+
ps_accounts: {
30+
status: true
31+
}
32+
})
33+
}));
34+
factory({
35+
enableLink: '/enable'
36+
});
37+
expect(findAlertButton());
38+
await findAlertButton().trigger('click');
39+
expect(fetch).toHaveBeenCalledWith('/upgrade', {
40+
method: 'POST'
41+
});
42+
});
43+
44+
it('should not call the update route on click if there is no link passed', async () => {
45+
vi.mocked<any>(global.fetch).mockImplementationOnce(async () => ({
46+
status: 200,
47+
ok: true,
48+
json: async () => ({
49+
ps_accounts: {
50+
status: true
51+
}
52+
})
53+
}));
54+
factory({
55+
enableLink: null
56+
});
57+
expect(findAlertButton());
58+
await findAlertButton().trigger('click');
59+
expect(fetch).not.toBeCalled();
60+
});
61+
});

0 commit comments

Comments
 (0)