diff --git a/exercises/01-Hello-World/README.es.md b/exercises/01-Hello-World/README.es.md index 779fe511..ec1c29ff 100644 --- a/exercises/01-Hello-World/README.es.md +++ b/exercises/01-Hello-World/README.es.md @@ -19,7 +19,6 @@ Mira este ejemplo: ```HTML diff --git a/exercises/01-Hello-World/README.md b/exercises/01-Hello-World/README.md index 9510cd81..35efc390 100644 --- a/exercises/01-Hello-World/README.md +++ b/exercises/01-Hello-World/README.md @@ -18,7 +18,6 @@ Look at this example: ```HTML diff --git a/exercises/01-Hello-World/index.html b/exercises/01-Hello-World/index.html index 03ae0584..93d4ce1c 100644 --- a/exercises/01-Hello-World/index.html +++ b/exercises/01-Hello-World/index.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/exercises/01-Hello-World/solution.hide.html b/exercises/01-Hello-World/solution.hide.html new file mode 100644 index 00000000..b2ad5b0e --- /dev/null +++ b/exercises/01-Hello-World/solution.hide.html @@ -0,0 +1,7 @@ + + +Click me to open google.com diff --git a/exercises/01-Hello-World/test.js b/exercises/01-Hello-World/test.js new file mode 100644 index 00000000..fbe19bf5 --- /dev/null +++ b/exercises/01-Hello-World/test.js @@ -0,0 +1,34 @@ +const fs = require('fs'); +const path = require('path'); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +document.documentElement.innerHTML = html.toString(); + +jest.dontMock('fs'); + +const a = document.querySelector("a"); + +test("There should be an anchor tag", ()=>{ + expect(a).toBeTruthy() +}) + +test("The anchor tag should be pink", ()=>{ + let styles = window.getComputedStyle(a); + expect(styles["color"]).toBe("pink"); +}); + +test("There should be a href attribute pointing to 'https://google.com'", ()=>{ + let href = a.getAttribute('href'); + expect(href).toBeTruthy(); + expect(href).toBe("https://google.com"); +}) + +test("There should be a target attribute pointing to '_blank'", ()=>{ + let target = a.getAttribute('target'); + expect(target).toBeTruthy(); + expect(target).toBe("_blank"); +}) + +test("The anchor tag should not contains any inline style", ()=>{ + let emptyBodyInlineStyle = {}; + expect(a.style._values).toEqual(emptyBodyInlineStyle); +}); \ No newline at end of file diff --git a/exercises/01.1-The-Style-Tag/solution.hide.html b/exercises/01.1-The-Style-Tag/solution.hide.html new file mode 100644 index 00000000..659b76b3 --- /dev/null +++ b/exercises/01.1-The-Style-Tag/solution.hide.html @@ -0,0 +1,12 @@ + + +

+ Coding is a basic literacy in the digital age, and it is important for kids to understand and be able to work with and understand the technology + around them. Having children learn coding at a young age prepares them for the future. Coding helps children with communication, creativity, + math,writing, and confidence. +

