Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
63d39712
Commit
63d39712
authored
Aug 21, 2019
by
Kyle Keating
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Namespace the frames module
parent
1e62dac0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
132 deletions
+95
-132
frames.js
src/sidebar/store/modules/frames.js
+7
-12
frames-test.js
src/sidebar/store/modules/test/frames-test.js
+88
-120
No files found.
src/sidebar/store/modules/frames.js
View file @
63d39712
...
...
@@ -5,25 +5,21 @@ const { createSelector } = require('reselect');
const
util
=
require
(
'../util'
);
function
init
()
{
return
{
// The list of frames connected to the sidebar app
frames
:
[],
};
// The list of frames connected to the sidebar app
return
[];
}
const
update
=
{
CONNECT_FRAME
:
function
(
state
,
action
)
{
return
{
frames
:
state
.
frames
.
concat
(
action
.
frame
)
}
;
return
[...
state
,
action
.
frame
]
;
},
DESTROY_FRAME
:
function
(
state
,
action
)
{
return
{
frames
:
state
.
frames
.
filter
(
f
=>
f
!==
action
.
frame
),
};
return
state
.
filter
(
f
=>
f
!==
action
.
frame
);
},
UPDATE_FRAME_ANNOTATION_FETCH_STATUS
:
function
(
state
,
action
)
{
const
frames
=
state
.
frames
.
map
(
function
(
frame
)
{
const
frames
=
state
.
map
(
function
(
frame
)
{
const
match
=
frame
.
uri
&&
frame
.
uri
===
action
.
uri
;
if
(
match
)
{
return
Object
.
assign
({},
frame
,
{
...
...
@@ -33,9 +29,7 @@ const update = {
return
frame
;
}
});
return
{
frames
:
frames
,
};
return
frames
;
},
};
...
...
@@ -123,6 +117,7 @@ function searchUris(state) {
module
.
exports
=
{
init
:
init
,
namespace
:
'frames'
,
update
:
update
,
actions
:
{
...
...
src/sidebar/store/modules/test/frames-test.js
View file @
63d39712
...
...
@@ -3,33 +3,19 @@
const
frames
=
require
(
'../frames'
);
const
createStore
=
require
(
'../../create-store'
);
const
session
=
require
(
'../session'
);
const
util
=
require
(
'../../util'
);
const
unroll
=
require
(
'../../../../shared/test/util'
).
unroll
;
const
actions
=
frames
.
actions
;
const
update
=
util
.
createReducer
(
frames
.
update
);
const
selectors
=
frames
.
selectors
;
function
init
()
{
return
Object
.
assign
({},
frames
.
init
(),
session
.
init
());
}
describe
(
'sidebar/store/modules/frames'
,
function
()
{
let
store
;
beforeEach
(()
=>
{
// Setup a store for tests. Note that some of the tests in this module
// pre-date the `createStore` helper and have not been refactored to use
// it yet.
// Setup a store for tests.
store
=
createStore
([
frames
]);
});
describe
(
'#connectFrame'
,
function
()
{
it
(
'adds the frame to the list of connected frames'
,
function
()
{
const
frame
=
{
uri
:
'http://example.com'
};
const
state
=
update
(
init
(),
actions
.
connectFrame
(
frame
)
);
assert
.
deepEqual
(
s
electors
.
frames
(
state
),
[
frame
]);
store
.
connectFrame
(
frame
);
assert
.
deepEqual
(
s
tore
.
frames
(
),
[
frame
]);
});
});
...
...
@@ -39,13 +25,10 @@ describe('sidebar/store/modules/frames', function() {
{
uri
:
'http://example.com'
},
{
uri
:
'http://example.org'
},
];
let
state
=
init
();
frameList
.
forEach
(
function
(
frame
)
{
state
=
update
(
state
,
actions
.
connectFrame
(
frame
));
});
assert
.
deepEqual
(
selectors
.
frames
(
state
),
frameList
);
const
updatedState
=
update
(
state
,
actions
.
destroyFrame
(
frameList
[
0
]));
assert
.
deepEqual
(
selectors
.
frames
(
updatedState
),
[
frameList
[
1
]]);
store
.
connectFrame
(
frameList
[
0
]);
store
.
connectFrame
(
frameList
[
1
]);
store
.
destroyFrame
(
frameList
[
0
]);
assert
.
deepEqual
(
store
.
frames
(),
[
frameList
[
1
]]);
});
});
...
...
@@ -58,27 +41,18 @@ describe('sidebar/store/modules/frames', function() {
uri
:
'http://example.com'
,
isAnnotationFetchComplete
:
true
,
};
const
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
const
updatedState
=
update
(
connectedState
,
actions
.
updateFrameAnnotationFetchStatus
(
frame
.
uri
,
true
)
);
assert
.
deepEqual
(
selectors
.
frames
(
updatedState
),
[
expectedFrame
]);
store
.
connectFrame
(
frame
);
store
.
updateFrameAnnotationFetchStatus
(
frame
.
uri
,
true
);
assert
.
deepEqual
(
store
.
frames
(),
[
expectedFrame
]);
});
it
(
'does not update the isAnnotationFetchComplete status of the wrong frame'
,
function
()
{
const
frame
=
{
uri
:
'http://example.com'
,
};
const
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
const
updatedState
=
update
(
connectedState
,
actions
.
updateFrameAnnotationFetchStatus
(
'http://anotherexample.com'
,
true
)
);
assert
.
deepEqual
(
selectors
.
frames
(
updatedState
),
[
frame
]);
store
.
connectFrame
(
frame
);
store
.
updateFrameAnnotationFetchStatus
(
'http://anotherexample.com'
,
true
);
assert
.
deepEqual
(
store
.
frames
(),
[
frame
]);
});
});
...
...
@@ -110,89 +84,83 @@ describe('sidebar/store/modules/frames', function() {
});
});
describe
(
'#searchUris'
,
function
()
{
unroll
(
'returns the expected search URIs (#when)'
,
function
(
testCase
)
{
let
state
=
init
();
if
(
testCase
.
features
)
{
state
.
session
.
features
=
testCase
.
features
;
}
testCase
.
frames
.
forEach
(
function
(
frame
)
{
state
=
update
(
state
,
actions
.
connectFrame
(
frame
));
});
assert
.
deepEqual
(
selectors
.
searchUris
(
state
),
testCase
.
searchUris
);
describe
(
'xxx #searchUris'
,
function
()
{
[
{
when
:
'one HTML frame'
,
frames
:
[
{
uri
:
'https://publisher.org/article.html'
,
},
],
searchUris
:
[
'https://publisher.org/article.html'
],
},
[
{
when
:
'one HTML frame'
,
frames
:
[
{
uri
:
'https://publisher.org/article.html'
,
},
],
searchUris
:
[
'https://publisher.org/article.html'
],
},
{
when
:
'one PDF frame'
,
frames
:
[
{
uri
:
'https://publisher.org/article.pdf'
,
metadata
:
{
documentFingerprint
:
'1234'
,
link
:
[
{
href
:
'urn:x-pdf:1234'
,
},
{
// When a document fingerprint is provided, we currently rely on the
// host frame to include the original URL of the document in the
// `metadata.link` list.
//
// This may be omitted if the URI is a `file:///` URI.
href
:
'https://publisher.org/article.pdf?from_meta_link=1'
,
},
],
},
},
],
searchUris
:
[
'urn:x-pdf:1234'
,
'https://publisher.org/article.pdf?from_meta_link=1'
,
],
},
{
when
:
'multiple HTML frames'
,
frames
:
[
{
uri
:
'https://publisher.org/article.html'
,
},
{
uri
:
'https://publisher.org/article2.html'
,
{
when
:
'one PDF frame'
,
frames
:
[
{
uri
:
'https://publisher.org/article.pdf'
,
metadata
:
{
documentFingerprint
:
'1234'
,
link
:
[
{
href
:
'urn:x-pdf:1234'
,
},
{
// When a document fingerprint is provided, we currently rely on the
// host frame to include the original URL of the document in the
// `metadata.link` list.
//
// This may be omitted if the URI is a `file:///` URI.
href
:
'https://publisher.org/article.pdf?from_meta_link=1'
,
},
],
},
],
searchUris
:
[
'https://publisher.org/article.html'
,
'https://publisher.org/article2.html'
,
],
},
{
when
:
'the document metadata includes a DOI'
,
frames
:
[
{
uri
:
'https://publisher.org/article.html'
,
metadata
:
{
link
:
[
{
href
:
'doi:10.1.1/1234'
,
},
],
},
},
],
searchUris
:
[
'urn:x-pdf:1234'
,
'https://publisher.org/article.pdf?from_meta_link=1'
,
],
},
{
when
:
'multiple HTML frames'
,
frames
:
[
{
uri
:
'https://publisher.org/article.html'
,
},
{
uri
:
'https://publisher.org/article2.html'
,
},
],
searchUris
:
[
'https://publisher.org/article.html'
,
'https://publisher.org/article2.html'
,
],
},
{
when
:
'the document metadata includes a DOI'
,
frames
:
[
{
uri
:
'https://publisher.org/article.html'
,
metadata
:
{
link
:
[
{
href
:
'doi:10.1.1/1234'
,
},
],
},
],
searchUris
:
[
'https://publisher.org/article.html'
,
'doi:10.1.1/1234'
],
},
]
);
},
],
searchUris
:
[
'https://publisher.org/article.html'
,
'doi:10.1.1/1234'
],
},
].
forEach
(
testCase
=>
{
it
(
testCase
.
when
,
()
=>
{
testCase
.
frames
.
forEach
(
frame
=>
{
store
.
connectFrame
(
frame
);
});
assert
.
deepEqual
(
store
.
searchUris
(),
testCase
.
searchUris
);
});
});
});
});
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