Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prettify linked tests : Fixes #1374 #1487

Merged
merged 13 commits into from
Feb 15, 2018

Conversation

shikhar-scs
Copy link
Contributor

As suggested by @marcoscaceres , the required changes mentioned at #1374 have been made. Here's a preview

heheheheehehe

Please preview

@shikhar-scs
Copy link
Contributor Author

shikhar-scs commented Feb 8, 2018

@marcoscaceres I have pushed in some new changes. Please review.

yoyoyoyy

Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick changes... I'm unsure about your usage of hyperHTML there also, but we can look at that after this round of fixes.

<a href="${href}">
${href.split("/").pop()}
${modifiedHref.split('-').join(' ')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon reflection, I think I'd like us to keep the "-".

@@ -23,11 +23,34 @@ export const name = "core/data-tests";
const lang = defaultLang in l10n ? defaultLang : "en";

function toListItem(href) {
return hyperHTML.bind(document.createElement("li"))`

let modifiedHref = href.split("/").pop().split(".html")[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

const [modifiedHref] = href.split("/").pop().split(".html");

Also, might be worth checking if the tests always end with ".html"... Some might end with just ".htm", but double check in the web platform test repository.


let emojiList = document.createElement('i');

let requiresConnectionEmoji = hyperHTML.bind(document.createElement("i"))` 🔒 `;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you chose i element in particular? I would figure maybe a span might be better here?

let emojiList = document.createElement('i');

let requiresConnectionEmoji = hyperHTML.bind(document.createElement("i"))` 🔒 `;
requiresConnectionEmoji.setAttribute('aria-label','require-secure-connection');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that aria-label is read out by a screen reader, so we want to make this as friendly as possible. I would suggest instead: "requires a secure connection".

We have quite a few users with visual impairments, so we do our best to support their needs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate that 👏

let requiresConnectionEmoji = hyperHTML.bind(document.createElement("i"))` 🔒 `;
requiresConnectionEmoji.setAttribute('aria-label','require-secure-connection');

let manualPerformEmoji = hyperHTML.bind(document.createElement("i"))` 💪 `;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, and aria label "the test must be run manually"


let emojiList = document.createElement('i');

let requiresConnectionEmoji = hyperHTML.bind(document.createElement("i"))` 🔒 `;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These elements should only be created inside the if statements below. Otherwise, they are getting created unnecessarily if not needed (and then thrown away).


let modifiedHref = href.split("/").pop().split(".html")[0];

let emojiList = document.createElement('i');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: all the let should be const, as we are not reassigning them.

@marcoscaceres
Copy link
Contributor

Just a general note that in the project we are using double quotes 😉

To pretty up the code, I've been using (prettier.js)[https://github.com/prettier/prettier] via Visual Studio Code... but also works in the command line.

@marcoscaceres
Copy link
Contributor

@shikhar-scs, if you are unsure about any JS syntax stuff (e.g., when should I use const vs let vs var), please let me know. Happy to give you pointers to explain the difference.

@shikhar-scs
Copy link
Contributor Author

Thank you for the review . I'll post the corrected changes soon👍

@marcoscaceres
Copy link
Contributor

Thanks for continuing to hack in this. I’m just on my way home, so will take a look first thing tomorrow.

@shikhar-scs
Copy link
Contributor Author

shikhar-scs commented Feb 8, 2018

To pretty up the code, I've been using (prettier.js)[https://github.com/prettier/prettier] via Visual Studio

Thankyou for your suggestions and though I do l know the differences between var let and const, I'll ask you in case I have any doubts.

I've pushed some new changes. And as of now, please ignore the changes made to basic.html

I’m just on my way home, so will take a look first thing tomorrow.

No problem

Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is mostly there, but a bit of refactoring needed here to keep this code easy to work with.

We can also do some optimizations, but trying to do the least amount of work possible.

@@ -3,8 +3,8 @@
<head>
<meta charset='utf-8'>
<title>Replace me with a real title</title>
<script src='../js/deps/require.js' data-main='../js/profile-w3c-common'
async class='remove'></script>
<script src='../js/deps/require.js' data-main='../js/profile-w3c-common'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert changes to this file.


// const modifiedHref = href.split("/").pop().split(".")[0];

if ( href.split("/").pop().split(".").includes("html") || href.split("/").pop().split(".").includes("htm") ) {
Copy link
Contributor

@marcoscaceres marcoscaceres Feb 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: make this two steps, and combine the search (otherwise, you are doing things twice):

// the last item will be the filename
const [testFile] = new URL(href).pathname.split("/").reverse();

// next we want to work out the type
const testParts = testFile.split(".");
const [testFile] = testParts; // the first item 
const isSecureTest = testParts.find(part => part === "https");
// this is probably incorrect, but find "manual" like this:  
const isManualTest = testFile.split("-").find(part => part === "manual");

// then 
if(isSecure){
  // add secure emoji...
}

if(isManualTest) {
  // add manual emoji
} 

@@ -24,34 +24,37 @@ const lang = defaultLang in l10n ? defaultLang : "en";

function toListItem(href) {

// const modifiedHref = href.split("/").pop().split(".")[0];
var [testFile] = new URL(href).pathname.split("/").reverse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename this to something else, don't reassign it below (otherwise it's confusing to know what this actually is)

Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting there 👍

@@ -23,11 +23,42 @@ export const name = "core/data-tests";
const lang = defaultLang in l10n ? defaultLang : "en";

function toListItem(href) {
return hyperHTML.bind(document.createElement("li"))`

var [testFile] = new URL(href).pathname.split("/").reverse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, call this something else and don't reassign it... otherwise, its confusing to know what this actually is.

const requiresConnectionEmoji = hyperHTML.bind(document.createElement("span"))` 🔒 `;
requiresConnectionEmoji.setAttribute("aria-label","requires a secure connection");

console.log(testFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove console.log

requiresConnectionEmoji.setAttribute("aria-label","requires a secure connection");

console.log(testFile)
testFile.split(".https").join("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line doesn't do anything :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does. It removes the .https parts from the end

@shikhar-scs
Copy link
Contributor Author

Please review now @marcoscaceres . I've also squashed all my commits

Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed up style and a few small bugs. Make sure you git pull the changes.

const isSecureTest = testParts.find(part => part === "https");
const isManualTest = testFileName.split(".").join("-").split("-").find(part => part === "manual");

let emojiList = document.createElement("span");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this should be a const, as it's not being reassigned, right?


const isSecureTest = testParts.find(part => part === "https");
if (isSecureTest) {
const requiresConnectionEmoji = hyperHTML.bind(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems unnecessary to use hyperHTML here, and same in the isManualTest block below. Just create spans here, and don't bind them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanx for that 👍

.split("-")
.find(part => part === "manual");
if (isManualTest) {
const manualPerformEmoji = hyperHTML.bind(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure 👍

</a>
`;
testList.append(emojiList);
Copy link
Contributor

@marcoscaceres marcoscaceres Feb 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I think testList should "render" like this:

 <a href="${href}">
    ${testFileName}
 </a> ${emojiList}

@@ -23,11 +23,50 @@ export const name = "core/data-tests";
const lang = defaultLang in l10n ? defaultLang : "en";

function toListItem(href) {
return hyperHTML.bind(document.createElement("li"))`
const emojiList = document.createElement("span");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this should be an array really... otherwise, this could end up with either and empty span or with a nested set of spans:

<a href="...">name-of-test</a> 
<!-- nested span are not great -->
<span>
   <span>💪</span>
</span>

We want to end up with markup like this:

<li>
  <a href="...">name-of-test</a> <span>💪</span> <span>🔒</span>
</li>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still remaining to be fixed, right? (i.e., const emojiList = [];, instead of using a span)

if (isManualTest) {
const manualPerformEmoji = hyperHTML.bind(
document.createElement("span")
)` 💪 `;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we probably don't need the whitespace. We should add that between the spans. If we then want them to have more padding, we should add that using CSS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I'll keep all of that in mind 👍

)` 💪 `;
manualPerformEmoji.setAttribute(
const manualPerformEmoji = document.createElement("span")
manualPerformEmoji.innerHTML = `💪`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: note that the indentation will get reset by prettier.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh completely forgot about that. Apart from that any more changes you would like to see ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lastly, we would need to add tests to tests/spec/core/data-tests-spec.js, that check all the new changes we've made.

So, pretty close to being done here! Thanks for hanging in there!

@shikhar-scs
Copy link
Contributor Author

@Marcos I've written the tests related to my code and pushed them here. Please review 😅

@marcoscaceres
Copy link
Contributor

@shikhar-scs, just stepping out, but promise to review first thing tomorrow! Thanks for putting in the work.

@shikhar-scs
Copy link
Contributor Author

@marcoscaceres Not an issue at all. I'll wait for tomorrow 👍

Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of small things. Nearly there however!

@@ -23,11 +23,50 @@ export const name = "core/data-tests";
const lang = defaultLang in l10n ? defaultLang : "en";

function toListItem(href) {
return hyperHTML.bind(document.createElement("li"))`
const emojiList = document.createElement("span");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still remaining to be fixed, right? (i.e., const emojiList = [];, instead of using a span)

@@ -17,6 +17,11 @@ describe("Core — data-tests attribute", () => {
<a id="t1" data-cite="#test">a</a>
<dfn id="t2" data-cite="#test">a</dfn>
</p>
<p id="metadata-tests"
data-tests="this-is-secure.https.html,
this-is-manual.html, this-is-secure-and-manual.https.html">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: put "this-is-secure-and-manual.https.html" on a new line, so it's visually distinct from the other two. Basically, we want:

data-tests="
   this-is-secure.https.html,
   this-is-manual.html,
   this-is-secure-and-manual.https.html"

@@ -63,5 +68,33 @@ describe("Core — data-tests attribute", () => {
expect(pathname.endsWith(`test${i}.html`)).toBe(true);
});
});
it(`adds emojis for manual and https related tests`, () => {

let test = doc.querySelector("#metadata-tests ul").querySelectorAll("li")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you have the tests here, we should split the tests into three separate it() statements:

it("adds emojis for secure tests", () => {
  const li = doc.querySelector("#metadata-tests ul>li:nth-child(1)");
  // other stuff
});
it("adds emojis for manual tests", () => {
  const li = doc.querySelector("#metadata-tests ul>li:nth-child(2)");
  // other stuff
});
it("adds emojis for secure manual tests", () => {
  const li = doc.querySelector("#metadata-tests ul>li:nth-child(3)");
  // other stuff
});

let test = doc.querySelector("#metadata-tests ul").querySelectorAll("li")

// for test 1
expect(test[0].children[0].innerText.trim()).toEqual("this-is-secure"); // filename
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be better here:

const filename = li.innerText.trim();
expect(filename).toEqual("this-is-secure");

Then it's much more clear exactly what you are testing, same applies to the ones below. Basically, if you find that you have to leave a comment, e.g., // filename, that's a strong sign you should be using a variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note also here, the fact that you are calling .trim() seems like it might be a bug in the implementation. You shouldn't need to call trim, as the implementation should have trimmed it.

shikhar-scs and others added 3 commits February 15, 2018 11:29
Fixed js style to match project.
Missing semicolons, etc.
Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕺Awesome work! I ran the code through prettier, so no to bother you with nits.

Last little question and one small change, and we should be all good to go.

it(`adds emojis for secure tests`, () => {
const li = doc.querySelector("#metadata-tests ul>li:nth-child(1)");

const fileName = li.children[0].innerText.trim();
Copy link
Contributor

@marcoscaceres marcoscaceres Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, having to do "li.children[0]" and "li.children[1]" is not ideal here, because it's not clear what element you are working with. Can you please destructure the array into named variables, like (you can probably come up with better names):

const [fileElement, secureIconElement] = li.children;

Similarly for the ones below...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo above, I mean "is not ideal"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah Sure 👍

);
expect(spanAriaLabel2).toEqual("the test must be run manually");

const spanTitle2 = li.children[1].children[1].getAttribute("title");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd that they are nested? I think this might be a bug. The tree structure should be:

<span>file-name</span> <span>emoji</span> <span>emoji</span>

Or am I reading this wrong?

Copy link
Contributor Author

@shikhar-scs shikhar-scs Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its something like

<li><a>fileName</a><span>emoji</span><span>emoji</span></li>

So, yeah roughly the same

@shikhar-scs
Copy link
Contributor Author

@marcoscaceres I've refactored the code, removing all children[i] parts of code by destructuring the array. Also I realised that because of introducing the emojilist = [] instead of initialising it as a querySelector , the structure of the li element had to be changed a bit for selecting the spans .
Thanks for reminding.

Please review the code now.

Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Looking forward to trying this out!

@shikhar-scs
Copy link
Contributor Author

Ready for merge ??

@marcoscaceres
Copy link
Contributor

yep, was just waiting for green light from TravisCI.

@marcoscaceres marcoscaceres merged commit ba657af into speced:develop Feb 15, 2018
marcoscaceres added a commit that referenced this pull request Feb 15, 2018
* develop:
  v19.6.0
  feat: add icons to describe tests (#1487)
  nit(headers-spec): use %20 instead of space
@marcoscaceres
Copy link
Contributor

respec@19.6.0 going live now. Great work @shikhar-scs!

@marcoscaceres
Copy link
Contributor

Looking hella nice in a real spec (make sure you shift-refresh) https://w3c.github.io/payment-request/ 😻

@shikhar-scs
Copy link
Contributor Author

Thanks a lot @marcoscaceres . My first contribution to respec 🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants