|
| 1 | +import { expect } from 'chai' |
| 2 | +import DataTable from '../../../lib/data/table.js' |
| 3 | + |
| 4 | +describe('Data-driven Before/After hooks - data structure', () => { |
| 5 | + it('should create DataTable with correct structure', () => { |
| 6 | + const accounts = new DataTable(['login', 'password']) |
| 7 | + accounts.add(['davert', '123456']) |
| 8 | + accounts.add(['admin', '654321']) |
| 9 | + |
| 10 | + expect(accounts.rows).to.have.lengthOf(2) |
| 11 | + expect(accounts.array).to.deep.equal(['login', 'password']) |
| 12 | + }) |
| 13 | + |
| 14 | + it('should have rows property with data and skip', () => { |
| 15 | + const accounts = new DataTable(['login', 'password']) |
| 16 | + accounts.add(['davert', '123456']) |
| 17 | + |
| 18 | + accounts.rows.forEach(row => { |
| 19 | + expect(row).to.have.property('data') |
| 20 | + expect(row).to.have.property('skip') |
| 21 | + expect(row.data).to.include.keys(['login', 'password']) |
| 22 | + }) |
| 23 | + }) |
| 24 | + |
| 25 | + it('first row should have correct data', () => { |
| 26 | + const accounts = new DataTable(['login', 'password']) |
| 27 | + accounts.add(['davert', '123456']) |
| 28 | + accounts.add(['admin', '654321']) |
| 29 | + |
| 30 | + const firstRow = accounts.rows[0] |
| 31 | + expect(firstRow.data.login).to.equal('davert') |
| 32 | + expect(firstRow.data.password).to.equal('123456') |
| 33 | + }) |
| 34 | + |
| 35 | + it('second row should have correct data', () => { |
| 36 | + const accounts = new DataTable(['login', 'password']) |
| 37 | + accounts.add(['davert', '123456']) |
| 38 | + accounts.add(['admin', '654321']) |
| 39 | + |
| 40 | + const secondRow = accounts.rows[1] |
| 41 | + expect(secondRow.data.login).to.equal('admin') |
| 42 | + expect(secondRow.data.password).to.equal('654321') |
| 43 | + }) |
| 44 | + |
| 45 | + it('should support filtering skipped rows', () => { |
| 46 | + const accounts = new DataTable(['login', 'password']) |
| 47 | + accounts.add(['davert', '123456']) |
| 48 | + accounts.add(['admin', '654321']) |
| 49 | + |
| 50 | + const activeRows = accounts.rows.filter(row => !row.skip) |
| 51 | + expect(activeRows).to.have.lengthOf(2) |
| 52 | + }) |
| 53 | + |
| 54 | + it('should extract current from row data', () => { |
| 55 | + const accounts = new DataTable(['login', 'password']) |
| 56 | + accounts.add(['davert', '123456']) |
| 57 | + |
| 58 | + const row = accounts.rows[0] |
| 59 | + const current = row.data |
| 60 | + |
| 61 | + expect(current.login).to.equal('davert') |
| 62 | + expect(current.password).to.equal('123456') |
| 63 | + }) |
| 64 | + |
| 65 | + it('should support iterating all rows', () => { |
| 66 | + const accounts = new DataTable(['login', 'password']) |
| 67 | + accounts.add(['davert', '123456']) |
| 68 | + accounts.add(['admin', '654321']) |
| 69 | + |
| 70 | + const currentValues = accounts.rows.map(row => row.data) |
| 71 | + expect(currentValues).to.have.lengthOf(2) |
| 72 | + expect(currentValues[0].login).to.equal('davert') |
| 73 | + expect(currentValues[1].login).to.equal('admin') |
| 74 | + }) |
| 75 | + |
| 76 | + it('should detect when row is skipped', () => { |
| 77 | + const accounts = new DataTable(['login', 'password']) |
| 78 | + accounts.add(['davert', '123456']) |
| 79 | + |
| 80 | + const firstRow = accounts.rows[0] |
| 81 | + expect(firstRow.skip).to.be.false |
| 82 | + }) |
| 83 | +}) |
0 commit comments