Tag Archives: blank.js

Yuav ua li cas: Configure tsev kuaj thiab tshuaj ntsuam cov kev pab uas muaj QUnit.js thiab Blanket.js rau ib qho chaw ua hauj lwm 365 SharePoint App

Intro

Twb tau kawm chav tsev kuaj thiab ntsuam xyuas cov kev pab tsis rau JavaScript nrog kuv ua hauj lwm hauv SharePoint app rau SharePoint hauv internet nyob rau hauv qhov chaw ua hauj lwm 365 Suite.  Cov cuab kev tshawb fawb paths coj kuv mus Qunit.js thiab txoj cai tom qab uas, mus Blanket.js.

QUnit cia kuv teeb tsev kuaj thiab koom rau hauv modules.  Ib tug module nws cia li yooj yim rau Teacher lwm yam kev kuaj. (Kuv tsis paub hais tias kuv yuav siv nws los siv yuav tsum, tab sis nws puas ua haujlwm rau kuv nyob deb thiaj nrog lub me me teeb ntawm kev ntsuam xyuas uas kuv tau deb deb li no txhais).

Blanket.js integrates nrog Qunit thiab nws yuav qhia kuv qhov tseeb kab ntawm JavaScript tau – thiab ntau ceeb tshaj – twb tsis tau tseg thaum khiav cov kev ntsuam xyuas.  Qhov no yog "los" – cov kab mob tseg yog them los ntawm txoj kev kuaj no thaum lwm tus uas tsis.

Teem mus kuaj mob zoo thiab saib cov kev pab them nqi, peb yuav txo tau qhov uas yuav ua kom cov code peb tau muab zais tsis xws luag.  Zoo sij hawm.

Qunit

Piv txwv tias yog koj muaj koj Studio uas koj siv qhov muag saib ib qhov teeb, pib los daus JavaScript pob ntawm http://qunitjs.com.  Ntxiv cov JavaScript thiab coj CSS koj cov tshuaj.  Mine looks li no:

image

Daim duab 1

Raws li koj tau pom, Kuv twb siv 1.13.0 thaum lub sij hawm uas kuv sau tau no blog tswg. Tsis txhob hnov qab ntxiv rau CSS daim download tau thiab kev pab.

Uas tawm hauv txoj kev, cov kauj ruam tom ntej yog los tsim tej yam xeem sam xauv nees thiab reference lub Qunit khoom.  Kuv yuav kuaj ib Rev muaj zog hauv ib tsab ntawv thov hu ua "QuizUtil.js" es kuv tsim ib nplooj hu ua "QuizUtil_test.html" thaum pom tias cov HTML:

image Daim duab 2

Ntawm no yog cov chaws:

