Best JavaScript code snippet using cypress
multimp.js
Source:multimp.js
1module.exports = {2 Navi,3}4// å¨å¾®ä¿¡å°ç¨åºä¸ä½¿ç¨5function Navi(url) {6 var [appid, to] = _Navi(url)7 wx.navigateToMiniProgram({8 appId: appid,9 path: to,10 success(res) {11 console.log('Navi success:', res)12 },13 fail(res) {14 console.log('Navi fail:', res)15 }16 })17}18function _Navi(url) {19 var match = -120 for (var i = 0; i < directTransform.length; i++) {21 var trans = directTransform[i]22 var urlPrefix = trans.urlPrefix23 if (url.startsWith(urlPrefix)) { 24 match = i; break;25 }26 }27 if (match == -1) {return false}28 var trans = directTransform[match]29 var urlPrefix = trans.urlPrefix30 var nickname = trans.nickname31 if (url[url.length-1] == '/') {32 url = url.slice(0, url.length-1)33 }34 var to = trans.genMPUrl(trans, url)35 console.log('Navi url: ', url, ' to ', nickname, ' appid: ', trans.appid, to)36 return [trans.appid, to]37}38function Link(url) {39 var [appid, to] = _Navi(url)40 var link = '<a data-miniprogram-appid="' + appid + '" data-miniprogram-path="' + to + '" href="">ç¹å»</a>'41 console.log(link)42}43var directTransform = [{44 nickname: 'å¼æºBooks',45 appid: 'wxe60c5750c87916e0',46 indexPage: 'pages/bloglist/bloglist',47 urlPrefix: 'https://github.com',48 genMPUrl: function(meta, url) {49 var [owner, repo, filepath] = parseGitHub(url)50 console.log("parseGitHub url:", owner, repo, filepath)51 if (owner == "") { return meta.indexPage}52 else if (repo == "") { return 'pages/account/account?owner=' + owner }53 else if (filepath == "") { return 'pages/readme/readme?repo=' + owner + '/' + repo }54 else if (filepath.startsWith('issues/') || filepath.startsWith('pull/')) {55 var issue = 'https://api.github.com/repos/' + owner + '/' + repo + '/' + filepath.replace('pull/', 'issues/')56 return '/pages/issue/issue?issue='+issue57 }58 else { return 'pages/gitfile/gitfile?file=' + filepath + '&owner=' + owner + '&repo=' + repo }59 },60}, {61 nickname: 'iDayDayUP',62 appid: 'wx482958efb057c5a7',63 indexPage: 'pages/daily/daily',64 urlPrefix: 'https://idaydayup.com',65 genMPUrl: DefaultIndexMPWithPara,66}, {67 nickname: 'å¼æºè¯é¢',68 appid: 'wx0b48bcbd26917a62',69 indexPage: 'pages/bloglist/bloglist',70 urlPrefix: 'https://opensourcetopic.com',71 genMPUrl: DefaultIndexMPWithPara,72}, {73 nickname: 'Readhub',74 appid: 'wxd83c7f07a0b00f1b',75 urlPrefix: 'https://readhub.cn/topic',76 indexPage: 'pages/index',77 genMPUrl: function(meta, url) {78 var idx = url.indexOf(meta.urlPrefix)79 if (idx == -1) { return meta.indexPage }80 // Topic URL: https://readhub.cn/topic/7NgjG2U66fX81 // Index Page: https://readhub.cn/topics82 var topicID = url.slice(meta.urlPrefix.length+idx+1, url.length)83 if (topicID == "" || topicID == "/") { return meta.indexPage }84 return 'pages/detail?id=' + topicID85 },86}, {87 nickname: 'åå©åå©',88 appid: 'wx7564fd5313d24844',89 urlPrefix: 'https://www.bilibili.com/video/av',90 indexPage: 'pages/index/index',91 genMPUrl: function(meta, url) {92 var idx = url.indexOf(meta.urlPrefix)93 if (idx == -1) {return meta.indexPage }94 // pages/video/video?avid=5480978195 // https://www.bilibili.com/video/av54809781?spm_id_from=333.334.b_62696c695f67756f636875616e67.5196 var qmark = url.indexOf('?')97 var start = meta.urlPrefix.length+idx98 var id = url.slice(start, qmark!=-1&&qmark>start ? qmark : url.length)99 if (id == "" || id == "/") { return meta.indexPage }100 return 'pages/video/video?avid=' + id101 },102}, {103 nickname: 'è
¾è®¯è§é¢',104 appid: 'wxa75efa648b60994b',105 urlPrefix: 'https://v.qq.com/x/cover/',106 indexPage: 'pages/index/index',107 genMPUrl: function(meta, url) {108 var idx = url.indexOf(meta.urlPrefix)109 if (idx == -1) {return meta.indexPage }110 // pages/play/index.html?cid=jeds18ea11rrnbg&parentParams=111 // https://v.qq.com/x/cover/jeds18ea11rrnbg.html112 // https://v.qq.com/x/cover/5vgz1duinuar746/r00314e3n1i.html113 var arr = url.split('/')114 var id = arr[arr.length-1]115 if (id.indexOf('.html') != -1) {116 id = id.slice(0, id.indexOf('.html'))117 }118 if (id == "" || id == "/") { return meta.indexPage }119 return 'pages/play/index?parentParams=&cid=' + id120 },121}, {122 nickname: 'CSDN',123 appid: 'wx2115aba2ed1f96b9',124 urlPrefix: 'https://blog.csdn.net',125 indexPage: 'pages/index/index',126 genMPUrl: function(meta, url) {127 var idx = url.indexOf(meta.urlPrefix)128 if (idx == -1 || url.indexOf('/article/details/') == -1) {return meta.indexPage }129 // pages/blog/article-detail?userName=qq_41753040&articleId=90633737&__key_=15599641012541130 // https://blog.csdn.net/qq_41753040/article/details/90633737131 var arr = url.slice(meta.urlPrefix.length, url.length).split('/')132 if (arr.length < 4) { return meta.indexPage }133 var username = arr[0]134 var id = arr[3]135 if (username == 0 || id == "" || id == "/") { return meta.indexPage }136 return 'pages/blog/article-detail?userName=' + username + '&articleId=' + id137 },138}, {139 nickname: 'ç®ä¹¦',140 appid: 'wx646159264d261dab',141 urlPrefix: 'https://www.jianshu.com',142 indexPage: 'pages/index',143 // https://www.jianshu.com/p/24d22539d45a144 genMPUrl: GenFormatOneMPUrl('p', 'pages/note?slug='),145}, {146 nickname: 'ç¥ä¹çæ¦',147 appid: 'wxeb39b10e39bf6b54',148 urlPrefix: 'https://www.zhihu.com',149 indexPage: 'pages/index/index',150 // https://www.zhihu.com/question/329765131151 genMPUrl: GenFormatOneMPUrl('question', 'zhihu/question?id='),152}, {153 nickname: 'ç¥ä¹çæ¦',154 appid: 'wxeb39b10e39bf6b54',155 urlPrefix: 'https://zhuanlan.zhihu.com',156 indexPage: 'pages/index/index',157 // https://zhuanlan.zhihu.com/p/63501230158 genMPUrl: GenFormatOneMPUrl('p', 'zhihu/article?id='),159}, {160 nickname: 'ä»ä¹å¼å¾ä¹°',161 appid: 'wxeb5d1f826d7998df',162 urlPrefix: 'https://www.smzdm.com',163 indexPage: 'pages/index/index',164 // https://www.smzdm.com/p/14483467/165 genMPUrl: GenFormatOneMPUrl('p', 'pages/haojia_details/haojia_details?id='),166}, {167 nickname: 'ä»ä¹å¼å¾ä¹°',168 appid: 'wxeb5d1f826d7998df',169 urlPrefix: 'https://post.smzdm.com',170 indexPage: 'pages/index/index',171 // https://post.smzdm.com/p/ax08nrm2/172 genMPUrl: GenFormatOneMPUrl('p', 'pages/haowen_details/haowen_details?type=11&id='),173}, {174 nickname: 'ç¾åº¦ç½ç',175 appid: 'wxdcd3d073e47d1742',176 urlPrefix: 'https://pan.baidu.com',177 indexPage: 'pages/netdisk_index/index',178 // https://pan.baidu.com/s/10v3OUqXpkBnpurKFLI40jQ179 genMPUrl: GenFormatOneMPUrl('s', 'pages/netdisk_share/share?scene='),180}, {181 nickname: '36æ°ªLite',182 appid: 'wx23551bed0b72cd7f',183 urlPrefix: 'https://36kr.com',184 indexPage: 'pages/list/list',185 // https://36kr.com/p/5220102186 genMPUrl: GenFormatOneMPUrl('p', 'pages/detail/detail?id='),187}, {188 nickname: 'æé第ä¸æ¹ç',189 appid: 'wx0f72a9f832b78889',190 urlPrefix: 'https://juejin.im',191 indexPage: 'pages/launch/launch',192 // https://juejin.im/post/5d147765f265da1bb003d0dc193 genMPUrl: GenFormatOneMPUrl('post', 'pages/post/post?type=post&id='),194}, {195 nickname: 'V2EX For You',196 appid: 'wx1b979cda6b085993',197 urlPrefix: 'https://www.v2ex.com',198 indexPage: 'pages/index/index',199 // https://www.v2ex.com/t/578260#reply22200 genMPUrl: function (meta, url) {201 var p = GenFormatOneMPUrl('t', 'pages/topic/index?topicId=')(meta, url)202 if (p.indexOf('#') != -1 ){203 p = p.slice(0, p.indexOf('#'))204 }205 return p206 }207}, {208 nickname: 'è±ç£è¯å',209 appid: 'wx2f9b06c1de1ccfca',210 urlPrefix: 'https://movie.douban.com',211 indexPage: 'pages/index/index',212 // https://movie.douban.com/subject/26794435/?from=showing213 genMPUrl: GenFormatOneMPUrl('subject', 'pages/subject/subject?type=movie&id='),214}, {215 nickname: 'è±ç£è¯å',216 appid: 'wx2f9b06c1de1ccfca',217 urlPrefix: 'https://book.douban.com',218 indexPage: 'pages/index/index',219 // https://book.douban.com/subject/33442274/?icn=index-latestbook-subject220 genMPUrl: GenFormatOneMPUrl('subject', 'pages/subject/subject?type=book&id='),221}, {222 nickname: 'è±ç£è¯å',223 appid: 'wx2f9b06c1de1ccfca',224 urlPrefix: 'https://music.douban.com',225 indexPage: 'pages/index/index',226 // https://music.douban.com/subject/34780472/227 genMPUrl: GenFormatOneMPUrl('subject', 'pages/subject/subject?type=music&id='),228}, {229 nickname: 'è
¾è®¯æ°é»',230 appid: 'wxb10c47503e8c8e01',231 urlPrefix: 'https://new.qq.com',232 indexPage: 'pages/main_page/main_page',233 // https://new.qq.com/omn/TWF20190/TWF2019081200847600.html234 genMPUrl: GenFormatLastPathMPUrl('pages/normal/index?atype=0&id='),235}]236function DefaultGenMPUrl(meta, url) {237 if (url == meta.urlPrefix) {return meta.indexPage}238 return url239}240function isGitHubPage(url) {241 return url.startsWith("https://github.com/") || url.startsWith("http://github.com/")242}243function DefaultIndexMPWithPara(meta, url) {244 var p = url.slice(meta.urlPrefix.length, url.length)245 return meta.indexPage + p246}247function parseGitHub(url) {248 if (!isGitHubPage(url)) {249 return ["", "", ""]250 }251 var arr = url.split('/')252 if (arr.length == 4){253 return [arr[3], "", ""]254 } else if (arr.length == 5) {255 var repo = arr[4]256 if (repo.indexOf('#')) {257 repo = arr[4].split('#')[0]258 }259 return [arr[3], repo, ""]260 } else if (arr.length > 5) {261 var file = url.slice(("https://github.com/" + arr[3] + "/" + arr[4] + "/").length)262 return [arr[3], arr[4], file]263 }264 return ["", "", ""]265}266// url like: <prefix>/xxx/yyy/zzz/<last>.<sufix>267function GenFormatLastPathMPUrl(path) {268 function genMPUrl(meta, url) {269 var idx = url.indexOf(meta.urlPrefix)270 if (idx == -1) {return meta.indexPage }271 var arr = url.split('/')272 var lastpath = arr[arr.length-1].split('.')[0]273 if (lastpath == "") {return meta.indexPage} 274 return path + lastpath275 }276 return genMPUrl277}278// url like: <prefix>/<gap>/<id>, such as: https://zhuanlan.zhihu.com/p/63501230279function GenFormatOneMPUrl(gap, path) {280 function genMPUrl(meta, url) {281 var idx = url.indexOf(meta.urlPrefix)282 if (idx == -1 || url.indexOf('/'+gap+'/') == -1) {return meta.indexPage }283 var arr = url.split('/')284 if (arr.length < 5) { return meta.indexPage }285 var id = arr[4]286 if (id == "") { return meta.indexPage }287 return path + id288 }289 return genMPUrl290}...
index-controller.spec.js
Source:index-controller.spec.js
1const expect = require('chai').expect;2const helper = require('../test-helper');3const links = require('../../app/assets/json/link');4const content = require('../../app/locales/en');5const points = require('../../app/assets/json/points');6const indexPage = helper.indexPage;7describe('Index Controller - Default', () => {8 const expectedPlayer = 'MajorSlackmore';9 it('should display the correct banner image', () =>10 indexPage.visit()11 .then(() => {12 expect(indexPage.bannerImage()).to.contain('/images/glider_rider.png');13 })14 );15 it('should display the correct template', () =>16 indexPage.visit()17 .then(() => {18 expect(indexPage.backgroundStyle()).to.equal('obsidian');19 })20 );21 it('should display the message of the day', () =>22 indexPage.visit()23 .then(() => {24 expect(indexPage.messageOfTheDay()).to.equal('A Minecraft Server');25 })26 );27 it('should display the correct server connection details', () =>28 indexPage.visit()29 .then(() => {30 expect(indexPage.serverDetails()).to.equal('localhost:25565');31 })32 );33 it('should display the correct avatar', () =>34 indexPage.visit()35 .then(() => {36 expect(indexPage.avatar(expectedPlayer)).to.equal('https://minotar.net/avatar/MajorSlackmore/100.png');37 })38 );39 it('should display the correct player name', () =>40 indexPage.visit()41 .then(() => {42 expect(indexPage.player(expectedPlayer)).to.equal(expectedPlayer);43 })44 );45 [46 { name: 'advancement-minecraft-story-root', link: 'minecraft-story', content: ['minecraft', 'story', 'root'] },47 { name: 'advancement-minecraft-story-mine_stone', link: 'minecraft-story', content: ['minecraft', 'story', 'mine_stone'] }48 ]49 .forEach((adv) => {50 it(`should display the advancement ${adv.name}`, () =>51 indexPage.visit()52 .then(() => {53 const advancement = indexPage.advancement(expectedPlayer, adv.name);54 const titleContent =55 content.advancement.title[adv.content[0]][adv.content[1]][adv.content[2]];56 const descriptionContent =57 content.advancement.description[adv.content[0]][adv.content[1]][adv.content[2]];58 expect(advancement.href).to.equal(links[adv.link]);59 expect(advancement.title).to.equal(`${titleContent} : ${descriptionContent}`);60 })61 );62 });63 it('should display the correct score', () =>64 indexPage.visit()65 .then(() => {66 expect(indexPage.score(expectedPlayer)).to.equal('20');67 })68 );69 it('should display the players in the correct order', () =>70 indexPage.visit()71 .then(() => {72 expect(indexPage.playerInPosition(0)).to.equal('MinorSlackmore');73 expect(indexPage.playerInPosition(1)).to.equal('MiniSlackmore');74 expect(indexPage.playerInPosition(2)).to.equal('MajorSlackmore');75 })76 );77});78function getAdvancementDetails() {79 const detailsArray = [];80 const totalAch = Object.keys(points).length;81 for (let i = 0; i < totalAch; i += 1) {82 const rawEntry = Object.keys(points)[i];83 const topic = rawEntry.split(':')[1].split('/')[0];84 const achievement = rawEntry.split(':')[1].split('/')[1];85 const domain = rawEntry.split(':')[0];86 detailsArray.push({ name: `advancement-${domain}-${topic}-${achievement}`, link: `${domain}-${topic}`, content: [`${domain}`, `${topic}`, `${achievement}`] });87 }88 return detailsArray;89}90describe('Index Controller - Default', () => {91 const allAdvancementPlayer = 'MinorSlackmore';92 const advDetails = getAdvancementDetails();93 advDetails.forEach((adv) => {94 it(`should display the advancement ${adv.name}`, () =>95 indexPage.visit()96 .then(() => {97 const advancement = indexPage.advancement(allAdvancementPlayer, adv.name);98 const titleContent =99 content.advancement.title[adv.content[0]][adv.content[1]][adv.content[2]];100 const descriptionContent =101 content.advancement.description[adv.content[0]][adv.content[1]][adv.content[2]];102 expect(advancement.href).to.equal(links[adv.link]);103 expect(advancement.title).to.equal(`${titleContent} : ${descriptionContent}`);104 })105 );106 });107});108describe('Index Controller Stats Only - Default', () => {109 const expectedPlayer = 'MajorSlackmore';110 it('should display the correct avatar', () =>111 indexPage.visitStats()112 .then(() => {113 expect(indexPage.avatar(expectedPlayer)).to.equal('https://minotar.net/avatar/MajorSlackmore/100.png');114 })115 );116 it('should display the correct player name', () =>117 indexPage.visitStats()118 .then(() => {119 expect(indexPage.player(expectedPlayer)).to.equal(expectedPlayer);120 })121 );122 it('should display the correct advancements', () =>123 indexPage.visitStats()124 .then(() => {125 expect(indexPage.advancements(expectedPlayer)).to.contain('minecraft-story-root');126 expect(indexPage.advancements(expectedPlayer)).to.contain('minecraft-story-mine_stone');127 })128 );129 it('should display the correct score', () =>130 indexPage.visitStats()131 .then(() => {132 expect(indexPage.score(expectedPlayer)).to.equal('20');133 })134 );135 it('should display the players in the correct order', () =>136 indexPage.visitStats()137 .then(() => {138 expect(indexPage.playerInPosition(0)).to.equal('MinorSlackmore');139 expect(indexPage.playerInPosition(1)).to.equal('MiniSlackmore');140 expect(indexPage.playerInPosition(2)).to.equal('MajorSlackmore');141 })142 );143});144describe('Index Controller - NoPlayers', () => {145 it('should display Waiting if no players are found', () =>146 indexPage.visit()147 .then(() =>148 expect(indexPage.amWaitingForPlayers()))149 );150});151describe('Index Controller - NoCache', () => {152 it('should still display all players if cache is wrong', () =>153 indexPage.visit()154 .then(() =>155 expect(indexPage.noOfPlayersShown(2)))156 );157 it('should display the correct avatar', () =>158 indexPage.visit()159 .then(() => {160 expect(indexPage.avatar('MajorSlackmore')).to.equal('https://minotar.net/avatar/MajorSlackmore/100.png');161 })162 );163});164describe('Index Controller - NoInternet', () => {165 it('should display the default player name', () =>166 indexPage.visit()167 .then(() => {168 expect(indexPage.player('6eb35f96')).to.equal('6eb35f96');169 })170 );171});172describe('Index Controller - OtherConfig', () => {173 it('should NOT display the server connection details', () =>174 indexPage.visit()175 .then(() => expect(indexPage.serverDetails()).to.be.empty)176 );177 it('should limit the number of displayed players', () =>178 indexPage.visit()179 .then(() => {180 expect(indexPage.playerInPosition(0)).to.equal('MinorSlackmore');181 expect(indexPage.playerInPosition(1)).to.equal(undefined);182 })183 );184 it('should limit the number of displayed players on partial stats reload', () =>185 indexPage.visitStats()186 .then(() => {187 expect(indexPage.playerInPosition(0)).to.equal('MinorSlackmore');188 expect(indexPage.playerInPosition(1)).to.equal(undefined);189 })190 );...
FirstVisitIndexPage.js
Source:FirstVisitIndexPage.js
1/*2 * This file is part of justoverclock/first-visit-indexpage.3 *4 * Copyright (c) 2021 Marco Colia.5 * https://flarum.it6 *7 * For the full copyright and license information, please view the LICENSE.md8 * file that was distributed with this source code.9 */10import app from 'flarum/forum/app';11import Page from 'flarum/components/Page';12import IndexPage from 'flarum/components/IndexPage';13export default class FirstVisitIndexPage extends Page {14 oncreate(vnode) {15 super.oncreate(vnode);16 app.setTitle(app.translator.trans('first-visit-indexpage.forum.app-title'));17 app.setTitleCount(0);18 }19 view() {20 const baseUrl = app.forum.attribute('baseUrl');21 const toHome = '/';22 return m('.IndexPage', [23 IndexPage.prototype.hero(),24 m('.container',25 m('.sideNavContainer', [26 m('.IndexPage-results.sideNavOffset',27 m('div', { className: 'body-post' }, [28 m('section',29 { className: 'timeline-outer', id: 'timeline' },30 m('div',31 { className: 'container', id: 'content' },32 m('div',33 { className: 'row' },34 m('div', { className: 'col s12 m12 l12' }, [35 m('h1',36 { className: 'maintitle-text lighten-1 header' },37 app.translator.trans('first-visit-indexpage.forum.title')38 ),39 m('div',40 { id: 'warningbox' },41 m('div', { id: 'rulesbox' }, [42 m('p', [43 m('i', { className: 'fas fa-exclamation' }),44 m('strong', app.translator.trans('first-visit-indexpage.forum.warning-title')),45 ]),46 m('p', app.translator.trans('first-visit-indexpage.forum.warning-text')),47 ])48 ),49 m('ul', { className: 'timeline' }, [50 m('li', { className: 'event' }, [51 m('h3',52 { id: 'generalRules' },53 app.translator.trans('first-visit-indexpage.forum.general-rules')54 ),55 m('p', app.translator.trans('first-visit-indexpage.forum.general-rules-text')),56 ]),57 m('li', { className: 'event' }, [58 m('h3', { id: 'posting' }, app.translator.trans('first-visit-indexpage.forum.posting-rules')),59 m('p', app.translator.trans('first-visit-indexpage.forum.posting-rules-text')),60 ]),61 m('li', { className: 'event' }, [62 m('h3', { id: 'spam' }, app.translator.trans('first-visit-indexpage.forum.spam')),63 m('p', app.translator.trans('first-visit-indexpage.forum.spam-text')),64 ]),65 m('li', { className: 'event' }, [66 m('h3', { id: 'copyright' }, app.translator.trans('first-visit-indexpage.forum.copyright')),67 m('p', app.translator.trans('first-visit-indexpage.forum.copyright-text')),68 ]),69 m('li', { className: 'event' }, [70 m('h3', { id: 'break' }, app.translator.trans('first-visit-indexpage.forum.rule-break')),71 m('p', app.translator.trans('first-visit-indexpage.forum.rule-break-text')),72 ]),73 ]),74 ])75 )76 )77 ),78 m('div',79 { className: 'outer make-center' },80 m('div',81 { className: 'inner make-center' },82 m('input', { type: 'checkbox', id: 'agreeRules' }),83 app.translator.trans('first-visit-indexpage.forum.accept-rules')84 )85 ),86 m('button',87 {88 className: 'btn btn1',89 id: 'acceptRules',90 onclick: function () {91 if (document.getElementById('agreeRules').checked) {92 m.route.set(toHome);93 } else {94 alert(app.translator.trans('first-visit-indexpage.forum.alert-message'));95 }96 },97 },98 app.translator.trans('first-visit-indexpage.forum.agree-button')99 ),100 ])101 ),102 ])103 ),104 ]);105 }...
index_test.js
Source:index_test.js
1const assert = require('assert')2Feature('Index Page')3Scenario('Shamu is visible', (I, shamu) => {4 I.amOnPage('/')5 I.waitForVisible(shamu.shamuWidgetToggle)6 shamu.hasShamuWidget()7 shamu.hasAttentionGrabberImage()8})9Scenario('Only Have 1 H1 Tag', function * (I, seo) {10 I.amOnPage('/')11 I.waitForVisible(seo.h1Tag)12 const h1Count = yield * seo.getH1TagCount()13 assert.equal(h1Count, 1)14})15Scenario('Images Alt Attributes Not Empty', (I, seo) => {16 I.amOnPage('/')17 I.waitForVisible(seo.imgEl())18 assert.ok(seo.hasImgAlt())19})20Scenario('Meta Description Should Not Be Empty', (I, seo) => {21 I.amOnPage('/')22 I.waitForElement(seo.metaDescription)23 assert.ok(seo.hasContent(seo.metaDescription))24})25Scenario('Meta Keywords Should Not Be Empty', (I, seo) => {26 I.amOnPage('/')27 I.waitForElement(seo.metaKeywords)28 assert.ok(seo.hasContent(seo.metaKeywords))29})30Scenario('Header Should Be Displayed Properly', (I, indexPage) => {31 I.amOnPage('/')32 I.waitForVisible(indexPage.header.logo)33 I.seeElement(indexPage.header.logo)34 I.seeElement(indexPage.header.desktopMenu)35})36Scenario('Header Menu Should Be Displayed Properly', (I, indexPage) => {37 I.amOnPage('/')38 I.waitForVisible(indexPage.header.berandaMenu)39 I.seeElement(indexPage.header.berandaMenu)40 I.seeElement(indexPage.header.fiturMenu)41 I.seeElement(indexPage.header.pricingMenu)42 I.seeElement(indexPage.header.caraKerjaMenu)43 I.seeElement(indexPage.header.ceritaSuksesMenu)44 I.seeElement(indexPage.header.freeTrialButton)45})46Scenario('Section Intro Should Be Displayed Properly', function * (I, indexPage) {47 I.amOnPage('/')48 I.waitForVisible(indexPage.body.intro.intro)49 const descCount = yield * indexPage.getElementCount(indexPage.body.intro.description.css)50 assert.equal(descCount, 1)51 I.seeElement(indexPage.body.intro.intro)52 I.seeElement(indexPage.body.intro.title)53 I.seeElement(indexPage.body.intro.description)54 I.seeElement(indexPage.body.intro.chatButton)55 I.seeElement(indexPage.body.intro.image)56})57Scenario('Section Cara Kerja 1 Should Be Displayed Properly', function * (I, indexPage) {58 I.amOnPage('/')59 I.waitForVisible(indexPage.body.caraKerja1.caraKerja1)60 const descCount = yield * indexPage.getElementCount(indexPage.body.caraKerja1.description.css)61 assert.equal(descCount, 4)62 I.seeElement(indexPage.body.caraKerja1.caraKerja1)63 I.seeElement(indexPage.body.caraKerja1.title)64 I.seeElement(indexPage.body.caraKerja1.description)65 I.seeElement(indexPage.body.caraKerja1.linkStartVideo)66 I.seeElement(indexPage.body.caraKerja1.video)67})68Scenario('Section Cara Kerja 2 Should Be Displayed Properly', function * (I, indexPage) {69 I.amOnPage('/')70 I.waitForVisible(indexPage.body.caraKerja2.caraKerja2)71 const descCount = yield * indexPage.getElementCount(indexPage.body.caraKerja2.description.css)72 assert.equal(descCount, 2)73 I.seeElement(indexPage.body.caraKerja2.caraKerja2)74 I.seeElement(indexPage.body.caraKerja2.title)75 I.seeElement(indexPage.body.caraKerja2.description)76 I.seeElement(indexPage.body.caraKerja2.image)77})78Scenario('Footer Should Be Displayed Properly', (I, indexPage) => {79 I.amOnPage('/')80 I.waitForVisible(indexPage.footer.logo)81 I.seeElement(indexPage.footer.logo)82 I.seeElement(indexPage.footer.copyright)83})84Scenario('Footer Menu Should Be Displayed Properly', (I, indexPage) => {85 I.amOnPage('/')86 I.waitForVisible(indexPage.footer.product)87 I.seeElement(indexPage.footer.product)88 I.seeElement(indexPage.footer.features)89 I.seeElement(indexPage.footer.pricing)90 I.seeElement(indexPage.footer.tutorial)91 I.seeElement(indexPage.footer.developers)92 I.seeElement(indexPage.footer.docs)93 I.seeElement(indexPage.footer.company)94 I.seeElement(indexPage.footer.blog)95 I.seeElement(indexPage.footer.careers)96 I.seeElement(indexPage.footer.legal)97 I.seeElement(indexPage.footer.termOfService)98 I.seeElement(indexPage.footer.privacyPolicy)99 I.seeElement(indexPage.footer.socialMedia.facebook)100 I.seeElement(indexPage.footer.socialMedia.instagram)101 I.seeElement(indexPage.footer.socialMedia.youtube)102 I.seeElement(indexPage.footer.socialMedia.linkedin)...
index.js
Source:index.js
1_.indexPage = {2 banner:{3 navigation: {4 nextEl: '.swiper-button-next',5 prevEl: '.swiper-button-prev',6 },7 },8 bannerSwiper:'#index-swiper',9 scroll:[10 {11 el:'.index-atlas-item-one',12 options:{13 scrollamount:50,14 hoverstop: false15 }16 },17 {18 el:'.index-atlas-item-two',19 options:{20 scrollamount:60,21 hoverstop: false,22 }23 },24 {25 el:'.index-atlas-item-three',26 options:{27 scrollamount:70,28 hoverstop: false29 }30 },31 ],32 top:$('.index-sidebar-scrollTop'),33 video:{34 img:$('.index-about-video-img'),35 button:$('.index-about-video-model'),36 video:$('.index-about-video-el')[0],37 state:0, // 0 æªææ¾ 1æå 2éæ38 state_str:['play','pause','replay']39 },40 i:0,41 count:0,42};43if (!_.mobile) {44 //è§é¢ææ¾45 _.indexPage.video.button.click(function () {46 var state = $(this).attr('data-state') || 0;47 state = parseInt(state);48 if (state == 1){49 _.indexPage.video.video.pause();50 state = 0;51 } else {52 _.indexPage.video.video.play();53 state = 1;54 }55 _.indexPage.setVideoImg(state);56 });57 _.indexPage.setVideoImg = function(index){58 index = index || 0;59 var attrKey = 'data-'+_.indexPage.video.state_str[index];60 _.indexPage.video.img.attr('src',_.indexPage.video.img.attr(attrKey));61 if (index == 1){62 _.indexPage.video.button.addClass('index-about-video-hover');63 }else {64 _.indexPage.video.button.removeClass('index-about-video-hover');65 }66 _.indexPage.video.button.attr('data-state',index);67 };68 _.indexPage.video.video.onended = function(){69 _.indexPage.setVideoImg(2);70 };71}else{72 _.indexPage.video.button.hide();73 _.indexPage.video.video.controls=true;74}75// banner76_.indexPage.bannerSwiper = new Swiper(_.indexPage.bannerSwiper,_.indexPage.banner);77//设置æ è¡æ¥78for (_.indexPage.count=_.indexPage.scroll.length;_.indexPage.i<_.indexPage.count;_.indexPage.i++){79 _.indexPage.width = $(_.indexPage.scroll[_.indexPage.i].el).children('img').length * 380;80 _.indexPage.widthCount = Math.ceil(_.width/_.indexPage.width);81 _.indexPage.html = $(_.indexPage.scroll[_.indexPage.i].el).html();82 83 _.indexPage.j = 0;84 for (;_.indexPage.j<_.indexPage.widthCount;_.indexPage.j++){85 _.indexPage.html+=_.indexPage.html;86 }87 $(_.indexPage.scroll[_.indexPage.i].el).html(_.indexPage.html);88 $(_.indexPage.scroll[_.indexPage.i].el).liMarquee(_.indexPage.scroll[_.indexPage.i].options);89}90//设置è¿å顶é¨91_.indexPage.top.click(function (){92 $('html,body').animate({scrollTop:0},500);...
Authorized.js
Source:Authorized.js
1import React from 'react';2import RenderAuthorized from '@/components/Authorized';3import { getAuthority } from '@/utils/authority';4import Redirect from 'umi/redirect';5import { roles } from '@/../config/routesAuthority.config';6import storage from '@/utils/storage'7const Authority = getAuthority();8const Authorized = RenderAuthorized(Authority);9// æ ¹æ®æé跳转é¦é¡µ10const IndexPage = ({ children, location }) => {11 const userinfo = storage.get("userinfo");12 if(!userinfo){13 return <Redirect to='/user/login' />;14 }15 console.log('location:',location)16 if (location.pathname === '/') {17 let indexPage = '/credit/list'; // é»è®¤ç®¡çåç»è®¡é¡µé¢18 // æ¥çè§è²æ¯å¦é
ç½® index, 并ä¸è®¾ç½® index 页é¢19 getAuthority().forEach(item => {20 console.log('item:00000:',item);21 if(item === 'admin'){22 indexPage = '/organ/list'23 }else if(item === 'creditQuery'){24 indexPage = '/credit/list'25 }else if(item === 'creditAudit'){26 indexPage = '/credit/list'27 }else if(item === 'loanQuery'){28 indexPage = '/loan/list'29 }else if(item === 'loanAudit'){30 indexPage = '/loan/list'31 }else if(item === 'dataSync'){32 indexPage = '/information/list'33 }else{34 indexPage = '/organ/list'35 }36 });37 return <Redirect to={indexPage} />;38 }39 return children;40 // if (location.pathname === '/') {41 // Authority.find42 // return getAuthority().includes('admin') ? (43 // <Redirect to="/credit" />44 // ) : (45 // <Redirect to="/account/center" />46 // );47 // }48 // return children;49};50export default ({ children, ...props }) => (51 <Authorized authority={children.props.route.authority} noMatch={<Redirect to="/user/login" />}>52 <IndexPage {...props}>{children}</IndexPage>53 </Authorized>...
indexpage.js
Source:indexpage.js
1//é¦é¡µæ¥å£2apiRootArray.push(3 {name:'é¦é¡µ',4 id:'indexpage'5 }6);7apiArray.push({8 parentId:'indexpage',9 name:'ç¾å°',10 id:'userSign',11 url:'/indexpage/userSign',12 type:'POST',13 xmlParam:'',14 developer:"å»é¾æ"15},{16 parentId:'indexpage',17 name:'è·åæ¥åæ°æ®',18 id:'getCalendarData',19 url:'/indexpage/getCalendarData',20 type:'POST',21 xmlParam:'',22 developer:"å»é¾æ"23},{24 parentId:'indexpage',25 name:'è·åæ°å¢çé¢ä¿¡æ¯',26 id:'getAddMsg',27 url:'/indexpage/getAddMsg',28 type:'POST',29 xmlParam:'',30 developer:"å»é¾æ"31},{32 parentId:'indexpage',33 name:'è·åæ¯å¦æ交å¼å¸¸æ å¿',34 id:'getExceptionFlag',35 url:'/indexpage/getExceptionFlag',36 type:'POST',37 xmlParam:'',38 developer:"å»é¾æ"39},{40 parentId:'indexpage',41 name:'æ±æ¥å¼å¸¸',42 id:'reportException',43 url:'/indexpage/reportException',44 type:'POST',45 xmlParam:'',46 developer:"å»é¾æ"47},{48 parentId:'indexpage',49 name:'è·åé¦é¡µæ¨èèµæº',50 id:'getRecomendResources',51 url:'/indexpage/getRecomendResources',52 type:'POST',53 xmlParam:'',54 developer:"å»é¾æ"...
main.password.spec.js
Source:main.password.spec.js
23fixture `Left menu password entering`4 .page('http://localhost:5555/');56const indexPage = new IndexPage();78test("enter bad password", async t => {9 await t10 .expect(indexPage.layout.visible).ok()11 .click(indexPage.menu.enterPassword)12 .typeText(indexPage.dialogs.enterPassword.password, "wrong")13 .click(indexPage.dialogs.enterPassword.submit)14 .expect(indexPage.messageBar.text.textContent).contains("Couldn't find a level with password wrong.");15});1617test("cancel password", async t => {18 await t19 .expect(indexPage.layout.visible).ok()20 .click(indexPage.menu.enterPassword)
...
Using AI Code Generation
1describe('My First Test', function() {2 it('Visits the Kitchen Sink', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('h1', 'Welcome to React')4 })5})6describe('My First Test', function() {7 it('Does not do much!', function() {8 cy.contains('h1', 'Welcome to React')9 })10})11describe('My First Test', function() {12 it('Does not do much!', function() {13 cy.contains('h1', 'Welcome to React')14 })15})16describe('My First Test', function() {17 it('Does not do much!', function() {18 cy.contains('h1', 'Welcome to React')19 })20})21describe('My First Test', function() {22 it('Does not do much!', function() {23 cy.contains('h1', 'Welcome to React')24 })25})26describe('My First Test', function() {27 it('Does not do much!', function() {28 cy.contains('h1', 'Welcome to React')29 })30})31describe('My First Test', function() {32 it('Does not do much!', function() {33 cy.contains('h1', 'Welcome to React')34 })35})36describe('My First Test', function() {37 it('Does not do much!', function() {38 cy.contains('h1', 'Welcome to React')39 })40})41describe('My First Test', function() {42 it('Does not do much!', function() {43 cy.contains('h1', 'Welcome to React')44 })45})
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('h1', 'Welcome to Next.js!')4 cy.contains('a', 'Learn More')5 })6})
Using AI Code Generation
1describe('Test Suite', function() {2 it('Test Case', function() {3 cy.get('input[name="q"]').type('Cypress')4 cy.get('input[value="Google Search"]').click()5 })6})7{8 "env": {9 }10}11describe('Test Suite', function() {12 it('Test Case', function() {13 cy.visit('/')14 cy.get('input[name="q"]').type('Cypress')15 cy.get('input[value="Google Search"]').click()16 })17})
Using AI Code Generation
1it('test', () => {2 cy.IndexPage()3})4Cypress.Commands.add('IndexPage', () => {5})6it('test', () => {7 cy.IndexPage()8})9Cypress.Commands.add('IndexPage', () => {10})11it('test', () => {12 cy.IndexPage()13})14Cypress.Commands.add('IndexPage', () => {15})16it('test', () => {17 cy.IndexPage()18})19Cypress.Commands.add('IndexPage', () => {20})21it('test', () => {22 cy.IndexPage()23})24Cypress.Commands.add('IndexPage', () => {25})26it('test', () => {27 cy.IndexPage()28})29Cypress.Commands.add('IndexPage', () => {30})31it('test', () => {32 cy.IndexPage()33})34Cypress.Commands.add('IndexPage', () => {
Using AI Code Generation
1describe('Index page', () => {2 it('should display the index page', () => {3 cy.get('h1').should('have.text', 'Hello World')4 })5})6describe('Index page', () => {7 it('should display the index page', () => {8 cy.visit('/')9 cy.get('h1').should('have.text', 'Hello World')10 })11})12describe('Index page', () => {13 it('should display the index page', () => {14 cy.get('h1').should('have.text', 'Hello World')15 })16})17describe('Index page', () => {18 it('should display the index page', () => {19 cy.get('h1').should('have.text', 'Hello World')20 })21})22describe('Index page', () => {23 it('should display the index page', () => {24 cy.get('h1').should('have.text', 'Hello World')25 })26})27describe('Index page', () => {28 it('should display the index page', () => {29 cy.get('h1').should('have.text', 'Hello World')30 })31})32describe('Index page', () => {33 it('should display the index page', () => {34 cy.get('h1').should('have.text', 'Hello World')35 })36})37describe('Index page', () => {38 it('should display the index page', () => {39 cy.get('h1').should('have.text', 'Hello World')40 })41})42describe('Index page', () => {43 it('should display the index page', () => {
Using AI Code Generation
1import { IndexPage } from 'cypress/support/page-objects/index-page'2const indexPage = new IndexPage()3indexPage.visit()4describe('Index page', () => {5 it('should render correctly', () => {6 indexPage.checkPageTitle()7 })8})9class IndexPage {10 visit() {11 cy.visit('/')12 }13 checkPageTitle() {14 cy.get('h1').should('contain', 'Welcome to the Gatsby Default Starter')15 }16}17export { IndexPage }
Using AI Code Generation
1it('My First Test', function() {2})3describe('My First Test', function() {4 it('Does not do much!', function() {5 expect(true).to.equal(true)6 })7})8describe('My First Test', function() {9 it('Does not do much!', function() {10 expect(true).to.equal(true)11 })12})13describe('My First Test', function() {14 it('Does not do much!', function() {15 expect(true).to.equal(true)16 })17})18describe('My First Test', function() {19 it('Does not do much!', function() {20 expect(true).to.equal(true)21 })22})23describe('My First Test', function() {24 it('Does not do much!', function() {25 expect(true).to.equal(true)26 })27})28describe('My First Test', function() {29 it('Does not do much!', function() {30 expect(true).to.equal(true)31 })32})33describe('My First Test', function() {34 it('Does not do much!', function() {35 expect(true).to.equal(true)36 })37})38describe('My First Test', function() {39 it('Does not do much!', function() {40 expect(true).to.equal(true)41 })42})43describe('My First Test', function() {44 it('
Using AI Code Generation
1Cypress.IndexPage()2Cypress.IndexPage().clickSignIn()3var IndexPage = function () {4 this.signInButton = element(by.css('[ng-click="login()"]'))5 this.signIn = function () {6 this.signInButton.click()7 }8}9Cypress.IndexPage().signInButton.click()10Cypress.IndexPage().signIn()11var IndexPage = function () {12 this.signInButton = element(by.css('[ng-click="login()"]'))13 this.signIn = function () {14 this.signInButton.click()15 }16}17module.exports = new IndexPage()18Cypress.IndexPage()19Cypress.IndexPage().signInButton.click()20Cypress.IndexPage().signIn()21Cypress.IndexPage()22Cypress.IndexPage().signInButton.click()
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!