Skip to content

Commit

Permalink
Merge pull request #3 from zfir-dev/first-tests
Browse files Browse the repository at this point in the history
First tests
  • Loading branch information
zfir authored Jul 13, 2024
2 parents 9ecf4cf + 9af13f3 commit c893ca4
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 15 deletions.
File renamed without changes.
19 changes: 9 additions & 10 deletions app/components/input-modal.hbs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<!-- app/components/input-modal.hbs -->
{{!-- app/components/input-modal.hbs --}}
<div class="input-modal">
<div class="modal-content">
<button {{on "click" this.closeModal}}>X</button>
<label>First Name</label>
<input type="text" value={{this.firstName}} {{on "input" this.updateFirstName}} />
<button type="button" {{on "click" this.closeModal}}>X</button>
<label for="first-name">First Name</label>
<input id="first-name" type="text" value={{this.firstName}} {{on "input" this.updateFirstName}} />

<label>Last Name</label>
<input type="text" value={{this.lastName}} {{on "input" this.updateLastName}} />
<label for="last-name">Last Name</label>
<input id="last-name" type="text" value={{this.lastName}} {{on "input" this.updateLastName}} />

<label>Email</label>
<input type="email" value={{this.email}} {{on "input" this.updateEmail}} />

<button {{on "click" this.save}}>Save</button>
<label for="email">Email</label>
<input id="email" type="email" value={{this.email}} {{on "input" this.updateEmail}} />
<button type="button" {{on "click" this.save}}>Save</button>
</div>
</div>
File renamed without changes.
4 changes: 2 additions & 2 deletions app/components/open-modal-button.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- app/components/open-modal-button.hbs -->
<button {{on "click" this.openModal}}>Open Modal</button>
{{!-- app/components/open-modal-button.hbs --}}
<button type="button" {{on "click" this.openModal}}>Open Modal</button>
{{#if this.isModalOpen}}
<InputModal @closeModal={{this.closeModal}} />
{{/if}}
File renamed without changes.
5 changes: 3 additions & 2 deletions app/styles/app.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Ember supports plain CSS out of the box. More info: https://cli.emberjs.com/release/advanced-use/stylesheets/ */

/* app/styles/app.css */
.input-modal {
position: fixed;
Expand All @@ -8,8 +9,8 @@
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
background-color: rgb(0 0 0);
background-color: rgb(0 0 0 / 40%);
padding-top: 60px;
}

Expand Down
2 changes: 1 addition & 1 deletion app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- app/templates/application.hbs -->
{{!-- app/templates/application.hbs --}}
<h2>Welcome to DevCon 2024 Ember.js Test Demo</h2>
<OpenModalButton />
{{outlet}}
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@types/ember-data__store": "^4.0.7",
"@types/ember-qunit": "^6.1.1",
"@types/ember-resolver": "^9.0.0",
"@types/htmlbars-inline-precompile": "^3.0.0",
"@types/qunit": "^2.19.10",
"@types/rsvp": "^4.0.9",
"broccoli-asset-rev": "^3.0.0",
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/input-modal-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// tests/integration/components/input-modal-test.ts
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | input-modal', function (hooks) {
setupRenderingTest(hooks);

test('it renders input fields, a close button and a save button', async function (assert) {
await render(hbs`<InputModal />`);
assert.dom('input[type="text"]:nth-of-type(1)').exists();
assert.dom('input[type="text"]:nth-of-type(2)').exists();
assert.dom('input[type="email"]').exists();
assert.dom('button:nth-of-type(1)').hasText('X');
assert.dom('button:nth-of-type(2)').hasText('Save');
});
});
33 changes: 33 additions & 0 deletions tests/integration/open-modal-button-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// tests/integration/components/input-modal-test.ts
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { click, findAll, render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | open-modal-button', function (hooks) {
setupRenderingTest(hooks);

test('it renders the open modal button', async function (assert) {
await render(hbs`<OpenModalButton />`);
assert.dom('button').hasText('Open Modal');
});

test('it opens the modal when the button is clicked', async function (assert) {
await render(hbs`<OpenModalButton />`);
assert.dom('input[type="text"]:nth-of-type(1)').doesNotExist();
assert.strictEqual(
findAll('button').filter((btn) => btn.textContent?.trim() === 'Save')
.length,
0,
'Save button does not exist before clicking',
);
await click('button');
assert.dom('input[type="text"]:nth-of-type(1)').exists();
assert.strictEqual(
findAll('button').filter((btn) => btn.textContent?.trim() === 'Save')
.length,
1,
'Save button exists after clicking',
);
});
});
File renamed without changes.

0 comments on commit c893ca4

Please sign in to comment.