2019-07-26 18:40:36 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-29 21:55:26 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-04-24 20:53:49 +08:00
|
|
|
describe SmartAnnotations::HtmlPreview do
|
2018-03-29 21:55:26 +08:00
|
|
|
let(:subject) { described_class }
|
|
|
|
let(:user) { create :user }
|
2022-03-09 21:12:16 +08:00
|
|
|
let(:project) { create :project, name: 'my project', created_by: user }
|
2018-03-29 21:55:26 +08:00
|
|
|
let(:experiment) do
|
|
|
|
create :experiment, name: 'my experiment',
|
|
|
|
project: project,
|
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user
|
|
|
|
end
|
2021-09-30 17:32:11 +08:00
|
|
|
let(:task) { create :my_module, name: 'task', experiment: experiment, created_by: experiment.created_by }
|
2018-03-29 21:55:26 +08:00
|
|
|
|
|
|
|
describe 'Project annotations with type prj' do
|
|
|
|
it 'returns a html snippet' do
|
|
|
|
snippet = subject.html(nil, 'prj', project)
|
|
|
|
expect(snippet).to eq(
|
2023-03-07 03:17:45 +08:00
|
|
|
"<a class='sa-link' href='/projects/#{project.id}'>" \
|
2020-09-08 15:39:15 +08:00
|
|
|
"<span class='sa-type'>Prj</span>my project</a>"
|
2018-03-29 21:55:26 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Experiment annotations with type exp' do
|
|
|
|
it 'returns a html snippet' do
|
|
|
|
snippet = subject.html(nil, 'exp', experiment)
|
|
|
|
expect(snippet).to eq(
|
2023-03-07 03:17:45 +08:00
|
|
|
"<a class='sa-link' href='/experiments/#{experiment.id}/my_modules'>" \
|
2020-09-08 15:39:15 +08:00
|
|
|
"<span class='sa-type'>Exp</span>my experiment</a>"
|
2018-03-29 21:55:26 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'MyModule annotations with type tsk' do
|
|
|
|
it 'returns a html snippet' do
|
|
|
|
snippet = subject.html(nil, 'tsk', task)
|
|
|
|
expect(snippet).to eq(
|
2023-03-07 03:17:45 +08:00
|
|
|
"<a class='sa-link' href='/modules/#{task.id}/protocols'>" \
|
2020-09-08 15:39:15 +08:00
|
|
|
"<span class='sa-type'>Tsk</span>task</a>"
|
2018-03-29 21:55:26 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Repository item annotations with type rep_item' do
|
|
|
|
it 'returns a html snippet' do
|
|
|
|
snippet = subject.html('my item', 'rep_item', nil)
|
|
|
|
expect(snippet).to eq(
|
2018-05-25 17:41:43 +08:00
|
|
|
'<span class=\'sa-type\'>Inv</span> my item (deleted)'
|
2018-03-29 21:55:26 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-04 16:44:23 +08:00
|
|
|
context '#trim_repository_name/1' do
|
|
|
|
describe 'repository name with one word' do
|
|
|
|
it 'is returns a 3 letter capitalize string' do
|
|
|
|
trimmed_repository_name = subject.__send__(
|
|
|
|
:trim_repository_name, 'banana'
|
|
|
|
)
|
|
|
|
expect(trimmed_repository_name).to eq('Ban')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'repository name with two words' do
|
|
|
|
it 'returns the first two letters of first word ' \
|
|
|
|
'and the first letter of second word' do
|
|
|
|
trimmed_repository_name = subject.__send__(
|
|
|
|
:trim_repository_name, 'two words'
|
|
|
|
)
|
|
|
|
expect(trimmed_repository_name).to eq('Tww')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return 3 letters of the first word' do
|
|
|
|
trimmed_repository_name = subject.__send__(
|
|
|
|
:trim_repository_name, 'two words'
|
|
|
|
)
|
|
|
|
expect(trimmed_repository_name).not_to eq('Two')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'repository name with three words' do
|
|
|
|
it 'returns the first letter of first 3 words capitalized' do
|
|
|
|
trimmed_repository_name = subject.__send__(
|
|
|
|
:trim_repository_name, 'two words of wisdom'
|
|
|
|
)
|
|
|
|
expect(trimmed_repository_name).to eq('Two')
|
|
|
|
end
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|