| [9af201e] | 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | const assert = require( 'assert' )
|
|---|
| 4 | const data = require( './data' )
|
|---|
| 5 | const implementation = require( './implementation' )
|
|---|
| 6 | const baseAdapter = require( '../' )
|
|---|
| 7 |
|
|---|
| 8 | const adapter = baseAdapter( implementation )
|
|---|
| 9 |
|
|---|
| 10 | const getById = id => adapter.findOne(
|
|---|
| 11 | node => adapter.getAttributeValue( node, 'id' ) === id,
|
|---|
| 12 | data
|
|---|
| 13 | )
|
|---|
| 14 |
|
|---|
| 15 | const getByName = name => adapter.findAll(
|
|---|
| 16 | node => adapter.getName( node ) === name,
|
|---|
| 17 | data
|
|---|
| 18 | )
|
|---|
| 19 |
|
|---|
| 20 | const getByClass = className => adapter.findAll(
|
|---|
| 21 | node => adapter.getAttributeValue( node, 'class' ) === className,
|
|---|
| 22 | data
|
|---|
| 23 | )
|
|---|
| 24 |
|
|---|
| 25 | const existsName = name => adapter.existsOne(
|
|---|
| 26 | node => adapter.getName( node ) === name,
|
|---|
| 27 | data
|
|---|
| 28 | )
|
|---|
| 29 |
|
|---|
| 30 | const container = getById( 'container' )
|
|---|
| 31 | const strong = getByName( 'strong' )[ 0 ]
|
|---|
| 32 | const hello = strong.children[ 0 ]
|
|---|
| 33 | const world = container.children[ 1 ]
|
|---|
| 34 |
|
|---|
| 35 | describe( 'css-select-base-adapter', () => {
|
|---|
| 36 | it( 'getAttributeValue', () => {
|
|---|
| 37 | assert( container )
|
|---|
| 38 | })
|
|---|
| 39 |
|
|---|
| 40 | it( 'getName', () => {
|
|---|
| 41 | assert( strong )
|
|---|
| 42 | })
|
|---|
| 43 |
|
|---|
| 44 | it( 'findOne', () => {
|
|---|
| 45 | assert( container )
|
|---|
| 46 | })
|
|---|
| 47 |
|
|---|
| 48 | it( 'findAll', () => {
|
|---|
| 49 | const messages = getByClass( 'message' )
|
|---|
| 50 |
|
|---|
| 51 | assert.equal( messages.length, 2 )
|
|---|
| 52 | assert.equal( messages[ 0 ], container )
|
|---|
| 53 | assert.equal( messages[ 1 ], strong )
|
|---|
| 54 | })
|
|---|
| 55 |
|
|---|
| 56 | it( 'getParent', () => {
|
|---|
| 57 | const parent = adapter.getParent( strong )
|
|---|
| 58 |
|
|---|
| 59 | assert.equal( parent, container )
|
|---|
| 60 | })
|
|---|
| 61 |
|
|---|
| 62 | it( 'getSiblings', () => {
|
|---|
| 63 | const siblings = adapter.getSiblings( strong )
|
|---|
| 64 |
|
|---|
| 65 | assert.equal( siblings[ 0 ], strong )
|
|---|
| 66 | assert.equal( siblings[ 1 ], world )
|
|---|
| 67 | })
|
|---|
| 68 |
|
|---|
| 69 | it( 'getChildren', () => {
|
|---|
| 70 | const children = adapter.getChildren( container )
|
|---|
| 71 |
|
|---|
| 72 | assert.equal( children[ 0 ], strong )
|
|---|
| 73 | })
|
|---|
| 74 |
|
|---|
| 75 | it( 'getText', () => {
|
|---|
| 76 | const text = adapter.getText( container )
|
|---|
| 77 |
|
|---|
| 78 | assert.equal( text, 'Hello, World!' )
|
|---|
| 79 | })
|
|---|
| 80 |
|
|---|
| 81 | it( 'isTag', () => {
|
|---|
| 82 | assert( adapter.isTag( container ) )
|
|---|
| 83 | assert( adapter.isTag( strong ) )
|
|---|
| 84 | assert( !adapter.isTag( hello ) )
|
|---|
| 85 | })
|
|---|
| 86 |
|
|---|
| 87 | it( 'hasAttrib', () => {
|
|---|
| 88 | assert( adapter.hasAttrib( container, 'id' ) )
|
|---|
| 89 | assert( !adapter.hasAttrib( strong, 'id' ) )
|
|---|
| 90 | })
|
|---|
| 91 |
|
|---|
| 92 | it( 'existsOne', () => {
|
|---|
| 93 | assert( existsName( 'strong' ) )
|
|---|
| 94 | assert( !existsName( 'blink' ) )
|
|---|
| 95 | })
|
|---|
| 96 |
|
|---|
| 97 | it( 'removeSubsets', () => {
|
|---|
| 98 | const removed = adapter.removeSubsets([ container, strong, container ])
|
|---|
| 99 |
|
|---|
| 100 | assert.equal( removed.length, 1 )
|
|---|
| 101 | assert.equal( removed[ 0 ], container )
|
|---|
| 102 | })
|
|---|
| 103 | })
|
|---|