Skip to content

Commit

Permalink
Merge pull request #7993 from jrjohnson/convert-test
Browse files Browse the repository at this point in the history
Convert Test to Page Object
  • Loading branch information
jrjohnson authored Jul 24, 2024
2 parents 18e426d + 1acf4c1 commit 18d3154
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
32 changes: 13 additions & 19 deletions packages/frontend/tests/acceptance/programs-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { click, fillIn, find, currentURL, currentRouteName, visit } from '@ember/test-helpers';
import { currentURL, currentRouteName } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupAuthentication } from 'ilios-common';
import { setupApplicationTest } from 'frontend/tests/helpers';
Expand All @@ -25,26 +25,20 @@ module('Acceptance | Programs', function (hooks) {

test('add new program', async function (assert) {
this.user.update({ administeredSchools: [this.school] });
assert.expect(3);
const url = '/programs';
const expandButton = '.expand-button';
const input = '.new-program input';
const saveButton = '.new-program .done';
const savedLink = '.saved-result a';

await visit(url);
await click(expandButton);
assert.expect(6);
await page.visit();

assert.ok(page.root.toggleNewProgramFormExists);
await page.root.toggleNewProgramForm();
await percySnapshot(getUniqueName(assert, 'expandButton'));
await fillIn(input, 'Test Title');
await click(saveButton);
await page.root.newProgramForm.title.set('Test Title');
await page.root.newProgramForm.done.click();
await percySnapshot(getUniqueName(assert, 'saveButton'));
function getContent(i) {
return find(`tbody tr td:nth-of-type(${i + 1})`).textContent.trim();
}

assert.dom(savedLink).hasText('Test Title', 'link is visisble');
assert.strictEqual(getContent(0), 'Test Title', 'program is correct');
assert.strictEqual(getContent(1), 'school 0', 'school is correct');
assert.strictEqual(this.server.db.programs.length, 1);
assert.strictEqual(page.root.list.items.length, 1);
assert.dom('.flash-messages').exists({ count: 1 });
assert.strictEqual(page.root.list.items[0].title, 'Test Title');
assert.strictEqual(page.root.list.items[0].school, 'school 0');
});

test('remove program', async function (assert) {
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/tests/pages/components/programs/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
value,
} from 'ember-cli-page-object';
import list from './list';
import newProgramForm from '../program/new';

const definition = {
scope: '[data-test-programs]',
Expand All @@ -21,6 +22,7 @@ const definition = {
toggleNewProgramForm: clickable('[data-test-expand-collapse-button] button'),
toggleNewProgramFormExists: isVisible('[data-test-expand-collapse-button]'),
list,
newProgramForm,
};

export default definition;
Expand Down

0 comments on commit 18d3154

Please sign in to comment.