<!DOCTYPE html>
<html xmlns= "http://xyoo 1999/xhtml www.w3.org/">
<lub taub hau>
    <npe>QuizUtil xeem nrog Qunit</npe>
    <txuas rel= "stylesheet" href="../CSS/qunit-1.13.0.CSS" />
    <tsab ntawv hom= "ntawv nyeem/javascript" src="QuizUtil.js" cov ntaub ntawv npog></tsab ntawv>
    <Script yam ="ntawv nyeem/javascript" src ="qunit-1.13.0.js"></tsab ntawv>
    <Script yam ="ntawv nyeem/javascript" src ="blanket.min.js"></tsab ntawv>

    <tsab ntawv>
        Module("getIDFromLookup");
        ntsuam xyuas("QuizUtil getIDFromLookupField", muaj nuj nqi () {
            Var goodValue = "1;#Paul Galvin";

            sib npaug(getIDFromLookupField(goodValue) + 1, 2), "Tus ID rau [" + goodValue + "] + 1 yuav tsum muaj rau 2";
            sib npaug(getIDFromLookupField(undefined), undefined, "Undefined input cav yuav rov raug undefined.");
            sib npaug(getIDFromLookupField(""), undefined, "Khoob input cav yuav tsum tau xa ib tus nqi uas undefined.");
            sib npaug(getIDFromLookupField("gobbledigood3-thq;dkvn ada;skfja sdjfbvubvqrubqer0873407t534piutheqw;vn"), undefined,"Yuav tsum nco ntsoov rov ib lub convertible no rau ib Integer");
            sib npaug(getIDFromLookupField("2;#ib txhia neeg"), "2", "Xyuas [2;#ib txhia neeg].");
            sib npaug(getIDFromLookupField("9834524;#tus nqi uas ntev"), "9834524", "Coob tus nqi kuaj.");
            notEqual(getIDFromLookupField("5;#leej twg los", 6), 6, "Kuaj ib notEqual (5 yog tsis sib npaug 6 rau cov qauv no: [5;#leej twg los]");

        });

        Module("htmlEscape");
        ntsuam xyuas("QuizUtil htmlEscape()", muaj nuj nqi () {
            sib npaug(htmlEscape("<"), "&LT;", "Escaping ib tug tsawg dua li tus neeg teb xov tooj ('<')");
            sib npaug(htmlEscape("<div hoob = yog muaj "someclass">Tej ntawv nyeem</div>"), "&LT;chav kawm ntawv div =&quot;someclass&quot;&gt;Tej ntawv nyeem&LT;/div&gt;", "Ntau xeem txoj hlua.");
        });

        Module("getDateAsCaml");
        ntsuam xyuas("QuizUtil getDateAsCaml()", muaj nuj nqi () {
            sib npaug(getDateAsCaml(tshiab Hnub tim("12/31/2013")), "2013-12-31T:00:00:00", "Kuaj coded ib hnub: [12/31/2013]");
            sib npaug(getDateAsCaml(tshiab Hnub tim("01/05/2014")), "2014-01-05T:00:00:00", "Kuaj coded ib hnub: [01/05/2014]");
            sib npaug(getDateAsCaml(tshiab Hnub tim("01/31/2014")), "2014-01-31T:00:00:00", "Kuaj coded ib hnub: [01/31/2014]");
            sib npaug(getTodayAsCaml(), getDateAsCaml(tshiab Hnub tim()), "getTodayAsCaml() yuav tsum siab sib npaug getDateAsCaml(Hnub tshiab())");
            sib npaug(getDateAsCaml("dev paus tus nqi"), undefined, "Sim tau hnub ntawm ib cov nqi dev paus.");
            sib npaug(getDateAsCaml(undefined), undefined, "Sim tau lub hnub lub [undefined] hnub.");
        });

        Module("getParameterByName");
        ntsuam xyuas("QuizUtil getParameterByName (los ntawm cov lus nug hlua)", muaj nuj nqi () {
            sib npaug(getParameterByName(undefined), undefined, "Sim nrhiav undefined parameter yuav tsum tau rov undefined.");
            sib npaug(getParameterByName(muaj "tsis nyob"), undefined, "Sim nrhiav parameter nqi thaum uas peb paub tias muaj tus parameter tsis nyob.");

        });

        Module("Ncuav qab zib");
        ntsuam xyuas("QuizUtil kua nplaum uas ntau zog.", muaj nuj nqi () {
            sib npaug(setCookie("sim", "1", -1), getCookieValue("sim"), "Tau ib cov kua nplaum uas kuv teem caij yuav tsum tau ua.");
            sib npaug(setCookie("anycookie", "1", -1), tseeb, "Qhov chaw kawm ib tug siv tau noj yuav tsum tau xa 'nws muaj tseeb'.");
            sib npaug(setCookie("npab kua nplaum uas lub npe !@#$%"%\^&*(()?/><.,", "1", -1), tseeb, "Qhov chaw kawm ib lub npe phem cov kua nplaum uas yuav tsum tau rov 'cuav'.");
            sib npaug(setCookie(undefined, "1", -1), undefined, "Raws li cov kua nplaum uas npe undefined.");
            sib npaug(getCookieValue(muaj "tsis nyob"), "", Muaj "kua nplaum uas tsis nyob ntawd.");
        });

    </tsab ntawv>
</lub taub hau>
<lub cev>
    <div tus ID= "qunit"></div>
    <div tus ID= "qunit-fixture"></div>

</lub cev>
</html>

Muaj ntau ntau yam zoj zis no:

  1. Referencing kuv code (QuizUtil.js)
  2. Referencing Qunity.js
  3. Defining tej modules (getIDFromLookup, Ncuav qab zib, thiab lwm tus)
  4. Muab ib <div> nws daim ID yog "qunit".

Ces, Kuv cia li rub tau cov nplooj ntawv no thiab koj mus muab tau tej yam zoo li no:

image

Daim duab 3

Yog qhov koj saib hla saum, koj tau xaiv ob peb, yog ob tug uas nthuav:

  • Hide dhau kev ntsuam xyuas: Cuab kev zoo nkauj.  Yuav pab tau koj qhov muag pom xwb lub teeb meem chaw thiab tsis muaj coob plaus.
  • Module: (hlauv): Qhov no yuav lim tau cov kev ntsuam xyuas pawg xwb cov kev ntsuam xyuas uas koj xav mus ua.

Ntawm kev tshuaj ntsuam lawv tus kheej – ob peb lus:

  • Nws yuav mus tsis tau hais tias koj tau sau koj cov cai xws tias nws yog testable ua tus xub place.  Siv cov cuab tam yuav pab tswj qhov kev qhuab qhia. Piv txwv, Kuv muaj ib tug ua haujlwm hu ua "getTodayAsCaml()”.  Qhov no tsis testable heev vim nws yuav siv sij hawm tsis sib cav uas input thiab kuaj kev koob pheej ntawm lawv, peb yuav tau lossi kho qhov chaws kuaj kom muaj kev cuam tshuam rau hnub tam sim no.  Kuv refactored ntawd los ntawm kev muab ib cov ntaub ntawv input parameter ces dua sau hnub thaum kuv xav hnub no CAML hom.
  • Qhov lub moj khaum Qunit ntaub ntawv rau qhov kev ntsuam xyuas nws tus kheej thiab no mas, robust zoo nkauj.  Nws yuav ua tau tej yam yooj yim xws li kuaj kev koob pheej ntawm lawv thiab tseem muaj nyiaj yug rau ajax style hu (ob leeg "tiag tiag" los mocked siv koj txoj kev mocker).
  • Yuav ua raws cov txheej txheem kuj forces koj xav mus txog ntug no – yuav ua cas nrog "undefined" lossis null dhau mus ua ib tug muaj nuj nqi.  Nws ua nws tuag yooj yim mus kuaj cov scenarios tawm.  Khoom zoo.

Cov kev pab uas muaj Blanket.js

Blanket.js complements Qunit los nrhiav lub txoos kab kev cai txim tuag thaum khiav koj kev ntsuam xyuas.  Nws integrates txoj cai rau hauv Qunit no, txawm ho yog ib tus tseem cais app, nws nicely plays – nws yeej zoo li nws yog ib tug seamless app.

Qhov no nws yog blanket.js rau hauv ntawv:

image Daim duab 4

image

Daim duab 5

(Koj yeej tau mus nias rau ntawm "Pab kom cov kev pab" checkbox rau saum [pom daim duab 3] kom niam no.)

Tus kab highlighted nyob hauv daim duab 5 tau tsis tau tseg los ntawm ib yam ntawm kuv qhov kev ntsuam xyuas, li ntawd, kuv yuav npaj ib txoj kev kuaj uas ua rau lawv rau txim tuag yog kuv xav tau kev pab tas nrho.

Tau ua hauj lwm los yog ua raws li cov kauj ruam nram blanket.js:

  1. Download tau nws tawm http://blanketjs.org/.
  2. Ntxiv rau koj qhov project
  3. Hloov koj nplooj ntawv kuaj sam xauv nees (QuizUtil_test.html hauv kuv tsev neeg) raws li nram no:
    1. Siv tus cai
    2. Kho koj <tsab ntawv> siv nyiam qhov no:
    <tsab ntawv hom= "ntawv nyeem/javascript" src="QuizUtil.js" cov ntaub ntawv npog></tsab ntawv>

Blanket.js picks los ntawm "cov ntaub ntawv npog" attribute thiab puas tau nws cov khawv koob.  Nws mus ua Qunit hooks, siab tus UI ntxiv qhov "Pab kom cov kev pab" option thiab voila!

Txoj kev (TL; DR)

Siv Qunit los mus sau koj cov raug kuaj.

  • Download tau nws
  • Ntxiv rau koj qhov project
  • Sau tau ib nplooj ntawv kuaj sam xauv nees
  • Ua kom muaj qhov kev ntsuam xyuas koj
    • Ib txhia ntawm koj cov cai ua testable refactor
    • Yuav muaj tswv yim!  Xav txog crazy, scenarios yeej ua thiab kuaj lawv lawm.

Siv cov blanket.js kom muaj kev pab them nqi

  • Xyuas kom tseeb tias Qunit ua hauj lwm
  • Download tau blanket.js thiab ntxiv mus rau koj qhov project
  • Ntxiv rau mus kuaj sam xauv nees phab:
    • Ntxiv ib siv mus blanket.js
    • Ntxiv "cov ntaub ntawv npog" attribute rau koj <tsab ntawv> lossis
  • Khiav koj cov kev kuaj Qunit.

Kuv yeej tsis ua yam no ua ntej thiab muaj ib co rudimentary khoom ua hauj lwm ib handful teev. 

Kev soj ntsuam zoo siab!

</kawg>

undefinedSubscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin