Sha256: 13db372a1abb9c1aa723208d1ce27e1972f501a66a2fbc389ae36527603a1b78

Contents?: true

Size: 1.74 KB

Versions: 6

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'

describe Inesita::Router do
  let(:element) { Inesita::Browser::Document.JS.createElement('div') }
  let(:wrong_router) { Class.new { include Inesita::Router } }
  let(:empty_router) { Class.new { include Inesita::Router; def routes; end } }
  let(:router) do
    Class.new do
      include Inesita::Router

      class TestComponent
        include Inesita::Component

        def render
          div { "test" }
        end
      end

      class OtherTestComponent
        include Inesita::Component

        def render
          div { "other" }
        end
      end

      def routes
        route '/', to: TestComponent
        route '/other', to: OtherTestComponent
      end
    end
  end

  it 'should fail without routes' do
    expect { wrong_router.new.mount_to(element) }.to raise_error Inesita::Error
  end

  it 'should fail with empty routes' do
    expect { empty_router.new }.to raise_error Inesita::Error
  end

  it 'should not fail with routes' do
    expect { router.new }.not_to raise_error
  end

  describe '#url_for' do
    it 'should return url for component name' do
      expect(router.new.url_for(:test_component)).to eq '/'
    end

    it 'should return url for component name' do
      expect(router.new.url_for(:other_test_component)).to eq '/other'
    end

    it 'should fail when no route for component' do
      expect { router.new.url_for(:nothing) }.to raise_error Inesita::Error
    end
  end

  describe '#current_url?' do
    it 'should return true for current url' do
      expect(router.mount_to(element).current_url?(:test_component)).to eq true
    end

    it 'should return false for current url' do
      expect(router.mount_to(element).current_url?(:other_test_component)).to eq false
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inesita-router-0.4.0.pre.2 spec/router_spec.rb
inesita-router-0.4.0.pre.1 spec/router_spec.rb
inesita-router-0.3.0 spec/router_spec.rb
inesita-router-0.2.1 spec/router_spec.rb
inesita-router-0.2.0 spec/router_spec.rb
inesita-router-0.1.0 spec/router_spec.rb