Skip to content

Commit

Permalink
feat(api): use feature toggle for new sidebar in authenticated hbs
Browse files Browse the repository at this point in the history
fixup! feat(api): use feature toggle for new sidebar in authenticated hbs
  • Loading branch information
er-lim committed Feb 12, 2025
1 parent 85039da commit 808f67c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
10 changes: 10 additions & 0 deletions admin/app/controllers/authenticated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Controller from '@ember/controller';
import { service } from '@ember/service';

export default class AuthenticatedController extends Controller {
@service featureToggles;

get shouldDisplayNewSidebar() {
return this.featureToggles.featureToggles?.isPixAdminNewSidebarEnabled;
}
}
19 changes: 16 additions & 3 deletions admin/app/templates/authenticated.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
<Layout>
{{outlet}}
</Layout>
{{#if this.shouldDisplayNewSidebar}}
<PixAppLayout @variant="primary">
<:navigation>
<Layout::Sidebar />
</:navigation>
<:main>
<main>
{{outlet}}
</main>
</:main>
</PixAppLayout>
{{else}}
<Layout>
{{outlet}}
</Layout>
{{/if}}
60 changes: 60 additions & 0 deletions admin/tests/acceptance/authenticated-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { visit, within } from '@1024pix/ember-testing-library';
import Service from '@ember/service';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { setupApplicationTest } from 'ember-qunit';
import { module, test } from 'qunit';

import { authenticateAdminMemberWithRole } from '../helpers/test-init';

module('Acceptance | Authenticated pages', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

module('When "isPixAdminNewSidebarEnabled" feature toggle has "false" value', function (hooks) {
hooks.beforeEach(async function () {
// given
class FeatureTogglesStub extends Service {
featureToggles = { isPixAdminNewSidebarEnabled: false };

load() {}
}
this.owner.register('service:featureToggles', FeatureTogglesStub);

await authenticateAdminMemberWithRole({ isSuperAdmin: true })(server);
});

test('it displays old layout with its menu-bar', async function (assert) {
// when
const screen = await visit('/');

// then
assert.dom(screen.getByRole('navigation', { name: 'Navigation principale' })).exists();
});
});

module('When "isPixAdminNewSidebarEnabled" feature toggle has "true" value', function (hooks) {
hooks.beforeEach(async function () {
// given
class FeatureTogglesStub extends Service {
featureToggles = { isPixAdminNewSidebarEnabled: true };

load() {}
}
this.owner.register('service:featureToggles', FeatureTogglesStub);

await authenticateAdminMemberWithRole({ isSuperAdmin: true })(server);
});

test('it displays new layout', async function (assert) {
// when
const screen = await visit('/');

// then
const navBar = screen.getByRole('complementary');
const footer = within(navBar).getByRole('contentinfo');

assert.dom(footer).exists();
assert.ok(within(footer).getByRole('link', { name: 'Se déconnecter' }));
});
});
});

0 comments on commit 808f67c

Please sign in to comment.