Skip to content

Instantly share code, notes, and snippets.

@spacekitcat
Last active December 11, 2016 19:39
Show Gist options
  • Save spacekitcat/49869458d2443720135a07da26a70170 to your computer and use it in GitHub Desktop.
Save spacekitcat/49869458d2443720135a07da26a70170 to your computer and use it in GitHub Desktop.
describe("ClientsideTextReplace 'doReplace' function", function() {
beforeEach(function() {
});
var createTestDocument = function() {
return document.implementation.createHTMLDocument("test doc");
}
describe("Is able to replace the core targets", function() {
// N.B Not all targets are tested, just the main ones. Maintenance thing really.
it("Replaces gamergate", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "gamergate isnie cool!";
doReplace(testDocument);
expect(testDocument.body.innerHTML).toEqual('misogynist isnie cool!');
});
it("Replaces game-gate", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "game-gate isnie cool!";
doReplace(testDocument);
expect(testDocument.body.innerHTML).toEqual('misogynist isnie cool!');
});
it("Replaces gAmErGaTe (N.B. is the replace case insensitive)", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "gAmErGaTe isnie cool!";
doReplace(testDocument);
expect(testDocument.body.innerHTML).toEqual('misogynist isnie cool!');
});
it("Replaces gamer-gate", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "gamer-gate isnie cool!";
doReplace(testDocument);
expect(testDocument.body.innerHTML).toEqual('misogynist isnie cool!');
});
it("Replaces gamer gate", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "gamer gate isnie cool!";
doReplace(testDocument);
expect(testDocument.body.innerHTML).toEqual('misogynist isnie cool!');
});
it("Replaces gamegate", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "gamegate isnie cool!";
doReplace(testDocument);
expect(testDocument.body.innerHTML).toEqual('misogynist isnie cool!');
});
it("Replaces 'It's about ethics in journalism'", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "It's about ethics in journalism bro!";
doReplace(testDocument);
// A future version might use proper grammer (though probably not tbh).
expect(testDocument.body.innerHTML).toEqual('It\'s about stopping women from playing video games bro!');
});
it("Replaces 'It's about ethics in journalism' (case insensitive test)", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = " It's aBoUt eThIcs In jOurnalism bro!";
doReplace(testDocument);
// A future version might use proper grammer (though probably not tbh).
expect(testDocument.body.innerHTML).toEqual(' It\'s about stopping women from playing video games bro!');
});
it("Replaces 'It's about ethics in gaming'", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "It's about ethics in gaming bro!";
doReplace(testDocument);
// A future version might use proper grammer (though probably not tbh).
expect(testDocument.body.innerHTML).toEqual('It\'s about stopping women from playing video games bro!');
});
it("Replaces 'It's about ethics in GaMing'", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "It's about ethics in gaming bro!";
doReplace(testDocument);
// A future version might use proper grammer (though probably not tbh).
expect(testDocument.body.innerHTML).toEqual('It\'s about stopping women from playing video games bro!');
});
it("Replaces 'ethics in game journalism'", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "ethics in game journalism bro!";
doReplace(testDocument);
// A future version might use proper grammer (though probably not tbh).
expect(testDocument.body.innerHTML).toEqual('stopping women from playing video games bro!');
});
it("Replaces 'ethics in game journalism' (case insensitive)", function() {
// Test data setup
var testDocument = createTestDocument();
testDocument.body.innerText = "eThIcs iN gAme jOurNalIsm bro!";
doReplace(testDocument);
// A future version might use proper grammer (though probably not tbh).
expect(testDocument.body.innerHTML).toEqual('stopping women from playing video games bro!');
});
});
it("Replaces text inside body.p", function() {
// Test data setup
var testDocument = createTestDocument();
var pTag = testDocument.createElement('P');
pTag.innerText = "gamergate isnie cool!";
testDocument.body.append(pTag);
doReplace(testDocument);
// A future version might use proper grammer (though probably not tbh).
expect(testDocument.body.innerHTML).toEqual('<p>misogynist isnie cool!</p>');
});
it("Replaces againsts body.div.a withtout touch the href attribute", function() {
// Test data setup
var testDocument = createTestDocument();
var divTag = testDocument.createElement('DIV');
var aTag = testDocument.createElement('A');
aTag.innerText = "gamergate isnie cool!";
aTag.href = "http://wikawikawik.com/gamergate"
divTag.append(aTag);
testDocument.body.append(divTag);
doReplace(testDocument);
// A future version might use proper grammer (though probably not tbh).
expect(testDocument.body.innerHTML).toEqual('<div><a href="http://wikawikawik.com/gamergate">misogynist isnie cool!</a></div>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment