Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
becky-gilbert committed Jan 4, 2024
1 parent 5aba572 commit 00b8f8a
Showing 1 changed file with 18 additions and 268 deletions.
286 changes: 18 additions & 268 deletions packages/plugin-survey/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,284 +4,34 @@ import survey from ".";

describe("survey plugin", () => {
test("loads", async () => {
const { displayElement, expectRunning, getData } = await startTimeline([
{
type: survey,
pages: [
[
{
type: "drop-down",
prompt: "foo",
options: ["1", "2"],
},
],
],
},
]);

await expectRunning();
});

// drop-down
test("loads drop-down question with defaults", async () => {
const { displayElement, getHTML, expectFinished } = await startTimeline([
{
type: survey,
pages: [
[
{
type: "drop-down",
prompt: "foo",
options: ["1", "2"],
},
],
],
},
]);

// check that label displayed
const question = displayElement.querySelector('div[data-name="P0_Q0"]');
expect(question).not.toBeNull();
expect(question.querySelector("span").innerHTML).toBe("foo");

// check that dropdown displayed
const dropdown_menu = displayElement.getElementsByTagName("select");
expect(dropdown_menu[0]).not.toBeNull();

// check that finish button displayed
const finish_button = displayElement.querySelector("input.sv_complete_btn");
expect(finish_button).not.toBeNull();

clickTarget(finish_button);

await expectFinished();
});

// html
test("loads html question with defaults", async () => {
const { displayElement, expectFinished, getData } = await startTimeline([
{
type: survey,
pages: [
[
{
type: "html",
prompt: "<span id='prompt'>foo</span>",
},
],
],
},
]);

const question = displayElement.querySelector('div[data-name="P0_Q0"]');
expect(question).not.toBeNull();
expect(question.querySelector("#prompt").innerHTML).toBe("foo");

const finish_button = displayElement.querySelector("input.sv_complete_btn");
expect(finish_button).not.toBeNull();
clickTarget(finish_button);

await expectFinished();
});

// likert
// test("loads likert question with defaults", async () => {
// const { displayElement, expectFinished, getData } = await startTimeline([
// {
// type: survey,
// pages: [[{
// type: 'likert', prompt: 'foo', statements: [{prompt: 's1'},{prompt: 's2'}], options: ['fizz','buzz']
// }]]
// },
// ]);
// });

// multi-choice
test("loads multi-choice question with defaults", async () => {
const { displayElement, expectFinished, getData } = await startTimeline([
{
type: survey,
pages: [
[
{
type: "multi-choice",
prompt: "foo",
options: ["fizz", "buzz"],
},
],
],
},
]);

const question = displayElement.querySelector('div[data-name="P0_Q0"]');
expect(question).not.toBeNull();
expect(question.querySelector("span").innerHTML).toBe("foo");

const radio_btns = displayElement.querySelectorAll("input[type='radio']");
expect(radio_btns).not.toBeNull();
expect(radio_btns.length).toBe(2);

const finish_button = displayElement.querySelector("input.sv_complete_btn");
expect(finish_button).not.toBeNull();

clickTarget(finish_button);

await expectFinished();
});

// multi-select
test("loads multi-select question with defaults", async () => {
const { displayElement, expectFinished, getData } = await startTimeline([
{
type: survey,
pages: [
[
const survey_json = {
pages: [
{
name: "page1",
elements: [
{
type: "multi-select",
prompt: "foo",
options: ["fizz", "buzz"],
type: "text",
name: "question1",
title: "Question 1",
},
],
],
},
]);

const question = displayElement.querySelector('div[data-name="P0_Q0"]');
expect(question).not.toBeNull();
expect(question.querySelector("span").innerHTML).toBe("foo");

const checkboxes = displayElement.querySelectorAll("input[type='checkbox']");
expect(checkboxes).not.toBeNull();
expect(checkboxes.length).toBe(2);

const finish_button = displayElement.querySelector("input.sv_complete_btn");
expect(finish_button).not.toBeNull();
clickTarget(finish_button);

await expectFinished();
});

// text
test("loads single-line text question with defaults", async () => {
const { displayElement, expectFinished, getData } = await startTimeline([
{
type: survey,
pages: [
[
{
type: "text",
prompt: "foo",
type: "ranking",
name: "question2",
title: "Question 2",
choices: ["Item 1", "Item 2", "Item 3"],
},
],
],
},
]);

const question = displayElement.querySelector('div[data-name="P0_Q0"]');
expect(question).not.toBeNull();
expect(question.querySelector("span").innerHTML).toBe("foo");

const textinput = displayElement.querySelectorAll("input");
expect(textinput[0]).not.toBeNull();
expect(textinput[0].type).toBe("text");
expect(textinput[0].size).toBe(40);

const finish_button = displayElement.querySelector("input.sv_complete_btn");
expect(finish_button).not.toBeNull();
clickTarget(finish_button);

await expectFinished();
});
},
],
};

test("loads multi-line text question with defaults", async () => {
const { displayElement, expectFinished, getData } = await startTimeline([
const { displayElement, expectRunning, getData } = await startTimeline([
{
type: survey,
pages: [
[
{
type: "text",
prompt: "foo",
textbox_rows: 2,
},
],
],
survey_json: survey_json,
},
]);

const question = displayElement.querySelector('div[data-name="P0_Q0"]');
expect(question).not.toBeNull();
expect(question.querySelector("span").innerHTML).toBe("foo");

const textarea = displayElement.querySelectorAll("textarea");
expect(textarea[0]).not.toBeNull();
expect(textarea[0].cols).toBe(40);
expect(textarea[0].rows).toBe(2);

const finish_button = displayElement.querySelector("input.sv_complete_btn");
expect(finish_button).not.toBeNull();
clickTarget(finish_button);

await expectFinished();
});

test("loads single-line text questions of various input types", async () => {
jest.setTimeout(40000); // default timeout of 5s is too short for this test

const inputTypes = [
"color",
"date",
"datetime-local",
"email",
"month",
"number",
"password",
"range",
"tel",
"text",
"time",
"url",
"week",
];

for (const inputType of inputTypes) {
const { displayElement, expectFinished, getData } = await startTimeline([
{
type: survey,
pages: [
[
{
type: "text",
prompt: "foo",
input_type: inputType,
textbox_columns: 10,
},
],
],
},
]);

const question = displayElement.querySelector('div[data-name="P0_Q0"]');
expect(question).not.toBeNull();
expect(question.querySelector("span").innerHTML).toBe("foo");

const input = displayElement.querySelectorAll("input")[0];
expect(input).not.toBeNull();
expect(input.type).toEqual(inputType);
if (["email", "password", "tel", "url", "text"].includes(inputType)) {
// size can be specified only for text input types
expect(input.size).toEqual(10);
} else {
expect(input.size).not.toEqual(10);
}

const finish_button = displayElement.querySelector("input.sv_complete_btn");
expect(finish_button).not.toBeNull();
clickTarget(finish_button);

await expectFinished();
}
await expectRunning();
});

// survey options
});

0 comments on commit 00b8f8a

Please sign in to comment.