Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions dom-merge-conflict/tasks/buttons-and-counter/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ function increment(node) {
let current = node.textContent;
node.textContent = Number(current) + 1;
}
function decrement(node) {
let current = node.textContent;
node.textContent = Number(current) - 1;
}

export function App() {

const body = document.createElement("body");

const header = document.createElement("header");
header.innerHTML = `
<h1>Number Counter</h1>
<p>A simple counter. Press increment to increase the count by one.</p>
<p>A simple counter. Press decrement to decrease the count by one.</p>
`;
body.appendChild(header);

const main = document.createElement("main");
main.innerHTML = `
<p id="counter" data-testid="counter">0</p>
<button id="increment">Increment</button>
`;
body.appendChild(main);

const button = body.querySelector("#increment");
Expand All @@ -27,5 +26,11 @@ export function App() {
increment(counter);
});

const button = body.querySelector("#decrement");
const counter = body.querySelector("#counter");
button.addEventListener("click", () => {
decrement(counter);
});

return body;
}
5 changes: 5 additions & 0 deletions dom-merge-conflict/tasks/buttons-and-counter/src/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const header = document.createElement("header");
header.innerHTML = `
<h1>Number Counter</h1>
<p>A simple counter. Press increment to increase the count by one.</p>
`;
5 changes: 5 additions & 0 deletions dom-merge-conflict/tasks/buttons-and-counter/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const main = document.createElement("main");
main.innerHTML = `
<p id="counter" data-testid="counter">0</p>
<button id="increment">Increment</button>
`;
6 changes: 3 additions & 3 deletions dom-merge-conflict/tasks/buttons-and-counter/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("button and counter", () => {

test("contains description paragraph with mention of 'increment' in header", () => {
expect(
container.querySelector("header").querySelector("p")
container.querySelector("header").querySelector("p"),
).toHaveTextContent(/increment/i);
});

Expand All @@ -35,7 +35,7 @@ describe("button and counter", () => {
expect(getByTestId(container, "counter")).toHaveTextContent(/^2$/);
});

describe.skip("decrement button", () => {
describe("decrement button", () => {
test("pressing Decrement decreases the counter", () => {
const button = getByRole(container, "button", {
name: "Decrement",
Expand All @@ -49,7 +49,7 @@ describe("button and counter", () => {

test("contains description paragraph with mention of 'decrement' in header", () => {
expect(
container.querySelector("header").querySelector("p")
container.querySelector("header").querySelector("p"),
).toHaveTextContent(/decrement/i);
});
});
Expand Down