\ No newline at end of file diff --git a/exercises/01.1-The-Style-Tag/test.js b/exercises/01.1-The-Style-Tag/test.js new file mode 100644 index 00000000..a4be505b --- /dev/null +++ b/exercises/01.1-The-Style-Tag/test.js @@ -0,0 +1,22 @@ +const fs = require('fs'); +const path = require('path'); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +document.documentElement.innerHTML = html.toString(); + +jest.dontMock('fs'); + +const p = document.querySelector("p"); + +test("There should be a p tag", ()=>{ + expect(p).toBeTruthy(); +}) + +test("The p tag color should be blue", ()=>{ + let styles = window.getComputedStyle(p); + expect(styles["color"]).toBe("blue"); +}); + +test("The p tag should not contain any inline style", ()=>{ + let emptyBodyInlineStyle = {}; + expect(p.style._values).toEqual(emptyBodyInlineStyle); +}); \ No newline at end of file diff --git a/exercises/01.2-Your-First-Style/solution.hide.html b/exercises/01.2-Your-First-Style/solution.hide.html new file mode 100644 index 00000000..3907bb3c --- /dev/null +++ b/exercises/01.2-Your-First-Style/solution.hide.html @@ -0,0 +1,14 @@ + + + + + + + Hello! I am an anchor in red, change my color to yellow + + diff --git a/exercises/01.2-Your-First-Style/tests.js b/exercises/01.2-Your-First-Style/tests.js index 8e94018b..0eabdf65 100644 --- a/exercises/01.2-Your-First-Style/tests.js +++ b/exercises/01.2-Your-First-Style/tests.js @@ -1,31 +1,30 @@ -const fs = require("fs"); -const path = require("path"); -const html = fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf8"); -// const css = fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8"); +const fs = require('fs'); +const path = require('path'); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +document.documentElement.innerHTML = html.toString(); -jest.dontMock("fs"); +jest.dontMock('fs'); -describe("All the styles should be applied", function() { - beforeEach(() => { - //here I import the HTML into the document - document.documentElement.innerHTML = html.toString(); - }); - afterEach(() => { - jest.resetModules(); - }); +describe("All the styles should be applied", ()=>{ + const a = document.querySelector("a"); - it("The background should be blue", function() { - const body = document.querySelector("body"); - var styles = window.getComputedStyle(body); - expect(styles["background"]).toBe("blue"); + test("The anchor tag should be yellow", ()=>{ + let styles = window.getComputedStyle(a); + expect(styles["color"]).toBe("yellow"); }); - it("The body tag should not contains any inline style", function() { + + test("The body tag should not contain any inline style", ()=>{ let bodyInlineStyle = document.getElementsByTagName("body"); let emptyBodyInlineStyle = {}; expect(bodyInlineStyle[0].style._values).toEqual(emptyBodyInlineStyle); - // console.log(bodyInlineStyle[0].style._values.background); }); - it("You should not change the existing head tag elements", function () { + + test("The anchor tag should not contain any inline style", ()=>{ + let emptyBodyInlineStyle = {}; + expect(a.style._values).toEqual(emptyBodyInlineStyle); + }); + + test("You should not change the existing head tag elements", ()=>{ let head = document.querySelector('head') expect(head).toBeTruthy() diff --git a/exercises/01.3-Your-Second-Style/index.html b/exercises/01.3-Your-Second-Style/index.html index 998d973a..03e672a3 100644 --- a/exercises/01.3-Your-Second-Style/index.html +++ b/exercises/01.3-Your-Second-Style/index.html @@ -3,6 +3,9 @@ diff --git a/exercises/01.3-Your-Second-Style/solution.hide.html b/exercises/01.3-Your-Second-Style/solution.hide.html new file mode 100644 index 00000000..9b239409 --- /dev/null +++ b/exercises/01.3-Your-Second-Style/solution.hide.html @@ -0,0 +1,14 @@ + + + + + + + Hello! My background should be blue! + + diff --git a/exercises/01.3-Your-Second-Style/tests.js b/exercises/01.3-Your-Second-Style/tests.js index 2e0fa1a3..147aabc5 100644 --- a/exercises/01.3-Your-Second-Style/tests.js +++ b/exercises/01.3-Your-Second-Style/tests.js @@ -1,33 +1,27 @@ -const fs = require("fs"); -const path = require("path"); -const html = fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf8"); -// const css = fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8"); +const fs = require('fs'); +const path = require('path'); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +document.documentElement.innerHTML = html.toString(); -jest.dontMock("fs"); +jest.dontMock('fs'); -describe("All the styles should be applied", function() { - beforeEach(() => { - //here I import the HTML into the document - document.documentElement.innerHTML = html.toString(); - }); - afterEach(() => { - jest.resetModules(); - }); +describe("All the styles should be applied", ()=>{ + const body = document.querySelector("body"); - it("The background should be blue", function() { - const body = document.querySelector("body"); - var styles = window.getComputedStyle(body); + test("The background should be blue", ()=>{ + let styles = window.getComputedStyle(body); expect(styles["background"]).toBe("blue"); }); - it("The body tag should not contains any inline style", function() { - let bodyInlineStyle = document.getElementsByTagName("body"); + + test("The body tag should not contains any inline style", ()=>{ let emptyBodyInlineStyle = {}; - expect(bodyInlineStyle[0].style._values).toEqual(emptyBodyInlineStyle); - // console.log(bodyInlineStyle[0].style._values.background); + expect(body.style._values).toEqual(emptyBodyInlineStyle); }); - it("You should not change the existing head tag elements", function () { + + test("You should not change the existing head tag elements", ()=>{ let head = document.querySelector('head') expect(head).toBeTruthy() + let meta = head.querySelector("meta") expect(meta).toBe(null) }) diff --git a/exercises/02-Separate-Stylesheet/solution.hide.css b/exercises/02-Separate-Stylesheet/solution.hide.css new file mode 100644 index 00000000..5250e305 --- /dev/null +++ b/exercises/02-Separate-Stylesheet/solution.hide.css @@ -0,0 +1,7 @@ +/* your styles here: + 1. Select the body tag. + 2. Add the background rule equal to blue. + */ +body { + background: blue; +} diff --git a/exercises/02-Separate-Stylesheet/tests.js b/exercises/02-Separate-Stylesheet/tests.js index a583e81e..f36df975 100644 --- a/exercises/02-Separate-Stylesheet/tests.js +++ b/exercises/02-Separate-Stylesheet/tests.js @@ -1,64 +1,34 @@ const fs=require("fs"); const path=require("path"); -const html=fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf8"); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); const css=fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8"); +document.documentElement.innerHTML = html.toString(); jest.dontMock("fs"); -describe("All the styles should be applied", function () { - beforeEach(() => { - //here I import the HTML into the document - document.documentElement.innerHTML=html.toString(); +describe("All the styles should be applied", ()=>{ + const link = document.querySelector("link"); + const body = document.querySelector("body"); - //apply the styles from the stylesheet if needed - - - - }); - afterEach(() => { - jest.resetModules(); - }); - it("The body tag should not contains any inline style", function () { - document.querySelector( - "head" - ).innerHTML=``; - let bodyInlineStyle=document.getElementsByTagName("body"); + test("The body tag should not contains any inline style", ()=>{ + document.querySelector("head").innerHTML = ``; let emptyBodyInlineStyle={}; - expect(bodyInlineStyle[0].style._values).toEqual(emptyBodyInlineStyle); - // expect(bodyInlineStyle[0].style._values.background - repeat).toBe( - // undefined - // ); - - console.log(bodyInlineStyle[0].style._values); + expect(body.style._values).toEqual(emptyBodyInlineStyle) }); - it("the background-size should be 'contain' without quotes", function () { - document.querySelector( - "head" - ).innerHTML=``; - // get computed styles of any element you like - const body=document.querySelector("body"); - let styles=window.getComputedStyle(body); - expect(styles["background-size"]).toBe("contain"); - }); - - it("the background-repeat should be 'inherit' without quotes", function () { - document.querySelector( - "head" - ).innerHTML=``; - - const body=document.querySelector("body"); - let styles=window.getComputedStyle(body); - expect(styles["background-repeat"]).toBe("inherit"); - }); - it("You should not change the existing head tag elements", function () { + test("You should not change the existing head tag elements", ()=>{ let head = document.querySelector('head') expect(head).toBeTruthy() let meta = head.querySelector("meta") expect(meta).toBe(null) - const pathname = new URL(document.querySelector('link').href).pathname - expect(pathname).toBe('/styles.css') + let href = link.getAttribute("href") + expect(href).toEqual('./styles.css') + }); + + test("Your body tag background color should be blue", ()=>{ + let styles = window.getComputedStyle(body) + expect(styles["background-color"]).toBe("blue") }) }); diff --git a/exercises/02.1-Background/solution.hide.css b/exercises/02.1-Background/solution.hide.css new file mode 100644 index 00000000..8c72a684 --- /dev/null +++ b/exercises/02.1-Background/solution.hide.css @@ -0,0 +1,5 @@ +body { + background-image: url(https://4geeksacademy.github.io/exercise-assets/img/bg/small-mosaic.jpg); + background-size: contain; + background-repeat: inherit; +} \ No newline at end of file diff --git a/exercises/02.1-Background/tests.js b/exercises/02.1-Background/tests.js index cfde6b1f..b223105f 100644 --- a/exercises/02.1-Background/tests.js +++ b/exercises/02.1-Background/tests.js @@ -1,67 +1,53 @@ -const fs=require("fs"); -const path=require("path"); -const html=fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf8"); -const css=fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8"); +const fs = require("fs"); +const path = require("path"); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +const css = fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8"); +document.documentElement.innerHTML = html.toString(); jest.dontMock("fs"); -describe("All the styles should be applied", function () { - beforeEach(() => { - //here I import the HTML into the document - document.documentElement.innerHTML=html.toString(); - - //apply the styles from the stylesheet if needed - - - - }); - afterEach(() => { - jest.resetModules(); - }); - it("The body tag should not contains any inline style", function () { +describe("All the styles should be applied", ()=>{ + const body = document.querySelector("body"); + const link = document.querySelector("link"); + const title = document.querySelector('title'); + + test("The body tag should not contains any inline style", ()=>{ document.querySelector( "head" - ).innerHTML=``; - let bodyInlineStyle=document.getElementsByTagName("body"); - let emptyBodyInlineStyle={}; - expect(bodyInlineStyle[0].style._values).toEqual(emptyBodyInlineStyle); - // expect(bodyInlineStyle[0].style._values.background - repeat).toBe( - // undefined - // ); - - console.log(bodyInlineStyle[0].style._values); + ).innerHTML = ``; + let emptyBodyInlineStyle = {}; + expect(body.style._values).toEqual(emptyBodyInlineStyle); }); - it("the background-size should be 'contain' without quotes", function () { + test("the background-size should be 'contain' without quotes", ()=>{ document.querySelector( "head" - ).innerHTML=``; + ).innerHTML = ``; // get computed styles of any element you like - const body=document.querySelector("body"); - let styles=window.getComputedStyle(body); + let styles = window.getComputedStyle(body); expect(styles["background-size"]).toBe("contain"); }); - it("the background-repeat should be 'inherit' without quotes", function () { + test("the background-repeat should be 'inherit' without quotes", ()=>{ document.querySelector( "head" - ).innerHTML=``; + ).innerHTML = ``; - const body=document.querySelector("body"); - let styles=window.getComputedStyle(body); + let styles = window.getComputedStyle(body); expect(styles["background-repeat"]).toBe("inherit"); }); - it("You should not change the existing head tag elements", function () { + + test("You should not change the existing head tag elements", ()=>{ let head = document.querySelector('head') expect(head).toBeTruthy() - + let meta = head.querySelector("meta") expect(meta).toBe(null) - - const pathname = new URL(document.querySelector('link').href).pathname - expect(pathname).toBe('/styles.css') - let title = head.querySelector('title').innerHTML - expect(title).toBe('02 Background') + const href = link.getAttribute("href") + expect(href).toBe('./styles.css') + + let titleInner = title.innerHTML + expect(titleInner).toBe('02 Background') }) }); diff --git a/exercises/03-Inline-Styles/solution.hide.html b/exercises/03-Inline-Styles/solution.hide.html new file mode 100644 index 00000000..1c3a3828 --- /dev/null +++ b/exercises/03-Inline-Styles/solution.hide.html @@ -0,0 +1,17 @@ + + + + 03 Inline Styles + + + + + + + + + + +
Hello
My brother
+ + \ No newline at end of file diff --git a/exercises/03-Inline-Styles/tests.js b/exercises/03-Inline-Styles/tests.js index 3de572dd..b0b7b629 100644 --- a/exercises/03-Inline-Styles/tests.js +++ b/exercises/03-Inline-Styles/tests.js @@ -1,24 +1,16 @@ - const fs = require("fs"); const path = require("path"); -const html = fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf8"); - +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +document.documentElement.innerHTML = html.toString(); jest.dontMock("fs"); -describe("The Table tag should contain inline style background: green", function() { - beforeEach(() => { - //here I import the HTML into the document - document.documentElement.innerHTML = html.toString(); - }); - afterEach(() => { - jest.resetModules(); - }); +describe("The Table tag should contain inline style background: green", ()=>{ - it("You should not change the existing head tag elements", function () { + test("You should not change the existing head tag elements", ()=>{ let head = document.querySelector('head') expect(head).toBeTruthy() - + let meta = head.querySelector("meta") expect(meta).toBe(null) @@ -26,10 +18,10 @@ describe("The Table tag should contain inline style background: green", function expect(title).toBe('03 Inline Styles') }) - it("The background should be green", function() { + test("The background should be green", ()=>{ const table = document.querySelector("table"); // expect(table.style.background === "green").toBeTruthy(); - var styles = window.getComputedStyle(table); + let styles = window.getComputedStyle(table); expect(styles["background"]).toBe("green"); }); }); diff --git a/exercises/04-Class-Selector/index.html b/exercises/04-Class-Selector/index.html index e3abd1bd..45709afb 100644 --- a/exercises/04-Class-Selector/index.html +++ b/exercises/04-Class-Selector/index.html @@ -2,9 +2,7 @@ - - 04 Class selector - + 04 Class selector diff --git a/exercises/04-Class-Selector/solution.hide.html b/exercises/04-Class-Selector/solution.hide.html new file mode 100644 index 00000000..60e1d67f --- /dev/null +++ b/exercises/04-Class-Selector/solution.hide.html @@ -0,0 +1,12 @@ + + + + + 04 Class selector + + + +

Hello!

+

World!

+ + diff --git a/exercises/04-Class-Selector/test.js b/exercises/04-Class-Selector/test.js new file mode 100644 index 00000000..58c20d17 --- /dev/null +++ b/exercises/04-Class-Selector/test.js @@ -0,0 +1,40 @@ +const fs = require("fs"); +const path = require("path"); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +const css = fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8"); +document.documentElement.innerHTML = html.toString(); + +jest.dontMock("fs"); + +describe("Both p tags should have a blue background", () => { + const body = document.querySelector("body") + const p = document.querySelectorAll("p"); + test("You should not change the existing head tag elements", () => { + let head = document.querySelector('head') + expect(head).toBeTruthy() + + let meta = head.querySelector("meta") + expect(meta).toBe(null) + + let title = head.querySelector('title').innerHTML + expect(title).toBe('04 Class selector') + }); + + test("The body tag should not contains any inline style", () => { + document.querySelector( + "head" + ).innerHTML = ``; + let emptyBodyInlineStyle = {}; + expect(body.style._values).toEqual(emptyBodyInlineStyle) + }); + + test("There should be two p tags", () => { + expect(p.length).toBe(2) + }); + test("Both p tags should have a class name 'b-blue' without the quotation marks", () => { + p.forEach(e=>{ + let eClass = e.getAttribute("class"); + expect(eClass).toBe("b-blue") + }) + }); +}); diff --git a/exercises/04.1-Combined-Rules/index.html b/exercises/04.1-Combined-Rules/index.html index 2af5a24c..1525b6cf 100644 --- a/exercises/04.1-Combined-Rules/index.html +++ b/exercises/04.1-Combined-Rules/index.html @@ -2,9 +2,7 @@ - - 04 Combined Rules - + 04.1 Combined Rules diff --git a/exercises/04.1-Combined-Rules/solution.hide.css b/exercises/04.1-Combined-Rules/solution.hide.css new file mode 100644 index 00000000..e9d46fd5 --- /dev/null +++ b/exercises/04.1-Combined-Rules/solution.hide.css @@ -0,0 +1,8 @@ +.myBox { + width: 50px; + height: 50px; + padding: 10px 190px 50px 30px; + + background: rgb(189, 189, 189) url(https://github.com/4GeeksAcademy/css-tutorial-exercises-course/blob/3a2d1dd03f58167a5a4894155af2d3aa4d41d647/.learn/assets/baby.jpg?raw=true) no-repeat 100px; + background-size: contain; +} \ No newline at end of file diff --git a/exercises/04.1-Combined-Rules/tests.js b/exercises/04.1-Combined-Rules/tests.js index 16c3296a..c6f62acc 100644 --- a/exercises/04.1-Combined-Rules/tests.js +++ b/exercises/04.1-Combined-Rules/tests.js @@ -1,126 +1,95 @@ -const fs=require("fs"); -const path=require("path"); -const html=fs.readFileSync(path.resolve(__dirname, "./index.html"), "utf8"); -const css=fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8"); +const fs = require("fs"); +const path = require("path"); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +const css = fs.readFileSync(path.resolve(__dirname, "./styles.css"), "utf8"); +document.documentElement.innerHTML = html.toString(); jest.dontMock("fs"); -describe("All the styles should be applied", function () { - beforeEach(() => { - //here I import the HTML into the document - document.documentElement.innerHTML=html.toString(); +describe("All the styles should be applied", ()=> { + const body = document.querySelector("body"); + const link = document.querySelector("link"); + const title = document.querySelector('title'); - //apply the styles from the stylesheet if needed - // document.querySelector( - // "head" - // ).innerHTML = ``; - }); - afterEach(() => { - jest.resetModules(); - }); - - // it("The styles.css file should be empty", function () { - // console.log(css); - // expect(css.toString()==="").toBeTruthy(); - // }); - // it("The Head tag should includes a Style tag", function () { - // expect(html.toString().indexOf(`-1).toBeTruthy(); - // }); - it("The body tag should not contains any inline style", function () { + test("The body tag should not contains any inline style", ()=> { document.querySelector( "head" - ).innerHTML=``; - let bodyInlineStyle=document.getElementsByTagName("style"); - let emptyBodyInlineStyle={}; - expect(bodyInlineStyle[0].style._values).toEqual(emptyBodyInlineStyle); - console.log("sty: ", bodyInlineStyle[0]); + ).innerHTML = ``; + let emptyBodyInlineStyle = {}; + expect(body.style._values).toEqual(emptyBodyInlineStyle); }); - it("the width should be '50px'", function () { + + test("the width should be '50px'", ()=> { // get computed styles of any element you like document.querySelector( "head" - ).innerHTML=``; + ).innerHTML = ``; - let cssArray=document.styleSheets[0].cssRules; - // console.log("$$$:", cssArray) - let orangeHoverSelector=""; - for (let i=0; i< cssArray.length; i++) { + if (cssArray[i].selectorText === ".myBox") { + orangeHoverSelector = cssArray[i].style.width; } } - expect(orangeHoverSelector).toBe('50px'); + expect(orangeHoverSelector).toBe('50px'); }); - it("the height should be '50px'", function () { + + test("the height should be '50px'", ()=> { // get computed styles of any element you like document.querySelector( "head" - ).innerHTML=``; + ).innerHTML = ``; - let cssArray=document.styleSheets[0].cssRules; - // console.log("$$$:", cssArray) - let orangeHoverSelector=""; - for (let i=0; i< cssArray.length; i++) { + if (cssArray[i].selectorText === ".myBox") { + orangeHoverSelector = cssArray[i].style.height; } } - expect(orangeHoverSelector).toBe('50px'); + expect(orangeHoverSelector).toBe('50px'); }); - // it("the background should be in rgb code rgb(189, 189, 189)", function() { - // // get computed styles of any element you like - // const body = document.querySelector(".myBox"); - // var styles = window.getComputedStyle(body); - // expect(styles["background"]).toBe("rgb(189, 189, 189)"); - // }); - - // it("the padding-top should be deleted", function () { - // // get computed styles of any element you like - // const body=document.querySelector(".myBox"); - // var styles=window.getComputedStyle(body); - // expect(styles["padding-top"]).toBeFalsy(); - // expect(styles["padding-bottom"]).toBeFalsy(); - // expect(styles["padding-right"]).toBeFalsy(); - // expect(styles["padding-left"]).toBeFalsy(); - - // }); - - it("the background-size should be contain", function () { + + test("the background-size should be contain", ()=> { document.querySelector( "head" - ).innerHTML=``; + ).innerHTML = ``; - let cssArray=document.styleSheets[0].cssRules; - // console.log("$$$:", cssArray) - let orangeHoverSelector=""; - for (let i=0; i< cssArray.length; i++) { + if (cssArray[i].selectorText === ".myBox") { + orangeHoverSelector = cssArray[i].style['background-size']; } } + expect(orangeHoverSelector).toBe('contain'); }); - it("the background should include the shorthand property", function () { + + test("the background should include the shorthand property", ()=> { document.querySelector( "head" - ).innerHTML=``; + ).innerHTML = ``; - let cssArray=document.styleSheets[0].cssRules; - console.log("$$$:", cssArray) - let orangeHoverSelector=""; + let cssArray = document.styleSheets[0].cssRules; + let orangeHoverSelector = ""; let backImg = ""; let backColor = ""; let backPos = ""; let backRepeat = ""; - for (let i=0; i< cssArray.length; i++) { + if (cssArray[i].selectorText === ".myBox") { + orangeHoverSelector = cssArray[i].style.background; + backImg = cssArray[i].style['background-image']; + backColor = cssArray[i].style['background-color']; + backPos = cssArray[i].style['background-position-x']; + backRepeat = cssArray[i].style['background-repeat']; } } expect(backColor).toBeFalsy(); @@ -133,25 +102,25 @@ describe("All the styles should be applied", function () { expect(orangeHoverSelector).toContain('url(https://github.com/4GeeksAcademy/css-tutorial-exercises-course/blob/3a2d1dd03f58167a5a4894155af2d3aa4d41d647/.learn/assets/baby.jpg?raw=true)'); }); - it("the padding should include the shorthand property in the right order (top, right, bottom, left)", function () { + test("the padding should include the shorthand property in the right order (top, right, bottom, left)", ()=> { document.querySelector( "head" - ).innerHTML=``; + ).innerHTML = ``; - let cssArray=document.styleSheets[0].cssRules; + let cssArray = document.styleSheets[0].cssRules; // console.log("$$$:", cssArray) - let orangeHoverSelector=""; - let padTop= ""; - let padRight= ""; - let padBottom= ""; - let padLeft= ""; - for (let i=0; i< cssArray.length; i++) { + if (cssArray[i].selectorText === ".myBox") { + orangeHoverSelector = cssArray[i].style.padding; + padTop = cssArray[i].style['padding-top'] + padRight = cssArray[i].style['padding-right'] + padBottom = cssArray[i].style['padding-bottom'] + padLeft = cssArray[i].style['padding-left'] } } expect(orangeHoverSelector).toBe('10px 190px 50px 30px'); @@ -160,17 +129,17 @@ describe("All the styles should be applied", function () { expect(padBottom).toBeFalsy(); expect(padLeft).toBeFalsy(); }); - it("You should not change the existing head tag elements", function () { + + test("You should not change the existing head tag elements", ()=> { let head = document.querySelector('head') expect(head).toBeTruthy() - + let meta = head.querySelector("meta") expect(meta).toBe(null) - - const pathname = new URL(document.querySelector('link').href).pathname - expect(pathname).toBe('/styles.css') - - let title = head.querySelector('title') - expect(title).not.toBe(null) + + const href = link.getAttribute("href") + expect(href).toBe('./styles.css') + + expect(title).toBeTruthy() }) }); diff --git a/exercises/04.2-Apply-several-classes/index.html b/exercises/04.2-Apply-several-classes/index.html index a64723af..3a293815 100644 --- a/exercises/04.2-Apply-several-classes/index.html +++ b/exercises/04.2-Apply-several-classes/index.html @@ -2,9 +2,7 @@ - - 04 Class selector - + 04.2 Apply several classes diff --git a/exercises/04.2-Apply-several-classes/solution.hide.html b/exercises/04.2-Apply-several-classes/solution.hide.html new file mode 100644 index 00000000..95de441b --- /dev/null +++ b/exercises/04.2-Apply-several-classes/solution.hide.html @@ -0,0 +1,11 @@ + + + + + 04.2 Apply several classes + + + +
9
+ + diff --git a/exercises/04.2-Apply-several-classes/test.js b/exercises/04.2-Apply-several-classes/test.js new file mode 100644 index 00000000..6d1d608e --- /dev/null +++ b/exercises/04.2-Apply-several-classes/test.js @@ -0,0 +1,18 @@ +const fs = require("fs"); +const path = require("path"); +const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf8'); +document.documentElement.innerHTML = html.toString(); + +jest.dontMock("fs"); + +describe("You should change the class on the div tag", () => { + const div = document.querySelector("div"); + + test("The div class should NOT have the spades class", () => { + expect(div.classList.contains("spade")).toBe(false); + }); + + test("The div class should have the heart class", () => { + expect(div.classList.contains("heart")).toBe(true); + }); +}); diff --git a/learn.json b/learn.json index 709ede73..dc56301e 100644 --- a/learn.json +++ b/learn.json @@ -11,8 +11,8 @@ "difficulty": "easy", "video-solutions": true, "graded": true, - "disabledActions": ["test"], - "disableGrading": true, + "disabledActions": [], + "disableGrading": false, "editor": { "version": "1.0.73" }