Add a test helper to build the svg document
This commit is contained in:
parent
afda283d49
commit
1360a4b944
@ -51,10 +51,10 @@ global.page = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
global.mockResponse = async function mockResponse(driver, urlPath, template, createFn) {
|
global.mockResponse = async function mockResponse(driver, urlPath, template, buildFn) {
|
||||||
const connection = driver.createCDPConnection('page');
|
const connection = driver.createCDPConnection('page');
|
||||||
const dom = new JSDOM(template);
|
const dom = new JSDOM(template);
|
||||||
const contents = createFn(dom.window.document);
|
const contents = buildFn(dom.window.document);
|
||||||
|
|
||||||
const httpResponse = new HttpResponse(url(urlPath));
|
const httpResponse = new HttpResponse(url(urlPath));
|
||||||
httpResponse.body = contents;
|
httpResponse.body = contents;
|
||||||
@ -86,3 +86,7 @@ global.selectCounter = function (counter) {
|
|||||||
counter.querySelector('.counter').classList.add('selected');
|
counter.querySelector('.counter').classList.add('selected');
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global.svgDocument = function (document) {
|
||||||
|
return `<?xml version="1.0" standalone="yes"?>\n` + document.querySelector('svg').outerHTML;
|
||||||
|
}
|
||||||
|
@ -27,7 +27,7 @@ describe('a trooper', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await mockResponse(driver, `/assets/images/${scenario}`, fixture, (document) => {
|
await mockResponse(driver, `/assets/images/${scenario}`, fixture, (document) => {
|
||||||
placeCounter(document, createTroopCounter(), { x: 1, y: 1 });
|
placeCounter(document, createTroopCounter(), { x: 1, y: 1 });
|
||||||
return `<?xml version="1.0" standalone="yes"?>\n` + document.querySelector('svg').outerHTML;
|
return svgDocument(document);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ describe('a selected trooper', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await mockResponse(driver, `/assets/images/${scenario}`, fixture, (document) => {
|
await mockResponse(driver, `/assets/images/${scenario}`, fixture, (document) => {
|
||||||
placeCounter(document, selectCounter(createTroopCounter()), { x: 1, y: 1 });
|
placeCounter(document, selectCounter(createTroopCounter()), { x: 1, y: 1 });
|
||||||
return `<?xml version="1.0" standalone="yes"?>\n` + document.querySelector('svg').outerHTML;
|
return svgDocument(document);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user