Skip to content

Commit

Permalink
added fixtures and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philipkueng committed Apr 3, 2019
1 parent 96c66f5 commit c52f4cb
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 3 deletions.
33 changes: 33 additions & 0 deletions resources/fixtures/data/hide-alt-tag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"title": "FIXTURE: hide alt tag",
"images": {
"variants": [
{
"images": [
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/300x200.png",
"key": "300x200.png",
"width": 300,
"height": 200
},
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/500x400.png",
"key": "500x400.png",
"width": 500,
"height": 600
}
]
},
{
"images": [
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/800x500.png",
"key": "800x500.png",
"width": 800,
"height": 500
}
]
}
]
}
}
34 changes: 34 additions & 0 deletions resources/fixtures/data/show-alt-tag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"title": "FIXTURE: show alt tag",
"subtitle": "Subtitle",
"images": {
"variants": [
{
"images": [
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/300x200.png",
"key": "300x200.png",
"width": 300,
"height": 200
},
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/500x400.png",
"key": "500x400.png",
"width": 500,
"height": 600
}
]
},
{
"images": [
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/800x500.png",
"key": "800x500.png",
"width": 800,
"height": 500
}
]
}
]
}
}
33 changes: 33 additions & 0 deletions resources/fixtures/data/show-title-alt-tag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"title": "FIXTURE: only show title in alt tag",
"images": {
"variants": [
{
"images": [
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/300x200.png",
"key": "300x200.png",
"width": 300,
"height": 200
},
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/500x400.png",
"key": "500x400.png",
"width": 500,
"height": 600
}
]
},
{
"images": [
{
"url": "https://nzz-q-assets-stage.s3.eu-west-1.amazonaws.com/800x500.png",
"key": "800x500.png",
"width": 800,
"height": 500
}
]
}
]
}
}
5 changes: 4 additions & 1 deletion routes/fixtures/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const fixtureDataDirectory = "../../resources/fixtures/data";
// has to be in sync with files created in build task - see ../../tasks/build.js
const fixtureData = [
require(`${fixtureDataDirectory}/2-variants-no-min-width.json`),
require(`${fixtureDataDirectory}/2-variants.json`)
require(`${fixtureDataDirectory}/2-variants.json`),
require(`${fixtureDataDirectory}/hide-alt-tag.json`),
require(`${fixtureDataDirectory}/show-alt-tag.json`),
require(`${fixtureDataDirectory}/show-title-alt-tag.json`)
];

module.exports = {
Expand Down
63 changes: 63 additions & 0 deletions test/dom-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,69 @@ lab.experiment("Q infographic dom tests", () => {
expect(value).to.be.equal(1);
});
});

it("should display the alt tag of image", async () => {
const item = require("../resources/fixtures/data/show-alt-tag.json");
const response = await server.inject({
url: "/rendering-info/web",
method: "POST",
payload: {
item: item,
toolRuntimeConfig: {
size: { width: [{ value: 400, comparison: "=" }] }
}
}
});
return getElements(response.result.markup, "img").then(elements => {
const altTag = `${item.title} - ${item.subtitle}`;
elements.forEach(element => {
expect(element.alt).to.be.equals(altTag);
});
});
});

it("should only display the title in alt tag of image", async () => {
const item = require("../resources/fixtures/data/hide-alt-tag.json");
const response = await server.inject({
url: "/rendering-info/web",
method: "POST",
payload: {
item: item,
toolRuntimeConfig: {
size: { width: [{ value: 400, comparison: "=" }] }
}
}
});

return getElements(response.result.markup, "img").then(elements => {
const altTag = `${item.title}`;
elements.forEach(element => {
expect(element.alt).to.be.equals(altTag);
});
});
});

it("shouldn't display the alt tag of image", async () => {
const response = await server.inject({
url: "/rendering-info/web",
method: "POST",
payload: {
item: require("../resources/fixtures/data/hide-alt-tag.json"),
toolRuntimeConfig: {
displayOptions: {
hideTitle: true
},
size: { width: [{ value: 400, comparison: "=" }] }
}
}
});

return getElements(response.result.markup, "img").then(elements => {
elements.forEach(element => {
expect(element.alt).to.be.equals("");
});
});
});
});

lab.experiment("correct image selection based on width", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ lab.experiment("rendering-info endpoint", () => {
});

lab.experiment("fixture data endpoint", () => {
it("returns 2 fixture data items for /fixtures/data", async () => {
it("returns 5 fixture data items for /fixtures/data", async () => {
const response = await server.inject("/fixtures/data");
expect(response.statusCode).to.be.equal(200);
expect(response.result.length).to.be.equal(2);
expect(response.result.length).to.be.equal(5);
});
});

0 comments on commit c52f4cb

Please sign in to comment.