mirror of https://github.com/01-edu/public.git
4 changed files with 127 additions and 164 deletions
@ -1,169 +1,132 @@ |
|||||||
import { deepStrictEqual } from 'assert' |
import { people } from './subjects/get-them-all/data.js' |
||||||
import puppeteer from 'puppeteer-core' |
|
||||||
import people from '../assets/data/get-them-all.js' |
const getIds = predicate => |
||||||
|
people |
||||||
const config = { |
.filter(predicate) |
||||||
headless: false, |
.map(e => e.id) |
||||||
executablePath: |
.sort((a, b) => a.localeCompare(b)) |
||||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', |
|
||||||
} |
const architects = getIds(p => p.tag === 'a') |
||||||
|
const notArchitects = getIds(p => p.tag !== 'a') |
||||||
const browser = await puppeteer.launch(config) |
|
||||||
const [page] = await browser.pages() |
const classical = getIds(p => p.classe === 'classical') |
||||||
await page.goto('http://localhost:8000/dom-js/get-them-all/') |
const notClassical = getIds(p => p.tag === 'a' && p.classe !== 'classical') |
||||||
|
|
||||||
const architects = people |
const active = getIds(p => p.classe === 'classical' && p.active) |
||||||
.filter((p) => p.tag === 'a') |
const notActive = getIds( |
||||||
.map((e) => e.id) |
p => p.tag === 'a' && p.classe === 'classical' && p.active === false, |
||||||
.sort((a, b) => a.localeCompare(b)) |
) |
||||||
|
|
||||||
const notArchitects = people |
const bonanno = people.find(p => p.id === 'BonannoPisano').id |
||||||
.filter((p) => p.tag !== 'a') |
const notBonanno = getIds( |
||||||
.map((e) => e.id) |
p => |
||||||
.sort((a, b) => a.localeCompare(b)) |
p.tag === 'a' && |
||||||
|
p.classe === 'classical' && |
||||||
const checkArchitects = async () => { |
p.active && |
||||||
|
p.id !== 'BonannoPisano', |
||||||
|
) |
||||||
|
|
||||||
|
export const tests = [] |
||||||
|
|
||||||
|
tests.push(async ({ eq, page }) => { |
||||||
|
// get architects
|
||||||
const btnArchitect = await page.$(`#btnArchitect`) |
const btnArchitect = await page.$(`#btnArchitect`) |
||||||
btnArchitect.click() |
btnArchitect.click() |
||||||
await page.waitFor(500) |
await page.waitFor(500) |
||||||
|
|
||||||
const selected = await page.$$eval('a', (nodes) => |
const selected = await page.$$eval('a', nodes => |
||||||
nodes |
nodes |
||||||
.filter((node) => node.textContent === 'Architect') |
.filter(node => node.textContent === 'Architect') |
||||||
.map((node) => node.id) |
.map(node => node.id) |
||||||
.sort((a, b) => a.localeCompare(b)), |
.sort((a, b) => a.localeCompare(b)), |
||||||
) |
) |
||||||
|
|
||||||
const eliminated = await page.$$eval('span', (nodes) => |
eq(selected, architects) |
||||||
|
|
||||||
|
const eliminated = await page.$$eval('span', nodes => |
||||||
nodes |
nodes |
||||||
.filter((node) => node.style.opacity === '0.2') |
.filter(node => node.style.opacity === '0.2') |
||||||
.map((node) => node.id) |
.map(node => node.id) |
||||||
.sort((a, b) => a.localeCompare(b)), |
.sort((a, b) => a.localeCompare(b)), |
||||||
) |
) |
||||||
|
|
||||||
deepStrictEqual(`architects: ${selected}`, `architects: ${architects}`) |
eq(eliminated, notArchitects) |
||||||
deepStrictEqual( |
|
||||||
`not architects: ${eliminated}`, |
|
||||||
`not architects: ${notArchitects}`, |
|
||||||
) |
|
||||||
} |
|
||||||
|
|
||||||
checkArchitects() |
|
||||||
await page.waitFor(1000) |
|
||||||
|
|
||||||
// get classical
|
|
||||||
const classical = people |
|
||||||
.filter((p) => p.classe === 'classical') |
|
||||||
.map((e) => e.id) |
|
||||||
.sort((a, b) => a.localeCompare(b)) |
|
||||||
|
|
||||||
const notClassical = people |
await page.waitFor(1000) |
||||||
.filter((p) => p.tag === 'a' && p.classe !== 'classical') |
}) |
||||||
.map((e) => e.id) |
|
||||||
.sort((a, b) => a.localeCompare(b)) |
|
||||||
|
|
||||||
const checkClassical = async () => { |
tests.push(async ({ page, eq }) => { |
||||||
|
// get classical
|
||||||
const btnClassical = await page.$(`#btnClassical`) |
const btnClassical = await page.$(`#btnClassical`) |
||||||
btnClassical.click() |
btnClassical.click() |
||||||
await page.waitFor(500) |
await page.waitFor(500) |
||||||
|
|
||||||
const selected = await page.$$eval('.classical', (nodes) => |
const selected = await page.$$eval('.classical', nodes => |
||||||
nodes |
nodes |
||||||
.filter((node) => node.textContent === 'Classical') |
.filter(node => node.textContent === 'Classical') |
||||||
.map((node) => node.id) |
.map(node => node.id) |
||||||
.sort((a, b) => a.localeCompare(b)), |
.sort((a, b) => a.localeCompare(b)), |
||||||
) |
) |
||||||
|
|
||||||
const eliminated = await page.$$eval('a:not(.classical)', (nodes) => |
eq(selected, classical) |
||||||
|
|
||||||
|
const eliminated = await page.$$eval('a:not(.classical)', nodes => |
||||||
nodes |
nodes |
||||||
.filter((node) => node.style.opacity === '0.2') |
.filter(node => node.style.opacity === '0.2') |
||||||
.map((node) => node.id) |
.map(node => node.id) |
||||||
.sort((a, b) => a.localeCompare(b)), |
.sort((a, b) => a.localeCompare(b)), |
||||||
) |
) |
||||||
|
|
||||||
deepStrictEqual(`classical: ${selected}`, `classical: ${classical}`) |
eq(eliminated, notClassical) |
||||||
deepStrictEqual( |
|
||||||
`not classical: ${eliminated}`, |
|
||||||
`not classical: ${notClassical}`, |
|
||||||
) |
|
||||||
} |
|
||||||
|
|
||||||
checkClassical() |
|
||||||
await page.waitFor(1000) |
|
||||||
|
|
||||||
// get active
|
await page.waitFor(1000) |
||||||
const active = people |
}) |
||||||
.filter((p) => p.classe === 'classical' && p.active) |
|
||||||
.map((e) => e.id) |
|
||||||
.sort((a, b) => a.localeCompare(b)) |
|
||||||
|
|
||||||
const notActive = people |
tests.push(async ({ page, eq }) => { |
||||||
.filter( |
// check active
|
||||||
(p) => p.tag === 'a' && p.classe === 'classical' && p.active === false, |
|
||||||
) |
|
||||||
.map((e) => e.id) |
|
||||||
.sort((a, b) => a.localeCompare(b)) |
|
||||||
|
|
||||||
const checkActive = async () => { |
|
||||||
const btnActive = await page.$(`#btnActive`) |
const btnActive = await page.$(`#btnActive`) |
||||||
btnActive.click() |
btnActive.click() |
||||||
await page.waitFor(500) |
await page.waitFor(500) |
||||||
|
|
||||||
const selected = await page.$$eval('.classical.active', (nodes) => |
const selected = await page.$$eval('.classical.active', nodes => |
||||||
nodes |
nodes |
||||||
.filter((node) => node.textContent === 'Active') |
.filter(node => node.textContent === 'Active') |
||||||
.map((node) => node.id) |
.map(node => node.id) |
||||||
.sort((a, b) => a.localeCompare(b)), |
.sort((a, b) => a.localeCompare(b)), |
||||||
) |
) |
||||||
|
eq(selected, active) |
||||||
|
|
||||||
const eliminated = await page.$$eval('.classical:not(.active)', (nodes) => |
const eliminated = await page.$$eval('.classical:not(.active)', nodes => |
||||||
nodes |
nodes |
||||||
.filter((node) => node.style.opacity === '0.2') |
.filter(node => node.style.opacity === '0.2') |
||||||
.map((node) => node.id) |
.map(node => node.id) |
||||||
.sort((a, b) => a.localeCompare(b)), |
.sort((a, b) => a.localeCompare(b)), |
||||||
) |
) |
||||||
|
|
||||||
deepStrictEqual(`active: ${selected}`, `active: ${active}`) |
eq(eliminated, notActive) |
||||||
deepStrictEqual(`not active: ${eliminated}`, `not active: ${notActive}`) |
await page.waitFor(1000) |
||||||
} |
}) |
||||||
|
|
||||||
checkActive() |
|
||||||
await page.waitFor(1000) |
|
||||||
|
|
||||||
// get bonanno
|
tests.push(async ({ page, eq }) => { |
||||||
const bonanno = people.find((p) => p.id === 'BonannoPisano').id |
// get bonanno
|
||||||
|
|
||||||
const notBonanno = people |
|
||||||
.filter( |
|
||||||
(p) => |
|
||||||
p.tag === 'a' && |
|
||||||
p.classe === 'classical' && |
|
||||||
p.active && |
|
||||||
p.id !== 'BonannoPisano', |
|
||||||
) |
|
||||||
.map((e) => e.id) |
|
||||||
.sort((a, b) => a.localeCompare(b)) |
|
||||||
|
|
||||||
const checkBonanno = async () => { |
|
||||||
const btnBonanno = await page.$(`#btnBonanno`) |
const btnBonanno = await page.$(`#btnBonanno`) |
||||||
btnBonanno.click() |
btnBonanno.click() |
||||||
await page.waitFor(500) |
await page.waitFor(500) |
||||||
|
|
||||||
const selected = await page.$eval('#BonannoPisano', (node) => { |
const selected = await page.$eval('#BonannoPisano', node => { |
||||||
if (node.textContent === 'Bonanno Pisano') return node.id |
if (node.textContent === 'Bonanno Pisano') return node.id |
||||||
}) |
}) |
||||||
|
|
||||||
|
eq(`bonanno: ${selected}`, `bonanno: ${bonanno}`) |
||||||
|
|
||||||
const eliminated = await page.$$eval( |
const eliminated = await page.$$eval( |
||||||
'a.classical.active:not(#BonannoPisano)', |
'a.classical.active:not(#BonannoPisano)', |
||||||
(nodes) => |
nodes => |
||||||
nodes |
nodes |
||||||
.filter((node) => node.style.opacity === '0.2') |
.filter(node => node.style.opacity === '0.2') |
||||||
.map((node) => node.id) |
.map(node => node.id) |
||||||
.sort((a, b) => a.localeCompare(b)), |
.sort((a, b) => a.localeCompare(b)), |
||||||
) |
) |
||||||
|
|
||||||
deepStrictEqual(`bonanno: ${selected}`, `bonanno: ${bonanno}`) |
eq(eliminated, notBonanno) |
||||||
deepStrictEqual(`not bonanno: ${eliminated}`, `not bonanno: ${notBonanno}`) |
}) |
||||||
} |
|
||||||
|
|
||||||
checkBonanno() |
|
||||||
|
@ -0,0 +1,47 @@ |
|||||||
|
export const people = [ |
||||||
|
{ id: 'LolaDunam', tag: 'span', classe: 'modern', active: false }, |
||||||
|
{ id: 'LeeMarley', tag: 'span', classe: 'baroque', active: false }, |
||||||
|
{ id: 'JeanDujardin', tag: 'a', classe: 'classical', active: true }, |
||||||
|
{ id: 'MarloStanfield', tag: 'span', classe: 'modern', active: false }, |
||||||
|
{ id: 'GeorgesDrumond', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'JuliaWhite', tag: 'span', classe: 'modern', active: true }, |
||||||
|
{ id: 'BarneyLeberre', tag: 'span', classe: 'modern', active: true }, |
||||||
|
{ id: 'DavidCarretta', tag: 'a', classe: 'classical', active: false }, |
||||||
|
{ id: 'AugustoCesar', tag: 'span', classe: 'modern', active: true }, |
||||||
|
{ id: 'DavidGuetta', tag: 'a', classe: 'modern', active: false }, |
||||||
|
{ id: 'MarlonBrando', tag: 'a', classe: 'classical', active: false }, |
||||||
|
{ id: 'BonannoPisano', tag: 'a', classe: 'classical', active: true }, |
||||||
|
{ id: 'AvonBarksdale', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'BarackObama', tag: 'span', classe: 'baroque', active: false }, |
||||||
|
{ id: 'MarcDupont', tag: 'span', classe: 'modern', active: false }, |
||||||
|
{ id: 'BillieElliott', tag: 'a', classe: 'baroque', active: true }, |
||||||
|
{ id: 'MariaCallas', tag: 'a', classe: 'baroque', active: false }, |
||||||
|
{ id: 'SteveJobbs', tag: 'a', classe: 'classical', active: false }, |
||||||
|
{ id: 'JoeLee', tag: 'span', classe: 'baroque', active: false }, |
||||||
|
{ id: 'AnthonyGrant', tag: 'span', classe: 'baroque', active: false }, |
||||||
|
{ id: 'ShakimaGreggs', tag: 'a', classe: 'modern', active: true }, |
||||||
|
{ id: 'RoyDeere', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'BobTurner', tag: 'a', classe: 'classical', active: true }, |
||||||
|
{ id: 'AngeloCapri', tag: 'span', classe: 'modern', active: false }, |
||||||
|
{ id: 'SamMcDonald', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'FannyLelouche', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'ClarkLoister', tag: 'a', classe: 'classical', active: false }, |
||||||
|
{ id: 'FinanObrien', tag: 'span', classe: 'modern', active: false }, |
||||||
|
{ id: 'ClariceSterling', tag: 'a', classe: 'modern', active: true }, |
||||||
|
{ id: 'JayHernan', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'HelenMirren', tag: 'a', classe: 'classical', active: false }, |
||||||
|
{ id: 'SarahForestier', tag: 'a', classe: 'modern', active: false }, |
||||||
|
{ id: 'JacquesChirac', tag: 'a', classe: 'classical', active: true }, |
||||||
|
{ id: 'MartinWealer', tag: 'a', classe: 'baroque', active: true }, |
||||||
|
{ id: 'JodieFoster', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'JeanJacques', tag: 'span', classe: 'modern', active: false }, |
||||||
|
{ id: 'MollyHeart', tag: 'a', classe: 'baroque', active: false }, |
||||||
|
{ id: 'FabioSalso', tag: 'a', classe: 'classical', active: true }, |
||||||
|
{ id: 'CarlosSanchez', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'RussellBell', tag: 'a', classe: 'classical', active: false }, |
||||||
|
{ id: 'JackDoe', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'EricCarver', tag: 'a', classe: 'classical', active: false }, |
||||||
|
{ id: 'LouisDeschamps', tag: 'span', classe: 'baroque', active: true }, |
||||||
|
{ id: 'HoracioCane', tag: 'a', classe: 'baroque', active: true }, |
||||||
|
{ id: 'HenryBright', tag: 'a', classe: 'baroque', active: true }, |
||||||
|
] |
Loading…
Reference in new issue