Skip to content

Commit 3725717

Browse files
authored
Merge pull request #2700 from codecrafters-io/update-start-track-button-functionality
feat(track-page): update start track button logic
2 parents 990a0d5 + 2d9be72 commit 3725717

File tree

7 files changed

+69
-26
lines changed

7 files changed

+69
-26
lines changed

app/components/pay-page/pricing-card.hbs

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@
7272
{{svg-jar "github" class="fill-current w-4 transform transition-all mr-2"}}
7373
{{/unless}}
7474

75-
Start membership →
75+
{{#if this.authenticator.isAuthenticated}}
76+
Start membership 
77+
{{else}}
78+
Try a free project 
79+
{{/if}}
7680

7781
{{#unless this.authenticator.isAuthenticated}}
78-
<EmberTooltip @text="Login via GitHub to start a membership." />
82+
<EmberTooltip @text="Login via GitHub to try a free project." />
7983
{{/unless}}
8084
</button>
8185

app/components/track-page/header/index.hbs

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
{{#if (has-block "cta")}}
3030
{{yield to="cta"}}
3131
{{else}}
32-
{{#if this.currentUserHasStartedTrack}}
32+
{{#if this.authenticator.isAnonymous}}
33+
<div class="flex items-center flex-wrap gap-x-2 gap-y-4 mt-5">
34+
{{! TODO: Bring this back for authed users once we can account for both concepts & challenges }}
35+
<TrackPage::StartTrackButton @language={{@language}} @courses={{@courses}} />
36+
</div>
37+
{{else if this.currentUserHasStartedTrack}}
3338
<div class="flex items-center flex-wrap gap-x-2 gap-y-4 mt-5">
3439
<TrackPage::ResumeTrackButton @language={{@language}} @courses={{@courses}} />
3540

36-
{{! TODO: Bring this the "Start Track" button once we can account for both concepts & challenges }}
37-
{{!-- <TrackPage::StartTrackButton @language={{@language}} @courses={{@courses}} /> --}}
38-
3941
{{#if (gt this.topParticipants.length 0)}}
4042
<div class="hidden sm:flex items-center">
4143
<div class="flex -space-x-1 hover:space-x-1 items-center">
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<PrimaryButton class="mr-2 flex items-center" data-test-primary-start-track-button {{on "click" this.handleClicked}} @size="large" ...attributes>
2-
{{#if this.currentUserIsAnonymous}}
2+
{{! If there's no primer concept group, the user will need to login to start the track }}
3+
{{#if (and this.authenticator.isAnonymous (not @language.primerConceptGroup))}}
34
{{svg-jar "github" class="fill-current w-5 transform transition-all mr-2"}}
45
{{/if}}
56

6-
Start Track
7+
Start Learning
78

89
{{svg-jar "arrow-right" class="w-4 ml-2 fill-current"}}
910
</PrimaryButton>

app/components/track-page/start-track-button.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export default class CourseOverviewStartTrackButtonComponent extends Component<S
2121
@service declare authenticator: AuthenticatorService;
2222
@service declare router: RouterService;
2323

24-
get currentUserIsAnonymous() {
25-
return this.authenticator.isAnonymous;
26-
}
27-
2824
@action
2925
handleClicked() {
30-
if (this.currentUserIsAnonymous) {
31-
this.authenticator.initiateLogin();
26+
if (this.authenticator.isAnonymous) {
27+
if (this.args.language.primerConceptGroup) {
28+
this.router.transitionTo('concept', this.args.language.primerConceptGroup.concepts[0]!.slug);
29+
} else {
30+
this.authenticator.initiateLogin();
31+
}
3232
} else {
3333
this.router.transitionTo('course', this.args.courses[0]!.slug, { queryParams: { repo: null, track: this.args.language.slug } });
3434
}

app/controllers/pay.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export default class PayController extends Controller {
5858
this.configureCheckoutSessionModalIsOpen = true;
5959
this.selectedPricingFrequency = pricingFrequency;
6060
} else {
61-
this.authenticator.initiateLogin();
61+
// The CTA is "Try a free project ->", so doesn't make sense to redirect to /pay again
62+
this.authenticator.initiateLoginAndRedirectTo('/catalog');
6263
}
6364
}
6465

tests/acceptance/pay-test.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ module('Acceptance | pay-test', function (hooks) {
2525
await payPage.pricingCards[0].startPaymentButton.hover();
2626

2727
assertTooltipContent(assert, {
28-
contentString: 'Login via GitHub to start a membership.',
28+
contentString: 'Login via GitHub to try a free project.',
2929
});
3030
});
3131

32-
test('user can view the page through the upgrade button', async function (assert) {
32+
test('user can view the page through the pricing link', async function (assert) {
3333
testScenario(this.server);
3434

3535
await catalogPage.visit();
3636

37-
assert.ok(catalogPage.header.upgradeButton.isVisible, 'Upgrade button is visible');
38-
39-
await catalogPage.header.upgradeButton.click();
40-
37+
await catalogPage.header.clickOnHeaderLink('Pricing');
4138
assert.strictEqual(currentURL(), '/pay');
4239
});
4340

@@ -49,7 +46,7 @@ module('Acceptance | pay-test', function (hooks) {
4946

5047
assert.strictEqual(
5148
windowMock.location.href,
52-
`${windowMock.location.origin}/login?next=http%3A%2F%2Flocalhost%3A${window.location.port}%2Fpay`,
49+
`${windowMock.location.origin}/login?next=http%3A%2F%2Flocalhost%3A${window.location.port}%2Fcatalog`,
5350
'should redirect to login URL',
5451
);
5552
});

tests/acceptance/track-page/start-track-test.js

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
1+
import createConceptFromFixture from 'codecrafters-frontend/mirage/utils/create-concept-from-fixture';
2+
import networkProtocols from 'codecrafters-frontend/mirage/concept-fixtures/network-protocols';
3+
import tcpOverview from 'codecrafters-frontend/mirage/concept-fixtures/tcp-overview';
14
import testScenario from 'codecrafters-frontend/mirage/scenarios/test';
25
import trackPage from 'codecrafters-frontend/tests/pages/track-page';
3-
import { module, skip } from 'qunit';
6+
import windowMock from 'ember-window-mock';
7+
import { currentURL, visit } from '@ember/test-helpers';
8+
import { module, skip, test } from 'qunit';
49
import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers';
10+
import { setupWindowMock } from 'ember-window-mock/test-support';
511
import { signIn } from 'codecrafters-frontend/tests/support/authentication-helpers';
6-
import { currentURL, visit } from '@ember/test-helpers';
712

813
module('Acceptance | track-page | start-track', function (hooks) {
914
setupApplicationTest(hooks);
15+
setupWindowMock(hooks);
1016

11-
// TODO: Bring this back once we can account for both concepts & challenges
12-
skip('it display the start-track-button for anonymous user', async function (assert) {
17+
test('it display the start-track-button for anonymous user (Track without primer concept group)', async function (assert) {
1318
testScenario(this.server);
1419

1520
await visit('/tracks/go');
1621
assert.ok(trackPage.hasStartTrackButton, 'start track button should be visible for anonymous users');
22+
23+
await trackPage.clickOnStartTrackButton();
24+
25+
assert.strictEqual(
26+
windowMock.location.href,
27+
`${windowMock.location.origin}/login?next=http%3A%2F%2Flocalhost%3A${window.location.port}%2Ftracks%2Fgo`,
28+
'should redirect to login URL',
29+
);
30+
});
31+
32+
test('it display the start-track-button for anonymous user (Track with primer concept group)', async function (assert) {
33+
testScenario(this.server);
34+
35+
const tcpOverviewConcept = createConceptFromFixture(this.server, tcpOverview);
36+
const networkProtocolsConcept = createConceptFromFixture(this.server, networkProtocols);
37+
38+
const rustPrimerConceptGroup = this.server.create('concept-group', {
39+
author: this.server.schema.users.first(),
40+
description_markdown: 'Dummy description',
41+
concepts: [tcpOverviewConcept, networkProtocolsConcept],
42+
concept_slugs: ['tcp-overview', 'network-protocols'],
43+
slug: 'rust-primer',
44+
title: 'Rust Primer',
45+
});
46+
47+
const rust = this.server.schema.languages.findBy({ slug: 'rust' });
48+
rust.update({ primerConceptGroup: rustPrimerConceptGroup });
49+
50+
await visit('/tracks/rust');
51+
assert.ok(trackPage.hasStartTrackButton, 'start track button should be visible for anonymous users');
52+
53+
await trackPage.clickOnStartTrackButton();
54+
assert.strictEqual(currentURL(), '/concepts/tcp-overview');
1755
});
1856

1957
// TODO: Bring this back once we can account for both concepts & challenges

0 commit comments

Comments
 (0)