Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
MalekKamel committed Sep 24, 2024
1 parent e91767c commit 0fa0d87
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 7 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run RSpec Tests

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:


jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'

- name: Install dependencies
run: |
gem install bundler
bundle install
- name: Run RSpec
run: bundle exec rspec solara/lib/spec/
2 changes: 1 addition & 1 deletion solara/lib/core/brands/brand_switcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def switch

case @platform
when Platform::Flutter
FlutterBrandSwitcher.new(@brand_key).switch
IOSBrandSwitcher.new(@brand_key).switch
AndroidBrandSwitcher.new(@brand_key).switch
FlutterBrandSwitcher.new(@brand_key).switch
when Platform::IOS
IOSBrandSwitcher.new(@brand_key).switch
when Platform::Android
Expand Down
2 changes: 2 additions & 0 deletions solara/lib/core/dashboard/dashboard_manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class DashboardManager

def start(brand_key = nil, port = 8000)
return if SolaraEnvironment.is_test

Solara.logger.header("Solara Dashboard #{brand_key.nil? || brand_key.empty? ? "" : "for #{brand_key}"}")
if brand_key.nil? || brand_key.empty?
open("brands/brands.html?source=local", port)
Expand Down
4 changes: 4 additions & 0 deletions solara/lib/core/scripts/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def self.android
"android"
end

def self.test_lab
File.join(ENV['HOME'], '.solara', 'testlab')
end

def self.android_project_root
case SolaraSettingsManager.instance.platform
when Platform::Flutter
Expand Down
27 changes: 26 additions & 1 deletion solara/lib/core/scripts/solara_settings_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
class SolaraSettingsManager
include Singleton

attr_accessor :root, :project_root
attr_accessor :root, :project_root, :environment

def initialize
@environment = SolaraEnvironment::Production
end

def platform
settings['platform']
Expand All @@ -28,6 +32,10 @@ def add(key, value)
save(json)
end

def is_test_environment
@environment === 'test'
end

private

def settings
Expand Down Expand Up @@ -70,4 +78,21 @@ def init(platform)
unless Platform.all.include?(platform)
raise ArgumentError, "Invalid platform. Please use one of: #{Platform.all.join(', ')}"
end
end

module SolaraEnvironment
Production = 'production'
Test = 'test'

def self.all
[Production, Test]
end

def self.is_production
SolaraSettingsManager.instance.environment.downcase == Production.downcase
end

def self.is_test
SolaraSettingsManager.instance.environment.downcase == Test.downcase
end
end
2 changes: 1 addition & 1 deletion solara/lib/solara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def init
platform = platform.to_s.downcase

SolaraSettingsManager.instance.platform = platform
SolaraManager.new.init(platform, brand_key, brand_name)
SolaraManager.new.init(brand_key, brand_name)
end

desc "status", "Check the current status of Solara. The results may include information about the brand's current standing, the list of brands, and additional details."
Expand Down
2 changes: 1 addition & 1 deletion solara/lib/solara_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SolaraManager
def initialize
end

def init(platform, brand_key, brand_name)
def init(brand_key, brand_name)
SolaraInitializer.new(brand_key, brand_name).init
end

Expand Down
3 changes: 1 addition & 2 deletions solara/lib/spec/solara_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@

expect(cli).to receive(:validate_brand_key).with('test_key', ignore_brand_check: true).and_return('test_key')
expect(cli).to receive(:validate_brand_name).with('Test Brand').and_return('Test Brand')
# expect(SolaraSettingsManager.instance).to receive(:platform=).with('test_platform')
expect_any_instance_of(SolaraManager).to receive(:init).with('test_platform', 'test_key', 'Test Brand')
expect_any_instance_of(SolaraManager).to receive(:init).with('test_key', 'Test Brand')

cli.init
end
Expand Down
102 changes: 102 additions & 0 deletions solara/lib/spec/solara_manager_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
require 'rspec'
require_relative '../solara.rb'
Dir.glob("../core/scripts/*.rb").each { |file| require file }

RSpec.describe SolaraManager do
let(:manager) { SolaraManager.new }
let(:brand_key) { 'brand1' }
let(:brand_name) { 'Brand 1' }
let(:clone_brand_key) { 'brand1' }
let(:configurations) { { key: 'value' } }
let(:path) { '/path/to/export' }

describe '#init' do
it 'initializes with the given platform and brand details' do
test_lab = FilePath.test_lab
FileManager.delete_if_exists(test_lab)

# Define the repository URL and the target directory
repo_url = 'https://github.com/Solara-Kit/TestLab.git'

# Clone the repository
system("git clone #{repo_url} #{test_lab}")

# Check if the clone was successful
if $?.success?
puts "Successfully cloned #{repo_url} into #{test_lab}."
else
puts "Failed to clone the repository."
end

SolaraSettingsManager.instance.environment = SolaraEnvironment::Test
SolaraSettingsManager.instance.root = Pathname.new(File.expand_path('../..', __FILE__))
SolaraSettingsManager.instance.project_root = File.join(test_lab, 'flutter')
SolaraSettingsManager.instance.platform = 'flutter'

expect { manager.init(brand_key, brand_name) }.not_to raise_error

is_current_brand = BrandsManager.instance.is_current_brand(brand_key)
expect(is_current_brand).to be true
end
end

# describe '#import' do
# it 'imports configurations correctly' do
# expect { manager.import(configurations) }.not_to raise_error
# end
# end
#
# describe '#export' do
# it 'exports brand keys to the specified path' do
# expect { manager.export([brand_key], path) }.not_to raise_error
# end
# end
#
# describe '#status' do
# it 'checks the status without errors' do
# expect { manager.status }.not_to raise_error
# end
# end
#
# describe '#onboard' do
# context 'when the brand does not exist' do
# it 'onboards a new brand successfully' do
# expect { manager.onboard(brand_key, brand_name) }.to output(/Onboarded #{brand_key} successfully/).to_stdout
# end
# end
#
# context 'when the brand already exists' do
# before do
# allow(BrandsManager.instance).to receive(:exists).with(brand_key).and_return(true)
# end
#
# it 'does not onboard and logs a fatal message' do
# expect { manager.onboard(brand_key, brand_name) }.to output(/Brand with key/).to_stdout
# end
# end
# end
#
# describe '#offboard' do
# it 'offboards the brand without errors' do
# expect { manager.offboard(brand_key) }.not_to raise_error
# end
# end
#
# describe '#switch' do
# it 'switches to the specified brand' do
# expect { manager.switch(brand_key) }.not_to raise_error
# end
# end
#
# describe '#dashboard' do
# it 'opens the dashboard for the specified brand' do
# expect { manager.dashboard(brand_key) }.not_to raise_error
# end
# end
#
# describe '#doctor' do
# it 'runs doctor on the specified brand' do
# expect { manager.doctor(brand_key) }.not_to raise_error
# end
# end
end
2 changes: 1 addition & 1 deletion solara/lib/spec/solara_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
expect(SolaraInitializer).to receive(:new).with(brand_key, brand_name).and_return(initializer_mock)
expect(initializer_mock).to receive(:init)

manager.init(platform, brand_key, brand_name)
manager.init(brand_key, brand_name)
end
end

Expand Down

0 comments on commit 0fa0d87

Please sign in to comment.