@projectcaluma/ember-testing 11.0.0-beta.3 → 11.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/addon/mirage-graphql/deserialize.js +13 -0
- package/addon/mirage-graphql/filters/answer.js +1 -1
- package/addon/mirage-graphql/filters/base.js +3 -3
- package/addon/mirage-graphql/filters/form.js +5 -1
- package/addon/mirage-graphql/filters/index.js +17 -0
- package/addon/mirage-graphql/filters/question.js +1 -1
- package/addon/mirage-graphql/filters/work-item.js +1 -1
- package/addon/mirage-graphql/index.js +59 -63
- package/addon/mirage-graphql/mocks/answer.js +2 -2
- package/addon/mirage-graphql/mocks/base.js +6 -8
- package/addon/mirage-graphql/mocks/form.js +2 -2
- package/addon/mirage-graphql/mocks/index.js +17 -0
- package/addon/mirage-graphql/mocks/question.js +2 -2
- package/addon/mirage-graphql/mocks/work-item.js +18 -5
- package/addon/mirage-graphql/register.js +20 -0
- package/addon/mirage-graphql/schema.graphql +1380 -882
- package/addon/mirage-graphql/serialize.js +14 -0
- package/addon/scenarios/distribution.js +31 -2
- package/addon-mirage-support/factories/form.js +1 -0
- package/package.json +11 -10
- package/addon/mirage-graphql/handler.js +0 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
# [@projectcaluma/ember-testing-v11.0.0-beta.6](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.5...@projectcaluma/ember-testing-v11.0.0-beta.6) (2022-04-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **cf-field:** add optional hints for form fields ([d847fbf](https://github.com/projectcaluma/ember-caluma/commit/d847fbffa376ea60971fb9e91aff8bf54ce77d50))
|
|
7
|
+
* **distribution:** enable completing the distribution ([beabe61](https://github.com/projectcaluma/ember-caluma/commit/beabe61bd34025c4785c1e1ba60c59babb3eb6ab))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### BREAKING CHANGES
|
|
11
|
+
|
|
12
|
+
* **cf-field:** Question hints requires Caluma >= v7.15.0
|
|
13
|
+
|
|
14
|
+
Add option to create hints for certain question types. These
|
|
15
|
+
are displayed below the input field and can be used to provide
|
|
16
|
+
short, informative messages. Hints are available for all question
|
|
17
|
+
types except for form, static and action button questions.
|
|
18
|
+
|
|
19
|
+
# [@projectcaluma/ember-testing-v11.0.0-beta.5](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.4...@projectcaluma/ember-testing-v11.0.0-beta.5) (2022-03-23)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* **embroider:** add missing dependency on @ember/string ([3a6e6bb](https://github.com/projectcaluma/ember-caluma/commit/3a6e6bb39a8c1a40a2ae00b3d4ea00606a755e25))
|
|
25
|
+
* **embroider:** use factory function instead of dynamic importing ([91459e7](https://github.com/projectcaluma/ember-caluma/commit/91459e7add66139a1f268b6c74dbabd9fa486158))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **testing:** add handler for canceling work items ([51c8024](https://github.com/projectcaluma/ember-caluma/commit/51c80240234fffa36a44a68a695ee7dbf074f1a9))
|
|
31
|
+
* **testing:** extend distribution scenario with withdrawn inquiries ([a190f0f](https://github.com/projectcaluma/ember-caluma/commit/a190f0f7ccceeca2944b1647320c738d81d44733))
|
|
32
|
+
|
|
33
|
+
# [@projectcaluma/ember-testing-v11.0.0-beta.4](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.3...@projectcaluma/ember-testing-v11.0.0-beta.4) (2022-03-11)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
* **form-builder:** add new categories published and unpublished ([52c1c1d](https://github.com/projectcaluma/ember-caluma/commit/52c1c1deaf15991e595e042f643889be64b425a0))
|
|
39
|
+
|
|
1
40
|
# [@projectcaluma/ember-testing-v11.0.0-beta.3](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-testing-v11.0.0-beta.2...@projectcaluma/ember-testing-v11.0.0-beta.3) (2022-02-16)
|
|
2
41
|
|
|
3
42
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function deserialize(serialized) {
|
|
2
|
+
let decodedId = serialized.id;
|
|
3
|
+
|
|
4
|
+
try {
|
|
5
|
+
decodedId = atob(serialized.id).split(":")[1] || serialized.id;
|
|
6
|
+
} catch (e) {
|
|
7
|
+
// This will happen if the ID is not a relay ID (Type plus ID base64
|
|
8
|
+
// encoded) but just the raw ID. The deserialize function needs to be able
|
|
9
|
+
// to handle both
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return { ...serialized, ...(decodedId ? { id: decodedId } : {}) };
|
|
13
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
|
|
2
2
|
|
|
3
|
-
export default class extends BaseFilter {
|
|
3
|
+
export default class AnswerFilter extends BaseFilter {
|
|
4
4
|
questions(records, value, { invert = false }) {
|
|
5
5
|
return records.filter(
|
|
6
6
|
(record) => invert !== value.includes(record.questionId)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { camelize } from "@ember/string";
|
|
2
2
|
|
|
3
|
-
export default class {
|
|
3
|
+
export default class BaseFilter {
|
|
4
4
|
constructor(type) {
|
|
5
5
|
this.type = type;
|
|
6
6
|
}
|
|
@@ -29,7 +29,7 @@ export default class {
|
|
|
29
29
|
return filters.map(({ key, value, options = {} }) => {
|
|
30
30
|
const fn = this[key];
|
|
31
31
|
|
|
32
|
-
return typeof fn === "function"
|
|
32
|
+
return typeof fn === "function" && ![null, undefined].includes(value)
|
|
33
33
|
? (records) => fn.call(this, records, value, options)
|
|
34
34
|
: (records) => records;
|
|
35
35
|
});
|
|
@@ -53,7 +53,7 @@ export default class {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
filter(records, filters) {
|
|
56
|
-
return this._getFilterFns(filters
|
|
56
|
+
return this._getFilterFns(filters?.filter ?? filters ?? []).reduce(
|
|
57
57
|
(recs, fn) => fn(recs),
|
|
58
58
|
this.sort(records, filters?.order)
|
|
59
59
|
);
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
|
|
2
2
|
|
|
3
|
-
export default class extends BaseFilter {
|
|
3
|
+
export default class FormFilter extends BaseFilter {
|
|
4
4
|
isArchived(records, value) {
|
|
5
5
|
return records.filter(({ isArchived }) => isArchived === value);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
isPublished(records, value) {
|
|
9
|
+
return records.filter(({ isPublished }) => isPublished === value);
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
search(records, value) {
|
|
9
13
|
const re = new RegExp(`.*${value}.*`, "i");
|
|
10
14
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AnswerFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/answer";
|
|
2
|
+
import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
|
|
3
|
+
import FormFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/form";
|
|
4
|
+
import QuestionFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/question";
|
|
5
|
+
import WorkItemFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/work-item";
|
|
6
|
+
|
|
7
|
+
const FILTER_MAPPING = {
|
|
8
|
+
Answer: AnswerFilter,
|
|
9
|
+
Form: FormFilter,
|
|
10
|
+
Question: QuestionFilter,
|
|
11
|
+
WorkItem: WorkItemFilter,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default function createFilter(type, ...args) {
|
|
15
|
+
const FilterClass = FILTER_MAPPING[type] ?? BaseFilter;
|
|
16
|
+
return new FilterClass(type, ...args);
|
|
17
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
|
|
2
2
|
|
|
3
|
-
export default class extends BaseFilter {
|
|
3
|
+
export default class QuestionFilter extends BaseFilter {
|
|
4
4
|
isArchived(records, value) {
|
|
5
5
|
return records.filter(({ isArchived }) => isArchived === value);
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BaseFilter from "@projectcaluma/ember-testing/mirage-graphql/filters/base";
|
|
2
2
|
|
|
3
|
-
export default class extends BaseFilter {
|
|
3
|
+
export default class WorkItemFilter extends BaseFilter {
|
|
4
4
|
status(records, value, { invert = false }) {
|
|
5
5
|
return records.filter(({ status }) => invert !== (status === value));
|
|
6
6
|
}
|
|
@@ -1,64 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
import { classify } from "@ember/string";
|
|
2
|
+
import { singularize } from "ember-inflector";
|
|
3
|
+
import { graphql } from "graphql";
|
|
4
|
+
import {
|
|
5
|
+
GraphQLDate as Date,
|
|
6
|
+
GraphQLDateTime as DateTime,
|
|
7
|
+
} from "graphql-iso-date";
|
|
8
|
+
import { addMockFunctionsToSchema, makeExecutableSchema } from "graphql-tools";
|
|
9
|
+
|
|
10
|
+
import createMock from "@projectcaluma/ember-testing/mirage-graphql/mocks";
|
|
11
|
+
import typeDefs from "@projectcaluma/ember-testing/mirage-graphql/schema.graphql";
|
|
12
|
+
|
|
13
|
+
export default function createGraphqlHandler(server) {
|
|
14
|
+
return function graphqlHandler({ db }, request) {
|
|
15
|
+
const mocks = db._collections.reduce((m, { name }) => {
|
|
16
|
+
const cls = classify(singularize(name));
|
|
17
|
+
const mock = createMock(cls, server);
|
|
18
|
+
|
|
19
|
+
return { ...m, ...mock.getHandlers() };
|
|
20
|
+
}, {});
|
|
21
|
+
|
|
22
|
+
const schema = makeExecutableSchema({
|
|
23
|
+
typeDefs,
|
|
24
|
+
resolvers: {
|
|
25
|
+
Date,
|
|
26
|
+
DateTime,
|
|
27
|
+
GenericScalar: {
|
|
28
|
+
serialize(value) {
|
|
29
|
+
return typeof value === "string" ? JSON.parse(value) : value;
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
resolverValidationOptions: { requireResolversForResolveType: false },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const { query, variables } = JSON.parse(request.requestBody);
|
|
37
|
+
|
|
38
|
+
addMockFunctionsToSchema({
|
|
39
|
+
schema,
|
|
40
|
+
mocks: {
|
|
41
|
+
...mocks,
|
|
42
|
+
JSONString: () => JSON.stringify({}),
|
|
43
|
+
GenericScalar: () => ({}),
|
|
44
|
+
Node: (_, { id }) => ({ __typename: atob(id).split(":")[0] }),
|
|
45
|
+
SelectedOption: ({ value }) => {
|
|
46
|
+
const option = server.schema.options.findBy({ slug: value });
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
slug: value,
|
|
50
|
+
label: option.label,
|
|
51
|
+
__typename: "SelectedOption",
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
preserveResolvers: false,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return graphql(schema, query, null, null, variables);
|
|
41
59
|
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const deserialize = (serialized) => {
|
|
45
|
-
let decodedId = serialized.id;
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
decodedId = atob(serialized.id).split(":")[1] || serialized.id;
|
|
49
|
-
} catch (e) {
|
|
50
|
-
// this is expected most times
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return { ...serialized, ...(decodedId ? { id: decodedId } : {}) };
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const Filter = function (type, ...args) {
|
|
57
|
-
return new (importTypeOrBase("./filters", type))(type, ...args);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const Mock = function (type, ...args) {
|
|
61
|
-
return new (importTypeOrBase("./mocks", type))(type, ...args);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export { default } from "./handler";
|
|
60
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DateTime } from "luxon";
|
|
2
2
|
|
|
3
|
-
import { register } from "@projectcaluma/ember-testing/mirage-graphql";
|
|
4
3
|
import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
|
|
4
|
+
import register from "@projectcaluma/ember-testing/mirage-graphql/register";
|
|
5
5
|
|
|
6
|
-
export default class extends BaseMock {
|
|
6
|
+
export default class AnswerMock extends BaseMock {
|
|
7
7
|
_handleSaveDocumentAnswer(
|
|
8
8
|
_,
|
|
9
9
|
{ question: questionId, document: documentId, value, type }
|
|
@@ -3,12 +3,10 @@ import { faker } from "@faker-js/faker";
|
|
|
3
3
|
import { singularize, pluralize } from "ember-inflector";
|
|
4
4
|
import { MockList } from "graphql-tools";
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
deserialize,
|
|
11
|
-
} from "@projectcaluma/ember-testing/mirage-graphql";
|
|
6
|
+
import deserialize from "@projectcaluma/ember-testing/mirage-graphql/deserialize";
|
|
7
|
+
import createFilter from "@projectcaluma/ember-testing/mirage-graphql/filters";
|
|
8
|
+
import register from "@projectcaluma/ember-testing/mirage-graphql/register";
|
|
9
|
+
import serialize from "@projectcaluma/ember-testing/mirage-graphql/serialize";
|
|
12
10
|
|
|
13
11
|
export const ANSWER_TYPES = [
|
|
14
12
|
"DATE",
|
|
@@ -50,13 +48,13 @@ export const TYPE_MAPPING = {
|
|
|
50
48
|
Task: TASK_TYPES,
|
|
51
49
|
};
|
|
52
50
|
|
|
53
|
-
export default class {
|
|
51
|
+
export default class BaseMock {
|
|
54
52
|
constructor(type, server) {
|
|
55
53
|
this.type = type;
|
|
56
54
|
this.server = server;
|
|
57
55
|
this.schema = server.schema;
|
|
58
56
|
|
|
59
|
-
this.filter =
|
|
57
|
+
this.filter = createFilter(type);
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
get collection() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { register } from "@projectcaluma/ember-testing/mirage-graphql";
|
|
2
1
|
import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
|
|
2
|
+
import register from "@projectcaluma/ember-testing/mirage-graphql/register";
|
|
3
3
|
|
|
4
|
-
export default class extends BaseMock {
|
|
4
|
+
export default class FormMock extends BaseMock {
|
|
5
5
|
@register("ReorderFormQuestionsPayload")
|
|
6
6
|
handleReorderFormQuestions(_, { input }) {
|
|
7
7
|
return this.handleSavePayload.fn.call(this, _, {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AnswerMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/answer";
|
|
2
|
+
import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
|
|
3
|
+
import FormMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/form";
|
|
4
|
+
import QuestionMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/question";
|
|
5
|
+
import WorkItemMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/work-item";
|
|
6
|
+
|
|
7
|
+
const MOCK_MAPPING = {
|
|
8
|
+
Answer: AnswerMock,
|
|
9
|
+
Form: FormMock,
|
|
10
|
+
Question: QuestionMock,
|
|
11
|
+
WorkItem: WorkItemMock,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default function createMock(type, ...args) {
|
|
15
|
+
const MockClass = MOCK_MAPPING[type] ?? BaseMock;
|
|
16
|
+
return new MockClass(type, ...args);
|
|
17
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { register } from "@projectcaluma/ember-testing/mirage-graphql";
|
|
2
1
|
import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
|
|
2
|
+
import register from "@projectcaluma/ember-testing/mirage-graphql/register";
|
|
3
3
|
|
|
4
|
-
export default class extends BaseMock {
|
|
4
|
+
export default class QuestionMock extends BaseMock {
|
|
5
5
|
@register("SaveTextQuestionPayload")
|
|
6
6
|
handleSaveTextQuestion(_, { input }) {
|
|
7
7
|
return this.handleSavePayload.fn.call(this, _, {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { DateTime } from "luxon";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
register,
|
|
5
|
-
deserialize,
|
|
6
|
-
} from "@projectcaluma/ember-testing/mirage-graphql";
|
|
3
|
+
import deserialize from "@projectcaluma/ember-testing/mirage-graphql/deserialize";
|
|
7
4
|
import BaseMock from "@projectcaluma/ember-testing/mirage-graphql/mocks/base";
|
|
5
|
+
import register from "@projectcaluma/ember-testing/mirage-graphql/register";
|
|
8
6
|
import { createInquiry } from "@projectcaluma/ember-testing/scenarios/distribution";
|
|
9
7
|
|
|
10
|
-
export default class extends BaseMock {
|
|
8
|
+
export default class WorkItemMock extends BaseMock {
|
|
11
9
|
@register("ResumeWorkItemPayload")
|
|
12
10
|
handleResumeWorkItem(_, { input }) {
|
|
13
11
|
return this.handleSavePayload.fn.call(this, _, {
|
|
@@ -22,6 +20,13 @@ export default class extends BaseMock {
|
|
|
22
20
|
});
|
|
23
21
|
}
|
|
24
22
|
|
|
23
|
+
@register("CancelWorkItemPayload")
|
|
24
|
+
handleCancelWorkItem(_, { input }) {
|
|
25
|
+
return this.handleSavePayload.fn.call(this, _, {
|
|
26
|
+
input: { id: input.id, status: "CANCELED" },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
@register("CompleteWorkItemPayload")
|
|
26
31
|
handleCompleteWorkItem(_, { input }) {
|
|
27
32
|
const { id } = deserialize(input);
|
|
@@ -96,6 +101,14 @@ export default class extends BaseMock {
|
|
|
96
101
|
status: "READY",
|
|
97
102
|
addressedGroups: workItem.addressedGroups,
|
|
98
103
|
});
|
|
104
|
+
} else if (taskId === "complete-distribution") {
|
|
105
|
+
this.collection
|
|
106
|
+
.where({ caseId, status: "READY" })
|
|
107
|
+
.update({ status: "CANCELED" });
|
|
108
|
+
|
|
109
|
+
this.collection
|
|
110
|
+
.where({ caseId, status: "SUSPENDED" })
|
|
111
|
+
.update({ status: "CANCELED" });
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
return this.handleSavePayload.fn.call(this, _, {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export default function register(tpl) {
|
|
2
|
+
return function decorate(target, name, descriptor) {
|
|
3
|
+
if (descriptor.value.__isHandler) {
|
|
4
|
+
descriptor.value.__handlerFor.push(tpl);
|
|
5
|
+
return descriptor;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
descriptor.writable = false;
|
|
9
|
+
descriptor.enumerable = true;
|
|
10
|
+
|
|
11
|
+
descriptor.value = {
|
|
12
|
+
__isHandler: true,
|
|
13
|
+
// Mocks can have multiple handlers per type.
|
|
14
|
+
__handlerFor: [tpl],
|
|
15
|
+
fn: descriptor.value,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return descriptor;
|
|
19
|
+
};
|
|
20
|
+
}
|