Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-1539: Fix start-track button #2511

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/track-page/start-track-button.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<PrimaryButton class="mr-2 flex items-center" data-test-start-track-button {{on "click" this.handleClicked}} @size="large" ...attributes>
<PrimaryButton class="mr-2 flex items-center" data-test-primary-start-track-button {{on "click" this.handleClicked}} @size="large" ...attributes>
{{#if this.currentUserIsAnonymous}}
{{svg-jar "github" class="fill-current w-5 transform transition-all mr-2"}}
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion app/components/track-page/start-track-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class CourseOverviewStartTrackButtonComponent extends Component<S
if (this.currentUserIsAnonymous) {
this.authenticator.initiateLogin(null);
} else {
this.router.transitionTo('course', this.args.courses[0]!.slug, { queryParams: { track: this.args.language.slug } });
this.router.transitionTo('course', this.args.courses[0]!.slug, { queryParams: { repo: null, track: this.args.language.slug } });
}
}
}
Expand Down
63 changes: 63 additions & 0 deletions tests/acceptance/track-page/start-track-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import testScenario from 'codecrafters-frontend/mirage/scenarios/test';
import trackPage from 'codecrafters-frontend/tests/pages/track-page';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers';
import { signIn } from 'codecrafters-frontend/tests/support/authentication-helpers';
import { currentURL, visit } from '@ember/test-helpers';

module('Acceptance | track-page | start-track', function (hooks) {
setupApplicationTest(hooks);

test('it display the start-track-button for anonymous user', async function (assert) {
testScenario(this.server);

await visit('/tracks/go');
assert.ok(trackPage.hasStartTrackButton, 'start track button should be visible for anonymous users');
});

test('it display the start-track-button for logged-in user who has not started course in the track', async function (assert) {
testScenario(this.server);
signIn(this.owner, this.server);

await visit('/tracks/go');
assert.ok(trackPage.hasStartTrackButton, 'start track button should be visible for users without course progress');
});

test('it does not display the start-track-button for logged-in user who has started course in the track', async function (assert) {
testScenario(this.server);
signIn(this.owner, this.server);

let currentUser = this.server.schema.users.first();
let git = this.server.schema.courses.findBy({ slug: 'git' });
let go = this.server.schema.languages.findBy({ slug: 'go' });
this.server.create('repository', 'withFirstStageCompleted', {
course: git,
language: go,
user: currentUser,
});

await visit('/tracks/go');
assert.notOk(trackPage.hasStartTrackButton, 'start track button should not be visible for users with course progress');
});

test('it starts track for logged-in user who has started course in a different track', async function (assert) {
testScenario(this.server);
signIn(this.owner, this.server);

let currentUser = this.server.schema.users.first();
let grep = this.server.schema.courses.findBy({ slug: 'grep' });
let python = this.server.schema.languages.findBy({ slug: 'python' });
this.server.create('repository', 'withFirstStageCompleted', {
course: grep,
language: python,
user: currentUser,
});

await visit('/tracks/go');
assert.ok(trackPage.hasStartTrackButton, 'start track button is visible');

await trackPage.clickOnStartTrackButton();
assert.ok(currentURL().includes('track=go'), 'started course page should have `track` query param in URL');
assert.notOk(currentURL().includes('repo='), 'started course page should not have `repo` query param in URL');
});
});
2 changes: 2 additions & 0 deletions tests/pages/track-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default createPage({
},

clickOnResumeTrackButton: clickable('[data-test-resume-track-button]'),
clickOnStartTrackButton: clickable('[data-test-primary-start-track-button]'),
hasResumeTrackButton: isVisible('[data-test-resume-track-button]'),
hasStartTrackButton: isVisible('[data-test-primary-start-track-button]'),

header: {
descriptionText: text('[data-test-track-header-description]'),
Expand Down
Loading