2020-01-24 12:26:28 +00:00
|
|
|
import { skip, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
|
|
import { Promise } from 'rsvp';
|
|
|
|
import Yadda from 'yadda';
|
|
|
|
|
|
|
|
import { env } from '../../env';
|
|
|
|
import api from './api';
|
|
|
|
import getDictionary from '../dictionary';
|
2018-05-11 12:47:21 +00:00
|
|
|
|
2018-06-25 11:11:01 +00:00
|
|
|
const staticClassList = [...document.documentElement.classList];
|
2020-01-24 12:26:28 +00:00
|
|
|
const reset = function() {
|
2018-06-25 11:11:01 +00:00
|
|
|
window.localStorage.clear();
|
|
|
|
api.server.reset();
|
|
|
|
const list = document.documentElement.classList;
|
|
|
|
while (list.length > 0) {
|
|
|
|
list.remove(list.item(0));
|
|
|
|
}
|
|
|
|
staticClassList.forEach(function(item) {
|
|
|
|
list.add(item);
|
|
|
|
});
|
2020-01-24 12:26:28 +00:00
|
|
|
};
|
2018-05-11 12:47:21 +00:00
|
|
|
|
2020-01-24 12:26:28 +00:00
|
|
|
const runTest = function(context, libraries, steps, scenarioContext) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Yadda.Yadda(libraries, context).yadda(steps, scenarioContext, function next(err, result) {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
2018-05-11 12:47:21 +00:00
|
|
|
}
|
2020-01-24 12:26:28 +00:00
|
|
|
resolve(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const checkAnnotations = function(annotations, isScenario) {
|
|
|
|
annotations = {
|
2020-02-07 11:02:53 +00:00
|
|
|
namespaceable: env('CONSUL_NSPACES_ENABLED'),
|
2020-01-24 12:26:28 +00:00
|
|
|
...annotations,
|
|
|
|
};
|
|
|
|
if (annotations.ignore) {
|
|
|
|
return function(test) {
|
|
|
|
skip(`${test.title}`, function(assert) {});
|
|
|
|
};
|
2018-05-11 12:47:21 +00:00
|
|
|
}
|
2020-01-24 12:26:28 +00:00
|
|
|
if (isScenario) {
|
2020-02-07 11:02:53 +00:00
|
|
|
if (env('CONSUL_NSPACES_ENABLED')) {
|
|
|
|
if (!annotations.notnamespaceable) {
|
|
|
|
return function(scenario, feature, yadda, yaddaAnnotations, library) {
|
|
|
|
['', 'default', 'team-1', undefined].forEach(function(item) {
|
|
|
|
test(`Scenario: ${
|
|
|
|
scenario.title
|
|
|
|
} with the ${item === '' ? 'empty' : typeof item === 'undefined' ? 'undefined' : item} namespace set`, function(assert) {
|
|
|
|
const libraries = library.default({
|
|
|
|
assert: assert,
|
|
|
|
library: Yadda.localisation.English.library(getDictionary(annotations, item)),
|
|
|
|
});
|
|
|
|
const scenarioContext = {
|
|
|
|
ctx: {
|
|
|
|
nspace: item,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const result = runTest(this, libraries, scenario.steps, scenarioContext);
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
});
|
2020-01-24 12:26:28 +00:00
|
|
|
};
|
2020-02-07 11:02:53 +00:00
|
|
|
} else {
|
|
|
|
return function() {};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!annotations.onlynamespaceable) {
|
|
|
|
return function(scenario, feature, yadda, yaddaAnnotations, library) {
|
|
|
|
test(`Scenario: ${scenario.title}`, function(assert) {
|
2020-01-24 12:26:28 +00:00
|
|
|
const libraries = library.default({
|
|
|
|
assert: assert,
|
2020-02-07 11:02:53 +00:00
|
|
|
library: Yadda.localisation.English.library(getDictionary(annotations)),
|
2020-01-24 12:26:28 +00:00
|
|
|
});
|
|
|
|
const scenarioContext = {
|
2020-02-07 11:02:53 +00:00
|
|
|
ctx: {},
|
2020-01-24 12:26:28 +00:00
|
|
|
};
|
|
|
|
return runTest(this, libraries, scenario.steps, scenarioContext);
|
|
|
|
});
|
2020-02-07 11:02:53 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return function() {};
|
2020-01-24 12:26:28 +00:00
|
|
|
}
|
2020-02-07 11:02:53 +00:00
|
|
|
}
|
2018-05-11 12:47:21 +00:00
|
|
|
}
|
2020-01-24 12:26:28 +00:00
|
|
|
};
|
|
|
|
export const setupFeature = function(featureAnnotations) {
|
|
|
|
return setupApplicationTest;
|
|
|
|
};
|
|
|
|
export const setupScenario = function(featureAnnotations, scenarioAnnotations) {
|
2018-05-11 12:47:21 +00:00
|
|
|
return function(model) {
|
|
|
|
model.afterEach(function() {
|
2018-06-25 11:11:01 +00:00
|
|
|
reset();
|
2018-05-11 12:47:21 +00:00
|
|
|
});
|
|
|
|
};
|
2020-01-24 12:26:28 +00:00
|
|
|
};
|
|
|
|
export const runFeature = function(annotations) {
|
|
|
|
return checkAnnotations(annotations);
|
|
|
|
};
|
2018-05-11 12:47:21 +00:00
|
|
|
|
2020-01-24 12:26:28 +00:00
|
|
|
export const runScenario = function(featureAnnotations, scenarioAnnotations) {
|
|
|
|
return checkAnnotations({ ...featureAnnotations, ...scenarioAnnotations }, true);
|
|
|
|
};
|