Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
b504b09b
Commit
b504b09b
authored
May 15, 2017
by
Luke "Jared" Bennett
Committed by
Phil Hughes
May 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added balsamiq jasmine integration test
parent
c48554ed
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
119 additions
and
48 deletions
+119
-48
.gitignore
.gitignore
+1
-0
app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js
app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js
+16
-16
app/assets/javascripts/blob/balsamiq_viewer.js
app/assets/javascripts/blob/balsamiq_viewer.js
+20
-4
config/webpack.config.js
config/webpack.config.js
+1
-1
spec/javascripts/blob/balsamiq/balsamiq_viewer_integration_spec.js
...scripts/blob/balsamiq/balsamiq_viewer_integration_spec.js
+51
-0
spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js
spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js
+11
-27
spec/javascripts/fixtures/balsamiq.rb
spec/javascripts/fixtures/balsamiq.rb
+18
-0
spec/javascripts/fixtures/balsamiq_viewer.html.haml
spec/javascripts/fixtures/balsamiq_viewer.html.haml
+1
-0
No files found.
.gitignore
View file @
b504b09b
...
...
@@ -48,6 +48,7 @@ eslint-report.html
/public/uploads/
/shared/artifacts/
/spec/javascripts/fixtures/blob/pdf/
/spec/javascripts/fixtures/blob/balsamiq/
/rails_best_practices_output.html
/tags
/tmp/*
...
...
app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js
View file @
b504b09b
/* global Flash */
import
sqljs
from
'
sql.js
'
;
import
{
template
as
_template
}
from
'
underscore
'
;
...
...
@@ -15,19 +13,27 @@ const PREVIEW_TEMPLATE = _template(`
class
BalsamiqViewer
{
constructor
(
viewer
)
{
this
.
viewer
=
viewer
;
this
.
endpoint
=
this
.
viewer
.
dataset
.
endpoint
;
}
loadFile
()
{
const
xhr
=
new
XMLHttpRequest
();
loadFile
(
endpoint
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
'
GET
'
,
endpoint
,
true
);
xhr
.
responseType
=
'
arraybuffer
'
;
xhr
.
onload
=
loadEvent
=>
this
.
fileLoaded
(
loadEvent
,
resolve
,
reject
);
xhr
.
onerror
=
reject
;
xhr
.
send
();
});
}
xhr
.
open
(
'
GET
'
,
this
.
endpoint
,
true
);
xhr
.
responseType
=
'
arraybuffer
'
;
fileLoaded
(
loadEvent
,
resolve
,
reject
)
{
if
(
loadEvent
.
target
.
status
!==
200
)
return
reject
()
;
xhr
.
onload
=
this
.
renderFile
.
bind
(
this
);
xhr
.
onerror
=
BalsamiqViewer
.
onError
;
this
.
renderFile
(
loadEvent
);
xhr
.
send
();
return
resolve
();
}
renderFile
(
loadEvent
)
{
...
...
@@ -103,12 +109,6 @@ class BalsamiqViewer {
static
parseTitle
(
resource
)
{
return
JSON
.
parse
(
resource
.
values
[
0
][
2
]).
name
;
}
static
onError
()
{
const
flash
=
new
Flash
(
'
Balsamiq file could not be loaded.
'
);
return
flash
;
}
}
export
default
BalsamiqViewer
;
app/assets/javascripts/blob/balsamiq_viewer.js
View file @
b504b09b
/* global Flash */
import
BalsamiqViewer
from
'
./balsamiq/balsamiq_viewer
'
;
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
const
balsamiqViewer
=
new
BalsamiqViewer
(
document
.
getElementById
(
'
js-balsamiq-viewer
'
));
balsamiqViewer
.
loadFile
();
});
function
onError
()
{
const
flash
=
new
window
.
Flash
(
'
Balsamiq file could not be loaded.
'
);
return
flash
;
}
function
loadBalsamiqFile
()
{
const
viewer
=
document
.
getElementById
(
'
js-balsamiq-viewer
'
);
if
(
!
(
viewer
instanceof
Element
))
return
;
const
endpoint
=
viewer
.
dataset
.
endpoint
;
const
balsamiqViewer
=
new
BalsamiqViewer
(
viewer
);
balsamiqViewer
.
loadFile
(
endpoint
).
catch
(
onError
);
}
$
(
loadBalsamiqFile
);
config/webpack.config.js
View file @
b504b09b
...
...
@@ -94,7 +94,7 @@ var config = {
query
:
{
mimetype
:
'
image/gif
'
},
},
{
test
:
/
\.(
worker
\.
js|pdf
)
$/
,
test
:
/
\.(
worker
\.
js|pdf
|bmpr
)
$/
,
exclude
:
/node_modules/
,
loader
:
'
file-loader
'
,
},
...
...
spec/javascripts/blob/balsamiq/balsamiq_viewer_integration_spec.js
0 → 100644
View file @
b504b09b
/* eslint-disable import/no-unresolved */
import
BalsamiqViewer
from
'
~/blob/balsamiq/balsamiq_viewer
'
;
import
bmprPath
from
'
../../fixtures/blob/balsamiq/test.bmpr
'
;
describe
(
'
Balsamiq integration spec
'
,
()
=>
{
let
container
;
let
endpoint
;
let
balsamiqViewer
;
preloadFixtures
(
'
static/balsamiq_viewer.html.raw
'
);
beforeEach
(()
=>
{
loadFixtures
(
'
static/balsamiq_viewer.html.raw
'
);
container
=
document
.
getElementById
(
'
js-balsamiq-viewer
'
);
balsamiqViewer
=
new
BalsamiqViewer
(
container
);
});
describe
(
'
successful response
'
,
()
=>
{
beforeEach
((
done
)
=>
{
endpoint
=
bmprPath
;
balsamiqViewer
.
loadFile
(
endpoint
).
then
(
done
).
catch
(
done
.
fail
);
});
it
(
'
does not show loading icon
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.loading
'
)).
toBeNull
();
});
it
(
'
renders the balsamiq previews
'
,
()
=>
{
expect
(
document
.
querySelectorAll
(
'
.previews .preview
'
).
length
).
not
.
toEqual
(
0
);
});
});
describe
(
'
error getting file
'
,
()
=>
{
beforeEach
((
done
)
=>
{
endpoint
=
'
invalid/path/to/file.bmpr
'
;
balsamiqViewer
.
loadFile
(
endpoint
).
then
(
done
.
fail
,
null
).
catch
(
done
);
});
it
(
'
does not show loading icon
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.loading
'
)).
toBeNull
();
});
it
(
'
does not render the balsamiq previews
'
,
()
=>
{
expect
(
document
.
querySelectorAll
(
'
.previews .preview
'
).
length
).
toEqual
(
0
);
});
});
});
spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js
View file @
b504b09b
...
...
@@ -4,17 +4,11 @@ import ClassSpecHelper from '../../helpers/class_spec_helper';
describe
(
'
BalsamiqViewer
'
,
()
=>
{
let
balsamiqViewer
;
let
endpoint
;
let
viewer
;
describe
(
'
class constructor
'
,
()
=>
{
beforeEach
(()
=>
{
endpoint
=
'
endpoint
'
;
viewer
=
{
dataset
:
{
endpoint
,
},
};
viewer
=
{};
balsamiqViewer
=
new
BalsamiqViewer
(
viewer
);
});
...
...
@@ -22,25 +16,25 @@ describe('BalsamiqViewer', () => {
it
(
'
should set .viewer
'
,
()
=>
{
expect
(
balsamiqViewer
.
viewer
).
toBe
(
viewer
);
});
});
describe
(
'
fileLoaded
'
,
()
=>
{
it
(
'
should set .endpoint
'
,
()
=>
{
expect
(
balsamiqViewer
.
endpoint
).
toBe
(
endpoint
);
});
});
describe
(
'
loadFile
'
,
()
=>
{
let
xhr
;
let
loadFile
;
const
endpoint
=
'
endpoint
'
;
beforeEach
(()
=>
{
endpoint
=
'
endpoint
'
;
xhr
=
jasmine
.
createSpyObj
(
'
xhr
'
,
[
'
open
'
,
'
send
'
]);
balsamiqViewer
=
jasmine
.
createSpyObj
(
'
balsamiqViewer
'
,
[
'
renderFile
'
]);
balsamiqViewer
.
endpoint
=
endpoint
;
spyOn
(
window
,
'
XMLHttpRequest
'
).
and
.
returnValue
(
xhr
);
BalsamiqViewer
.
prototype
.
loadFile
.
call
(
balsamiqViewer
);
loadFile
=
BalsamiqViewer
.
prototype
.
loadFile
.
call
(
balsamiqViewer
,
endpoint
);
});
it
(
'
should call .open
'
,
()
=>
{
...
...
@@ -54,6 +48,10 @@ describe('BalsamiqViewer', () => {
it
(
'
should call .send
'
,
()
=>
{
expect
(
xhr
.
send
).
toHaveBeenCalled
();
});
it
(
'
should return a promise
'
,
()
=>
{
expect
(
loadFile
).
toEqual
(
jasmine
.
any
(
Promise
));
});
});
describe
(
'
renderFile
'
,
()
=>
{
...
...
@@ -325,18 +323,4 @@ describe('BalsamiqViewer', () => {
expect
(
parseTitle
).
toBe
(
'
name
'
);
});
});
describe
(
'
onError
'
,
()
=>
{
beforeEach
(()
=>
{
spyOn
(
window
,
'
Flash
'
);
BalsamiqViewer
.
onError
();
});
ClassSpecHelper
.
itShouldBeAStaticMethod
(
BalsamiqViewer
,
'
onError
'
);
it
(
'
should instantiate Flash
'
,
()
=>
{
expect
(
window
.
Flash
).
toHaveBeenCalledWith
(
'
Balsamiq file could not be loaded.
'
);
});
});
});
spec/javascripts/fixtures/balsamiq.rb
0 → 100644
View file @
b504b09b
require
'spec_helper'
describe
'Balsamiq file'
,
'(JavaScript fixtures)'
,
type: :controller
do
include
JavaScriptFixturesHelpers
let
(
:namespace
)
{
create
(
:namespace
,
name:
'frontend-fixtures'
)}
let
(
:project
)
{
create
(
:project
,
namespace:
namespace
,
path:
'balsamiq-project'
)
}
before
(
:all
)
do
clean_frontend_fixtures
(
'blob/balsamiq/'
)
end
it
'blob/balsamiq/test.bmpr'
do
|
example
|
blob
=
project
.
repository
.
blob_at
(
'b89b56d79'
,
'files/images/balsamiq.bmpr'
)
store_frontend_fixture
(
blob
.
data
.
force_encoding
(
'utf-8'
),
example
.
description
)
end
end
spec/javascripts/fixtures/balsamiq_viewer.html.haml
0 → 100644
View file @
b504b09b
.file-content.balsamiq-viewer
#js-balsamiq-viewer
{
data:
{
endpoint:
'/test'
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment