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');
...
@@ -5,25 +5,21 @@ const { createSelector } = require('reselect');
const
util
=
require
(
'../util'
);
const
util
=
require
(
'../util'
);
function
init
()
{
function
init
()
{
return
{
// The list of frames connected to the sidebar app
// The list of frames connected to the sidebar app
return
[];
frames
:
[],
};
}
}
const
update
=
{
const
update
=
{
CONNECT_FRAME
:
function
(
state
,
action
)
{
CONNECT_FRAME
:
function
(
state
,
action
)
{
return
{
frames
:
state
.
frames
.
concat
(
action
.
frame
)
}
;
return
[...
state
,
action
.
frame
]
;
},
},
DESTROY_FRAME
:
function
(
state
,
action
)
{
DESTROY_FRAME
:
function
(
state
,
action
)
{
return
{
return
state
.
filter
(
f
=>
f
!==
action
.
frame
);
frames
:
state
.
frames
.
filter
(
f
=>
f
!==
action
.
frame
),
};
},
},
UPDATE_FRAME_ANNOTATION_FETCH_STATUS
:
function
(
state
,
action
)
{
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
;
const
match
=
frame
.
uri
&&
frame
.
uri
===
action
.
uri
;
if
(
match
)
{
if
(
match
)
{
return
Object
.
assign
({},
frame
,
{
return
Object
.
assign
({},
frame
,
{
...
@@ -33,9 +29,7 @@ const update = {
...
@@ -33,9 +29,7 @@ const update = {
return
frame
;
return
frame
;
}
}
});
});
return
{
return
frames
;
frames
:
frames
,
};
},
},
};
};
...
@@ -123,6 +117,7 @@ function searchUris(state) {
...
@@ -123,6 +117,7 @@ function searchUris(state) {
module
.
exports
=
{
module
.
exports
=
{
init
:
init
,
init
:
init
,
namespace
:
'frames'
,
update
:
update
,
update
:
update
,
actions
:
{
actions
:
{
...
...
src/sidebar/store/modules/test/frames-test.js
View file @
63d39712
...
@@ -3,33 +3,19 @@
...
@@ -3,33 +3,19 @@
const
frames
=
require
(
'../frames'
);
const
frames
=
require
(
'../frames'
);
const
createStore
=
require
(
'../../create-store'
);
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
()
{
describe
(
'sidebar/store/modules/frames'
,
function
()
{
let
store
;
let
store
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
// Setup a store for tests. Note that some of the tests in this module
// Setup a store for tests.
// pre-date the `createStore` helper and have not been refactored to use
// it yet.
store
=
createStore
([
frames
]);
store
=
createStore
([
frames
]);
});
});
describe
(
'#connectFrame'
,
function
()
{
describe
(
'#connectFrame'
,
function
()
{
it
(
'adds the frame to the list of connected frames'
,
function
()
{
it
(
'adds the frame to the list of connected frames'
,
function
()
{
const
frame
=
{
uri
:
'http://example.com'
};
const
frame
=
{
uri
:
'http://example.com'
};
const
state
=
update
(
init
(),
actions
.
connectFrame
(
frame
)
);
store
.
connectFrame
(
frame
);
assert
.
deepEqual
(
s
electors
.
frames
(
state
),
[
frame
]);
assert
.
deepEqual
(
s
tore
.
frames
(
),
[
frame
]);
});
});
});
});
...
@@ -39,13 +25,10 @@ describe('sidebar/store/modules/frames', function() {
...
@@ -39,13 +25,10 @@ describe('sidebar/store/modules/frames', function() {
{
uri
:
'http://example.com'
},
{
uri
:
'http://example.com'
},
{
uri
:
'http://example.org'
},
{
uri
:
'http://example.org'
},
];
];
let
state
=
init
();
store
.
connectFrame
(
frameList
[
0
]);
frameList
.
forEach
(
function
(
frame
)
{
store
.
connectFrame
(
frameList
[
1
]);
state
=
update
(
state
,
actions
.
connectFrame
(
frame
));
store
.
destroyFrame
(
frameList
[
0
]);
});
assert
.
deepEqual
(
store
.
frames
(),
[
frameList
[
1
]]);
assert
.
deepEqual
(
selectors
.
frames
(
state
),
frameList
);
const
updatedState
=
update
(
state
,
actions
.
destroyFrame
(
frameList
[
0
]));
assert
.
deepEqual
(
selectors
.
frames
(
updatedState
),
[
frameList
[
1
]]);
});
});
});
});
...
@@ -58,27 +41,18 @@ describe('sidebar/store/modules/frames', function() {
...
@@ -58,27 +41,18 @@ describe('sidebar/store/modules/frames', function() {
uri
:
'http://example.com'
,
uri
:
'http://example.com'
,
isAnnotationFetchComplete
:
true
,
isAnnotationFetchComplete
:
true
,
};
};
const
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
store
.
connectFrame
(
frame
);
const
updatedState
=
update
(
store
.
updateFrameAnnotationFetchStatus
(
frame
.
uri
,
true
);
connectedState
,
assert
.
deepEqual
(
store
.
frames
(),
[
expectedFrame
]);
actions
.
updateFrameAnnotationFetchStatus
(
frame
.
uri
,
true
)
);
assert
.
deepEqual
(
selectors
.
frames
(
updatedState
),
[
expectedFrame
]);
});
});
it
(
'does not update the isAnnotationFetchComplete status of the wrong frame'
,
function
()
{
it
(
'does not update the isAnnotationFetchComplete status of the wrong frame'
,
function
()
{
const
frame
=
{
const
frame
=
{
uri
:
'http://example.com'
,
uri
:
'http://example.com'
,
};
};
const
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
store
.
connectFrame
(
frame
);
const
updatedState
=
update
(
store
.
updateFrameAnnotationFetchStatus
(
'http://anotherexample.com'
,
true
);
connectedState
,
assert
.
deepEqual
(
store
.
frames
(),
[
frame
]);
actions
.
updateFrameAnnotationFetchStatus
(
'http://anotherexample.com'
,
true
)
);
assert
.
deepEqual
(
selectors
.
frames
(
updatedState
),
[
frame
]);
});
});
});
});
...
@@ -110,89 +84,83 @@ describe('sidebar/store/modules/frames', function() {
...
@@ -110,89 +84,83 @@ describe('sidebar/store/modules/frames', function() {
});
});
});
});
describe
(
'#searchUris'
,
function
()
{
describe
(
'xxx #searchUris'
,
function
()
{
unroll
(
[
'returns the expected search URIs (#when)'
,
{
function
(
testCase
)
{
when
:
'one HTML frame'
,
let
state
=
init
();
frames
:
[
if
(
testCase
.
features
)
{
{
state
.
session
.
features
=
testCase
.
features
;
uri
:
'https://publisher.org/article.html'
,
}
},
testCase
.
frames
.
forEach
(
function
(
frame
)
{
],
state
=
update
(
state
,
actions
.
connectFrame
(
frame
));
searchUris
:
[
'https://publisher.org/article.html'
],
});
assert
.
deepEqual
(
selectors
.
searchUris
(
state
),
testCase
.
searchUris
);
},
},
[
{
{
when
:
'one PDF frame'
,
when
:
'one HTML frame'
,
frames
:
[
frames
:
[
{
{
uri
:
'https://publisher.org/article.pdf'
,
uri
:
'https://publisher.org/article.html'
,
metadata
:
{
},
documentFingerprint
:
'1234'
,
],
link
:
[
searchUris
:
[
'https://publisher.org/article.html'
],
{
},
href
:
'urn:x-pdf:1234'
,
{
},
when
:
'one PDF frame'
,
{
frames
:
[
// When a document fingerprint is provided, we currently rely on the
{
// host frame to include the original URL of the document in the
uri
:
'https://publisher.org/article.pdf'
,
// `metadata.link` list.
metadata
:
{
//
documentFingerprint
:
'1234'
,
// This may be omitted if the URI is a `file:///` URI.
link
:
[
href
:
'https://publisher.org/article.pdf?from_meta_link=1'
,
{
},
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'
,
},
},
],
},
searchUris
:
[
],
'https://publisher.org/article.html'
,
searchUris
:
[
'https://publisher.org/article2.html'
,
'urn:x-pdf:1234'
,
],
'https://publisher.org/article.pdf?from_meta_link=1'
,
},
],
{
},
when
:
'the document metadata includes a DOI'
,
{
frames
:
[
when
:
'multiple HTML frames'
,
{
frames
:
[
uri
:
'https://publisher.org/article.html'
,
{
metadata
:
{
uri
:
'https://publisher.org/article.html'
,
link
:
[
},
{
{
href
:
'doi:10.1.1/1234'
,
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