-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1977 from codecrafters-io/add-demo-route-tests
Add tests for Demo route and components on it
- Loading branch information
Showing
17 changed files
with
407 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { module, test } from 'qunit'; | ||
import { currentURL } from '@ember/test-helpers'; | ||
import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers'; | ||
import demoPage from 'codecrafters-frontend/tests/pages/demo-page'; | ||
|
||
module('Acceptance | demo page', function (hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('it works', async function (assert) { | ||
await demoPage.visit(); | ||
assert.strictEqual(currentURL(), '/demo/code-mirror'); | ||
assert.ok(demoPage.demoTabs.codeMirror.isVisible, 'CodeMirror tab is active by default'); | ||
|
||
await demoPage.tabSwitcher.clickOnTab('DarkModeToggle'); | ||
assert.ok(demoPage.demoTabs.darkModeToggle.component.isVisible, 'DarkModeToggle tab is visible'); | ||
|
||
await demoPage.tabSwitcher.clickOnTab('FileContentsCard'); | ||
assert.ok(demoPage.demoTabs.fileContentsCard.component.isVisible, 'FileContentsCard tab is visible'); | ||
|
||
await demoPage.tabSwitcher.clickOnTab('CodeMirror'); | ||
assert.ok(demoPage.demoTabs.codeMirror.component.isVisible, 'CodeMirror tab is visible'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { module, test } from 'qunit'; | ||
import { currentURL } from '@ember/test-helpers'; | ||
import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers'; | ||
import demoPage from 'codecrafters-frontend/tests/pages/demo-page'; | ||
|
||
module('Acceptance | demo page | code-mirror', function (hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('it works', async function (assert) { | ||
await demoPage.demoTabs.codeMirror.visit(); | ||
assert.strictEqual(currentURL(), '/demo/code-mirror', 'URL is correct'); | ||
assert.ok(demoPage.demoTabs.codeMirror.component.hasRendered, 'component has rendered'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { module, test } from 'qunit'; | ||
import { currentURL } from '@ember/test-helpers'; | ||
import { run } from '@ember/runloop'; | ||
import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers'; | ||
import applicationPage from 'codecrafters-frontend/tests/pages/application-page'; | ||
import demoPage from 'codecrafters-frontend/tests/pages/demo-page'; | ||
|
||
function setLocalStoragePreference(darkModeService, preference) { | ||
run(() => { | ||
darkModeService.localStoragePreference = preference; | ||
}); | ||
} | ||
|
||
function setSystemPreference(darkModeService, preference) { | ||
run(() => { | ||
darkModeService.systemPreference = preference; | ||
}); | ||
} | ||
|
||
module('Acceptance | demo page | dark-mode-toggle', function (hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('it works', async function (assert) { | ||
await demoPage.demoTabs.darkModeToggle.visit(); | ||
assert.strictEqual(currentURL(), '/demo/dark-mode-toggle', 'URL is correct'); | ||
assert.ok(demoPage.demoTabs.darkModeToggle.component.isVisible, 'component has rendered'); | ||
}); | ||
|
||
test('it shows current localStorage preference', async function (assert) { | ||
await demoPage.demoTabs.darkModeToggle.visit(); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentLocalStoragePreference.text, 'null', 'localStorage preference is null by default'); | ||
setLocalStoragePreference(this.owner.lookup('service:dark-mode'), 'system'); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentLocalStoragePreference.text, 'system', "localStorage preference is 'system'"); | ||
setLocalStoragePreference(this.owner.lookup('service:dark-mode'), 'dark'); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentLocalStoragePreference.text, 'dark', "localStorage preference is 'dark'"); | ||
setLocalStoragePreference(this.owner.lookup('service:dark-mode'), 'light'); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentLocalStoragePreference.text, 'light', "localStorage preference is 'light'"); | ||
}); | ||
|
||
test('it shows current system preference', async function (assert) { | ||
await demoPage.demoTabs.darkModeToggle.visit(); | ||
setSystemPreference(this.owner.lookup('service:dark-mode'), 'light'); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentSystemPreference.text, 'light', "system preference is 'light'"); | ||
setSystemPreference(this.owner.lookup('service:dark-mode'), 'dark'); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentSystemPreference.text, 'dark', "system preference is 'dark'"); | ||
}); | ||
|
||
test('it updates localStorage preference after clicking on mode-switching buttons', async function (assert) { | ||
await demoPage.demoTabs.darkModeToggle.visit(); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentLocalStoragePreference.text, 'null', 'localStorage preference is null by default'); | ||
await demoPage.demoTabs.darkModeToggle.component.clickOnSystemOption(); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentLocalStoragePreference.text, 'system', "localStorage preference is 'system'"); | ||
await demoPage.demoTabs.darkModeToggle.component.clickOnDarkOption(); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentLocalStoragePreference.text, 'dark', "localStorage preference is 'dark'"); | ||
await demoPage.demoTabs.darkModeToggle.component.clickOnLightOption(); | ||
assert.strictEqual(demoPage.demoTabs.darkModeToggle.currentLocalStoragePreference.text, 'light', "localStorage preference is 'light'"); | ||
}); | ||
|
||
test("it adds a '.dark' class to application container when Dark mode is active", async function (assert) { | ||
await demoPage.demoTabs.darkModeToggle.visit(); | ||
assert.notOk(applicationPage.hasDarkClass, 'class .dark is absent by default'); | ||
await demoPage.demoTabs.darkModeToggle.component.clickOnLightOption(); | ||
assert.notOk(applicationPage.hasDarkClass, 'class .dark is absent when Light mode is selected'); | ||
await demoPage.demoTabs.darkModeToggle.component.clickOnDarkOption(); | ||
assert.ok(applicationPage.hasDarkClass, 'class .dark is present when Dark mode is selected'); | ||
await demoPage.demoTabs.darkModeToggle.component.clickOnSystemOption(); | ||
setSystemPreference(this.owner.lookup('service:dark-mode'), 'light'); | ||
assert.notOk(applicationPage.hasDarkClass, 'class .dark is absent when System mode is selected & system preference is Light'); | ||
setSystemPreference(this.owner.lookup('service:dark-mode'), 'dark'); | ||
assert.ok(applicationPage.hasDarkClass, 'class .dark is present when System mode is selected & system preference is Dark'); | ||
}); | ||
}); |
Oops, something went wrong.