Skip to content

Commit 990a0d5

Browse files
authored
Merge pull request #2699 from codecrafters-io/pk-branch-3
feat(header): add dynamic links for user authentication
2 parents c2fca36 + 91801c7 commit 990a0d5

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

app/components/header/index.hbs

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@
5757
</div>
5858
</FeedbackButton>
5959

60-
<BillingStatusBadge @size="small" class="mr-3" />
61-
6260
{{#if this.authenticator.isAuthenticated}}
61+
<BillingStatusBadge @size="small" class="mr-3" />
6362
<Header::AccountDropdown />
6463
{{else}}
6564
<div class="flex items-center">

app/components/header/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ export default class HeaderComponent extends Component<Signature> {
3939
}
4040

4141
get links(): { text: string; route: string; type: 'route' | 'link' }[] {
42+
if (this.currentUser) {
43+
return this.linksForAuthenticatedUser;
44+
} else {
45+
return this.linksForAnonymousUser;
46+
}
47+
}
48+
49+
get linksForAnonymousUser(): { text: string; route: string; type: 'route' | 'link' }[] {
50+
return [
51+
{ text: 'Catalog', route: 'catalog', type: 'route' },
52+
{ text: 'Pricing', route: 'pay', type: 'route' },
53+
];
54+
}
55+
56+
get linksForAuthenticatedUser(): { text: string; route: string; type: 'route' | 'link' }[] {
4257
const links: { text: string; route: string; type: 'route' | 'link' }[] = [
4358
{ text: 'Catalog', route: 'catalog', type: 'route' },
4459
{ text: 'Badges', route: 'badges', type: 'route' },

tests/acceptance/header-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ module('Acceptance | header-test', function (hooks) {
1111
setupApplicationTest(hooks);
1212
setupAnimationTest(hooks);
1313

14-
test('header should show sign-in & upgrade button if user is unauthenticated', async function (assert) {
14+
test('header should show sign-in & pricing link if user is unauthenticated', async function (assert) {
1515
testScenario(this.server);
1616

1717
await catalogPage.visit();
1818

1919
assert.true(catalogPage.header.signInButton.isVisible, 'expect sign-in button to be visible');
20-
assert.true(catalogPage.header.upgradeButton.isVisible, 'expect billing status badge to be visible');
21-
await catalogPage.header.upgradeButton.click();
20+
assert.true(catalogPage.header.hasLink('Pricing'), 'expect pricing link to be visible');
2221

22+
await catalogPage.header.clickOnHeaderLink('Pricing');
2323
assert.strictEqual(currentURL(), '/pay', 'expect to be redirected to pay page');
2424
});
2525

tests/pages/components/header.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { clickOnText, clickable, fillable, isVisible } from 'ember-cli-page-object';
1+
import { clickOnText, collection, clickable, fillable, isVisible } from 'ember-cli-page-object';
22
import BillingStatusBadge from 'codecrafters-frontend/tests/pages/components/billing-status-badge';
33

44
export default {
@@ -16,8 +16,12 @@ export default {
1616
toggle: clickable('[data-test-feedback-button]', { resetScope: true }),
1717
},
1818

19-
freeWeeksLeftButton: BillingStatusBadge.freeWeeksLeftButton,
19+
hasLink: function (linkText) {
20+
return !!this.links.toArray().find((link) => link.text === linkText);
21+
},
2022

23+
freeWeeksLeftButton: BillingStatusBadge.freeWeeksLeftButton,
24+
links: collection('[data-test-header-link]'),
2125
memberBadge: BillingStatusBadge.memberBadge,
2226

2327
scope: '[data-test-header]',

0 commit comments

Comments
 (0)