Skip to content

Commit

Permalink
fix: user menu is visible even when no auth is active (#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKoe committed Apr 28, 2023
1 parent 8f16132 commit 6c6ad38
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ const DEFAULT_CONFIG = {
},
};

export default merge(DEFAULT_CONFIG, window.SBA);
export default merge(DEFAULT_CONFIG, global.SBA);
35 changes: 35 additions & 0 deletions spring-boot-admin-server-ui/src/main/frontend/shell/navbar.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { screen } from '@testing-library/vue';
import { describe, expect, it, vi } from 'vitest';

import Navbar from '@/shell/navbar.vue';
import { render } from '@/test-utils';

vi.mock('@/sba-config');

describe('Navbar', function () {
it('User menu is visible, when a user is logged in', async function () {
const config = await vi.importActual('@/sba-config');
return {
default: {
...config.default,
user: {
name: 'mail@example.com',
},
},
};

render(Navbar);

expect(screen.queryByText('mail@example.org')).toBeVisible();
});

it('User menu is hidden, when no user is logged in', async function () {
global.SBA = {
user: null,
};

render(Navbar);

expect(screen.queryByText('mail@example.org')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
:available-locales="AVAILABLE_LANGUAGES"
@locale-changed="changeLocale"
/>
<sba-nav-usermenu />
<sba-nav-usermenu v-if="sbaConfig.user" />
<sba-nav-item :to="{ name: 'about' }">
<FontAwesomeIcon icon="question-circle" />
</sba-nav-item>
Expand Down
14 changes: 8 additions & 6 deletions spring-boot-admin-server-ui/src/main/frontend/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ import components from './components/index.js';
import terms from './i18n/i18n.en.json';
import SbaModalPlugin from './plugins/modal';

import { createViewRegistry } from '@/composables/ViewRegistry';
import ViewRegistry from '@/viewRegistry';

export let router;
createViewRegistry();

export const render = (testComponent, options) => {
let routes = [{ path: '/', component: testComponent }];
export const render = (testComponent, options?: any) => {
const routes = [{ path: '/', component: testComponent }];
if (testComponent.install) {
let viewRegistry = new ViewRegistry();
const viewRegistry = new ViewRegistry();
testComponent.install({ viewRegistry });
let routeForComponent = viewRegistry._toRoutes(
const routeForComponent = viewRegistry._toRoutes(
viewRegistry.views,
() => true
)[0];
Expand All @@ -34,7 +36,7 @@ export const render = (testComponent, options) => {
routes: routes,
});

let renderOptions = merge(
const renderOptions = merge(
{
global: {
plugins: [
Expand All @@ -56,6 +58,6 @@ export const render = (testComponent, options) => {
},
options
);
let utils = tlRender(testComponent, renderOptions);
const utils = tlRender(testComponent, renderOptions);
return { ...utils };
};
1 change: 1 addition & 0 deletions spring-boot-admin-server-ui/tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ global.ResizeObserver = vi.fn().mockImplementation(() => ({

// runs a cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
vi.clearAllMocks();
cleanup();
});

0 comments on commit 6c6ad38

Please sign in to comment.