From 1d0c32afb03a50324fafbcfece729321468030a5 Mon Sep 17 00:00:00 2001 From: Andy Li <1450947+andy1li@users.noreply.github.com> Date: Wed, 1 Jan 2025 02:37:20 +0800 Subject: [PATCH] Add test [percy] --- .../track-page/start-track-button.hbs | 2 +- .../acceptance/track-page/start-track-test.js | 63 +++++++++++++++++++ tests/pages/track-page.js | 2 + 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/track-page/start-track-test.js diff --git a/app/components/track-page/start-track-button.hbs b/app/components/track-page/start-track-button.hbs index 2d941b868..efc21c4d5 100644 --- a/app/components/track-page/start-track-button.hbs +++ b/app/components/track-page/start-track-button.hbs @@ -1,4 +1,4 @@ - + {{#if this.currentUserIsAnonymous}} {{svg-jar "github" class="fill-current w-5 transform transition-all mr-2"}} {{/if}} diff --git a/tests/acceptance/track-page/start-track-test.js b/tests/acceptance/track-page/start-track-test.js new file mode 100644 index 000000000..0c485e1a5 --- /dev/null +++ b/tests/acceptance/track-page/start-track-test.js @@ -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'); + }); +}); diff --git a/tests/pages/track-page.js b/tests/pages/track-page.js index 1f84f3cd3..566e6d2f8 100644 --- a/tests/pages/track-page.js +++ b/tests/pages/track-page.js @@ -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]'),