Skip to content

Commit

Permalink
add initial rendering test as example for other components
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim Scott committed Nov 17, 2020
1 parent 1486aeb commit 0cdc2ee
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/components/exp-lookit-survey/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ export default ExpFrameBaseComponent.extend({
formData: null,
actions: {
setupForm(form) {

if (this.get('isDestroyed') || this.get('isDestroying')) {
return;
}
this.set('form', form);
// If we've gotten here via 'previous' and so already have data, set the
// JSON value of this form to that data.
Expand Down
77 changes: 77 additions & 0 deletions tests/integration/components/exp-lookit-survey-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import Ember from 'ember';
import DS from 'ember-data';
import {moduleForComponent} from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';



module('Integration | Component | exp lookit survey', function(hooks) {
setupRenderingTest(hooks);

test('Exp-lookit-survey frame renders', async function (assert) {

assert.expect(2);
let formSchema = {
schema: {
type: "object",
title: "Tell us about your pet!",
properties: {
"age": {
"type": "integer",
"title": "Age",
"maximum": 200,
"minimum": 0,
"required": true
},
"name": {
"type": "string",
"title": "Name",
"required": true
},
"species": {
"enum": [
"dog",
"cat",
"fish",
"bird",
"raccoon"
],
"type": "string",
"title": "What type of animal?",
"default": ""
}
}
},
options: {
fields: {
age: {
"numericEntry": true
},
name: {
"placeholder": "a name..."
},
species: {
"type": "radio",
"message": "Seriously, what species??",
"validator": "required-field"
}
}
}
};

this.set('formSchema', formSchema);
await this.render(
hbs`{{exp-lookit-survey
nextButtonText="Moving on"
formSchema=formSchema
}}`
);

// Note: not all questions appear to be rendered at this time. May need to wait for that separately...
assert.equal(this.element.querySelector('legend').textContent.trim(), 'Tell us about your pet!');
assert.equal(this.element.querySelector('button').textContent.trim(), 'Moving on');
});
});
23 changes: 23 additions & 0 deletions tests/unit/utils/is-color-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { colorSpecToRgbaArray, isColor } from '../../../utils/is-color';
import { module, test} from 'qunit';


module('Unit | Utility | is color');

test('Valid CSS color syntax recognized', function(assert) {
assert.ok(isColor('black'), 'Black is a color');
assert.notOk(isColor('blark'), 'Blark is not a color');

assert.ok(isColor('#cc00ff'), '#cc00ff is a color');
assert.notOk(isColor('cc00ff'), 'cc00ff is not a color');
});

test('CSS color specs correctly turned into RGBA arrays', function(assert) {
let black = new Uint8ClampedArray([0, 0, 0, 255]);
assert.deepEqual(colorSpecToRgbaArray('black'), black);
assert.deepEqual(colorSpecToRgbaArray('#000'), black);

let limegreen = new Uint8ClampedArray([0, 255, 0, 255]);
assert.deepEqual(colorSpecToRgbaArray('lime'), limegreen);
assert.deepEqual(colorSpecToRgbaArray('#0f0'), limegreen);
});

0 comments on commit 0cdc2ee

Please sign in to comment.