2017-12-22 07:01:12 -05:00
|
|
|
describe QA::Page::Base do
|
|
|
|
describe 'page helpers' do
|
|
|
|
it 'exposes helpful page helpers' do
|
|
|
|
expect(subject).to respond_to :refresh, :wait, :scroll_to
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-22 09:40:46 -05:00
|
|
|
describe '.view', 'DSL for defining view partials' do
|
2017-12-22 07:01:12 -05:00
|
|
|
subject do
|
|
|
|
Class.new(described_class) do
|
|
|
|
view 'path/to/some/view.html.haml' do
|
|
|
|
element :something, 'string pattern'
|
|
|
|
element :something_else, /regexp pattern/
|
|
|
|
end
|
|
|
|
|
|
|
|
view 'path/to/some/_partial.html.haml' do
|
2018-02-16 06:00:13 -05:00
|
|
|
element :another_element, 'string pattern'
|
2017-12-22 07:01:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes it possible to define page views' do
|
|
|
|
expect(subject.views.size).to eq 2
|
|
|
|
expect(subject.views).to all(be_an_instance_of QA::Page::View)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'populates views objects with data about elements' do
|
2018-02-16 06:00:13 -05:00
|
|
|
expect(subject.elements.size).to eq 3
|
|
|
|
expect(subject.elements).to all(be_an_instance_of QA::Page::Element)
|
|
|
|
expect(subject.elements.map(&:name))
|
|
|
|
.to eq [:something, :something_else, :another_element]
|
2017-12-22 07:01:12 -05:00
|
|
|
end
|
|
|
|
end
|
2017-12-22 09:40:46 -05:00
|
|
|
|
|
|
|
describe '.errors' do
|
|
|
|
let(:view) { double('view') }
|
|
|
|
|
2018-01-09 06:06:58 -05:00
|
|
|
context 'when page has views and elements defined' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:views)
|
|
|
|
.and_return([view])
|
2017-12-22 09:40:46 -05:00
|
|
|
|
2018-01-09 06:06:58 -05:00
|
|
|
allow(view).to receive(:errors).and_return(['some error'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'iterates views composite and returns errors' do
|
|
|
|
expect(described_class.errors).to eq ['some error']
|
|
|
|
end
|
2017-12-22 09:40:46 -05:00
|
|
|
end
|
|
|
|
|
2018-01-09 06:06:58 -05:00
|
|
|
context 'when page has no views and elements defined' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:views).and_return([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends an error about missing views / elements block' do
|
|
|
|
expect(described_class.errors)
|
2018-01-09 06:34:47 -05:00
|
|
|
.to include 'Page class does not have views / elements defined!'
|
2018-01-09 06:06:58 -05:00
|
|
|
end
|
2017-12-22 09:40:46 -05:00
|
|
|
end
|
|
|
|
end
|
2017-12-22 07:01:12 -05:00
|
|
|
end
|