PluginProbe
Extendify / 3.1.1
Extendify v3.1.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / tests / unit / Agent / lib / redirects.test.js

redirects.test.js in Extendify 3.1.1, at tests/unit/Agent/lib/redirects.test.js

69 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const adminUrl = 'https://wordpress.test/wp-admin/';
2 const homeUrl = 'https://wordpress.test/';
3
4 let getRedirectUrl;
5
6 beforeEach(async () => {
7 jest.resetModules();
8 window.extSharedData = { adminUrl, homeUrl };
9 window.extAgentData = {
10 agentContext: {
11 pluginRecommendations: [
12 {
13 slug: 'woocommerce',
14 redirectTo: 'https://wordpress.test/wp-admin/admin.php?page=wc-setup',
15 },
16 {
17 slug: 'no-redirect',
18 redirectTo: '',
19 },
20 ],
21 },
22 };
23 const mod = await import('@agent/lib/redirects');
24 getRedirectUrl = mod.getRedirectUrl;
25 });
26
27 describe('getRedirectUrl', () => {
28 it('returns a full URL for a valid plugin-setup redirect', () => {
29 const result = getRedirectUrl(
30 { type: 'plugin-setup' },
31 { pluginSlug: 'woocommerce' },
32 );
33 expect(result).toBe(
34 'https://wordpress.test/wp-admin/admin.php?page=wc-setup',
35 );
36 });
37
38 it('returns empty when redirectTo is falsy', () => {
39 expect(getRedirectUrl(null, {})).toBe('');
40 expect(getRedirectUrl(undefined, {})).toBe('');
41 expect(getRedirectUrl('', {})).toBe('');
42 });
43
44 it('returns empty for an unknown redirect type', () => {
45 const result = getRedirectUrl(
46 { type: 'unknown' },
47 { pluginSlug: 'woocommerce' },
48 );
49 expect(result).toBe('');
50 });
51
52 it('returns empty when plugin slug is not in recommendations', () => {
53 const result = getRedirectUrl(
54 { type: 'plugin-setup' },
55 { pluginSlug: 'nonexistent' },
56 );
57 expect(result).toBe('');
58 });
59
60 it('returns empty when plugin has no redirectTo value', () => {
61 const result = getRedirectUrl(
62 { type: 'plugin-setup' },
63 { pluginSlug: 'no-redirect' },
64 );
65 expect(result).toBe('');
66 expect(console).toHaveErrored();
67 });
68 });
69