|
| 1 | +import percySnapshot from '@percy/ember'; |
| 2 | +import joinTrackPage from 'codecrafters-frontend/tests/pages/join-track-page'; |
| 3 | +import testScenario from 'codecrafters-frontend/mirage/scenarios/test'; |
| 4 | +import { currentURL } from '@ember/test-helpers'; |
| 5 | +import { module, test } from 'qunit'; |
| 6 | +import { setupAnimationTest } from 'ember-animated/test-support'; |
| 7 | +import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers'; |
| 8 | +import { signIn } from 'codecrafters-frontend/tests/support/authentication-helpers'; |
| 9 | + |
| 10 | +module('Acceptance | view-join-track-page', function (hooks) { |
| 11 | + setupApplicationTest(hooks); |
| 12 | + setupAnimationTest(hooks); |
| 13 | + |
| 14 | + test('can view join track page when not logged in', async function (assert) { |
| 15 | + testScenario(this.server); |
| 16 | + |
| 17 | + this.server.create('affiliate-link', { user: this.server.schema.users.first(), slug: 'dummy' }); |
| 18 | + |
| 19 | + await joinTrackPage.visit({ track_slug: 'go' }); |
| 20 | + assert.notOk(joinTrackPage.acceptReferralButtons[0].isVisible, 'First button is hidden (for mobile only)'); |
| 21 | + assert.ok(joinTrackPage.acceptReferralButtons[1].isVisible, 'Second button is visible (leaderboard)'); |
| 22 | + assert.ok(joinTrackPage.acceptReferralButtons[2].isVisible, 'Third button is visible (bottom of page)'); |
| 23 | + assert.strictEqual(joinTrackPage.acceptReferralButtons.length, 3, 'Three accept referral buttons are present'); |
| 24 | + |
| 25 | + await percySnapshot('Join Track Page | Anonymous'); |
| 26 | + }); |
| 27 | + |
| 28 | + test('can view affiliate link when logged in', async function (assert) { |
| 29 | + testScenario(this.server); |
| 30 | + signIn(this.owner, this.server); |
| 31 | + |
| 32 | + this.server.create('affiliate-link', { user: this.server.schema.users.first(), slug: 'dummy' }); |
| 33 | + |
| 34 | + await joinTrackPage.visit({ track_slug: 'go' }); |
| 35 | + assert.notOk(joinTrackPage.acceptReferralButtons[0].isVisible, 'First button is hidden (for mobile only)'); |
| 36 | + assert.ok(joinTrackPage.acceptReferralButtons[1].isVisible, 'Second button is visible (leaderboard)'); |
| 37 | + assert.ok(joinTrackPage.acceptReferralButtons[2].isVisible, 'Third button is visible (bottom of page)'); |
| 38 | + assert.strictEqual(joinTrackPage.acceptReferralButtons.length, 3, 'Three accept referral buttons are present'); |
| 39 | + |
| 40 | + await percySnapshot('Affiliate Link Page | View Affiliate Link (anonymous)'); |
| 41 | + }); |
| 42 | + |
| 43 | + test('redirects to not found if track slug is invalid', async function (assert) { |
| 44 | + testScenario(this.server); |
| 45 | + |
| 46 | + this.server.create('affiliate-link', { user: this.server.schema.users.first(), slug: 'dummy' }); |
| 47 | + |
| 48 | + await joinTrackPage.visit({ track_slug: 'invalid', affiliate_link_slug: 'dummy' }); |
| 49 | + assert.strictEqual(currentURL(), '/404'); |
| 50 | + }); |
| 51 | + |
| 52 | + test('redirects to not found if affiliate link is invalid', async function (assert) { |
| 53 | + testScenario(this.server); |
| 54 | + |
| 55 | + await joinTrackPage.visit({ track_slug: 'rust', affiliate_link_slug: 'invalid' }); |
| 56 | + assert.strictEqual(currentURL(), '/404'); |
| 57 | + }); |
| 58 | +}); |
0 commit comments