github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/wats/test/dashboard.js (about) 1 import test from 'ava'; 2 import Fly from '../helpers/fly' 3 import Web from '../helpers/web' 4 import puppeteer from 'puppeteer'; 5 6 const Suite = require('../helpers/suite'); 7 8 const color = require('color'); 9 const palette = require('../helpers/palette'); 10 11 test.beforeEach(async t => { 12 t.context = new Suite(); 13 await t.context.init(t); 14 }); 15 16 test.afterEach(async t => { 17 t.context.passed(t); 18 }); 19 20 test.afterEach.always(async t => { 21 await t.context.finish(t); 22 }); 23 24 test('does not show team name when unauthenticated and team has no exposed pipelines', async t => { 25 t.context.web = await Web.build(t.context.url) 26 await t.context.web.page.goto(t.context.web.route('/')); 27 28 const group = `.dashboard-team-group[data-team-name="main"]`; 29 const element = await t.context.web.page.$(group); 30 31 t.falsy(element); 32 }) 33 34 test('does not show team name when user is logged in another non-main team and has no exposed pipelines', async t => { 35 await t.context.fly.run('set-pipeline -n -p some-pipeline -c fixtures/states-pipeline.yml'); 36 await t.context.fly.run('login -n ' + t.context.guestTeamName + ' -u '+ t.context.guestUsername +' -p ' + t.context.guestPassword); 37 await t.context.fly.run('set-pipeline -n -p non-main-pipeline -c fixtures/states-pipeline.yml'); 38 39 let web = await Web.build(t.context.url, t.context.guestUsername, t.context.guestPassword); 40 await web.login(t); 41 await web.page.goto(web.route('/')); 42 const myGroup = `.dashboard-team-group[data-team-name="${t.context.guestTeamName}"]`; 43 const otherGroup = `.dashboard-team-group[data-team-name="${t.context.teamName}"]`; 44 await web.page.waitFor(myGroup); 45 const element = await web.page.$(otherGroup); 46 t.falsy(element); 47 }) 48 49 test('shows pipelines in their correct order', async t => { 50 let pipelineOrder = ['first', 'second', 'third', 'fourth', 'fifth']; 51 52 for (var i = 0; i < pipelineOrder.length; i++) { 53 let name = pipelineOrder[i]; 54 await t.context.fly.run(`set-pipeline -n -p ${name} -c fixtures/states-pipeline.yml`); 55 } 56 57 await t.context.web.page.goto(t.context.web.route('/')); 58 59 const group = `.dashboard-team-group[data-team-name="${t.context.teamName}"]`; 60 await t.context.web.scrollIntoView(group); 61 await t.context.web.page.waitFor(`${group} .pipeline-wrapper:nth-child(${pipelineOrder.length}) .card`); 62 63 const names = await t.context.web.page.$$eval(`${group} .dashboard-pipeline-name`, nameElements => { 64 var names = []; 65 nameElements.forEach(e => names.push(e.innerText)); 66 return names; 67 }); 68 69 t.deepEqual(names, pipelineOrder); 70 }); 71 72 test('auto-refreshes to reflect state changes', async t => { 73 await t.context.fly.run('set-pipeline -n -p some-pipeline -c fixtures/states-pipeline.yml'); 74 await t.context.fly.run('unpause-pipeline -p some-pipeline'); 75 76 await t.context.fly.run("trigger-job -w -j some-pipeline/passing"); 77 78 await t.context.web.page.goto(t.context.web.route('/')); 79 80 const group = `.dashboard-team-group[data-team-name="${t.context.teamName}"]`; 81 await t.context.web.scrollIntoView(group); 82 await t.context.web.page.waitFor(`${group} .card`); 83 const pipeline = await t.context.web.page.$(`${group} .card`); 84 const text = await t.context.web.text(pipeline); 85 86 const bannerSelector = `${group} .banner`; 87 88 await t.context.web.waitForBackgroundColor(bannerSelector, palette.green); 89 90 await t.throwsAsync(async () => await t.context.fly.run("trigger-job -w -j some-pipeline/failing")); 91 92 await t.context.web.waitForBackgroundColor(bannerSelector, palette.red); 93 }); 94 95 test('picks up cluster name from configuration', async t => { 96 await t.context.web.page.goto(t.context.web.route('/')); 97 98 const clusterNameSelector = `#top-bar-app > div:nth-child(1)`; 99 await t.context.web.page.waitFor(({selector}) => { 100 return document.querySelector(selector).innerText.length > 0; 101 }, {timeout: 10000}, { 102 selector: clusterNameSelector, 103 }); 104 105 const clusterName = await t.context.web.page.$eval(clusterNameSelector, el => el.innerText); 106 107 t.is(clusterName, 'dev'); 108 });