|
| 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'; |
1 | 4 | import testScenario from 'codecrafters-frontend/mirage/scenarios/test';
|
2 | 5 | 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'; |
4 | 9 | import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers';
|
| 10 | +import { setupWindowMock } from 'ember-window-mock/test-support'; |
5 | 11 | import { signIn } from 'codecrafters-frontend/tests/support/authentication-helpers';
|
6 |
| -import { currentURL, visit } from '@ember/test-helpers'; |
7 | 12 |
|
8 | 13 | module('Acceptance | track-page | start-track', function (hooks) {
|
9 | 14 | setupApplicationTest(hooks);
|
| 15 | + setupWindowMock(hooks); |
10 | 16 |
|
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) { |
13 | 18 | testScenario(this.server);
|
14 | 19 |
|
15 | 20 | await visit('/tracks/go');
|
16 | 21 | 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'); |
17 | 55 | });
|
18 | 56 |
|
19 | 57 | // TODO: Bring this back once we can account for both concepts & challenges
|
|
0 commit comments